相机胶卷添加borderColor

时间:2019-08-17 11:03:56

标签: javascript react-native stylesheet

因此,我想创建一个漂亮的相机胶卷UI,该相机胶卷具有borderColor而不是marginpadding,因为它会使图像不适合屏幕宽度。我也不想在图像的左侧和右侧添加borderColor。就像在Instagram上一样。

这是我想要实现的:

enter image description here

这是我的代码:

CameraRoll.js

  setIndex = (index) => {
if (index === this.state.index) {
  index = null
}
this.setState({ index });
};

getPhotos = () => {
CameraRoll.getPhotos({
  first: 200,
  assetType: 'All'
})
.then(res => {
  this.setState({ 
    photos: res.edges,
  });
})
.catch((err) => {
  console.log('Error image: ' + err);
});
};

render() {
return(
  <View style={styles.container}>
    <Image 
      source={{uri: this.state.pickedImage}} 
      style={styles.image}
    />
    <ScrollView contentContainerStyle={styles.scrollView} showsVerticalScrollIndicator={false}>
      {this.state.photos.map((photos, index) => {
        return(
          <TouchableHighlight 
            style={{opacity: index === this.state.index ? .5 : 1}}
            onPress={() => this.setState({pickedImage: photos.node.image.uri})}
            key={index}
            underlayColor='transparent'
          >
            <Image
              style={[{width: width / 3, height: width /3}]}
              source={{uri: photos.node.image.uri}}
              resizeMode='cover'
            />
          </TouchableHighlight>
        );
      })}
    </ScrollView>
  </View>
); 
}
}

1 个答案:

答案 0 :(得分:0)

  

更改TouchableHighlight或图像的样式,添加borderColor:“红色”,borderWidth:10

setIndex = (index) => {
if (index === this.state.index) {
  index = null
}
this.setState({ index });
};

getPhotos = () => {
CameraRoll.getPhotos({
  first: 200,
  assetType: 'All'
})
.then(res => {
  this.setState({ 
    photos: res.edges,
  });
})
.catch((err) => {
  console.log('Error image: ' + err);
});
};

render() {
return(
  <View style={styles.container}>
    <Image 
      source={{uri: this.state.pickedImage}} 
      style={styles.image}
    />
    <ScrollView contentContainerStyle={styles.scrollView} showsVerticalScrollIndicator={false}>
      {this.state.photos.map((photos, index) => {
        return(
          <TouchableHighlight 
            style={{
              opacity: index === this.state.index ? .5 : 1,  
              borderColor:"red", borderWidth:10
           }}
            onPress={() => this.setState({pickedImage: photos.node.image.uri})}
            key={index}
            underlayColor='transparent'
          >
            <Image
              style={[{width: width / 3, height: width /3}]}
              source={{uri: photos.node.image.uri}}
              resizeMode='cover'
            />
          </TouchableHighlight>
        );
      })}
    </ScrollView>
  </View>
); 
}
}