【发布时间】:2019-08-17 11:03:56
【问题描述】:
所以我想创建一个漂亮的相机胶卷 UI,它有一个 borderColor 而不是 margin 或 padding,因为它会使图像不适合屏幕的宽度。我也不想在图像的右侧和左侧添加borderColor。它只是喜欢在 Instagram 上。
这就是我想要实现的目标:
这是我的代码:
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>
);
}
}
【问题讨论】:
-
你可以使用
Flatlist -
@hongdevelop 然后呢?
标签: javascript react-native stylesheet