react-native - 如何在视图中设置状态并显示画廊中的多个选定图像
问题描述
我是 react-native 的新手。我曾使用 npm react-native-image-crop-picker 来访问画廊和相机。我一次只能访问画廊或相机。如何同时访问它们时间以及如何在视图中显示多个选定的图像?任何帮助,将不胜感激。谢谢,提前。我的示例代码,
galleryAccessFunc() {
ImagePicker.openPicker({
multiple: true
}).then(image => {
console.log(image)
this.setState({ImageSource:image.path})
});debugger
}
当我尝试显示所选图像时,它返回一个空视图,
<TouchableOpacity onPress={this.galleryAccessFunc.bind(this)} >
<View style={styles.ImageContainer}>
{ this.state.ImageSource === null ? <Text>Select a Photo</Text> :
<Image style={styles.ImageContainer} source={ this.state.ImageSource} />
}
</View>
</TouchableOpacity>
以及如何同时访问画廊和相机?
解决方案
pickMultiple() {
ImagePicker.openPicker({
multiple: true,
waitAnimationEnd: false
}).then(images => {
this.setState({
image: null,
images: images.map(i => {
console.log('received image', i);
return {uri: i.path, width: i.width, height: i.height, mime: i.mime};
})
});
}).catch(e => alert(e));
}
并像这样查看
<ScrollView horizontal >
this.state.images.map((i,key) => <View key={i.uri}>{this.renderAsset(i,key)}
</View>) :
</ScrollView>
如果您想从画廊和相机中选择,然后创建一个按钮并显示来自画廊或相机的选项并调用不同的函数来拍摄图像
推荐阅读
- mongodb - 我怎样才能做这样的查询过滤器?
- python - Python 协程不与 time.sleep() 同时运行?
- java - Lambda 表达式中的模式匹配
- bash - bash脚本中的while循环从文件中读取时删除第一行
- android - 尽管用户为 Null,但应用程序卸载和重新安装显示“不允许 Firebase 身份验证”。我们可以注销或删除用户或登录吗?
- ios - 如何快速判断设备屏幕何时锁定或解锁
- filter - 如何将自定义键值对添加到 grok 模式?
- oauth - 卡在“正在验证您的同意屏幕”
- r - 如何在保持时间的同时将“POSIXct”转换为日期对象?
- python - 进入屏幕3秒后如何切换屏幕?