我在我的React Native项目中使用了react-native-camera库。
但是我在拍照的时候遇到了一个问题。保存相片需要3-4秒。当我点击按钮拍摄照片时,我听到了声音,但随后需要大约3-4秒来保存照片。
render方法如下:
return (
<View style={styles.container}>
<Camera ref={(cam) => {this.camera = cam;}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}>
{this.imageOverlay()}
<Text style={styles.capture} onPress={this.takePicture.bind(this, this.state.type)}>[CAPTURE]</Text>
</Camera>
</View>
)takePicture函数如下:
takePicture(type){
let self = this;
this.camera.capture({target: Camera.constants.CaptureTarget.disk})
.then((data) => {
<!---------------------------------------------------------->
<!------------It takes 3-4 seconds to come here------------!>
<!---------------------------------------------------------->
let n_pictures = [];
each(this.state.pictures, function (picture){
if(picture.item !== type.item){
n_pictures.push(picture)
}else{
n_pictures.push({
title: type.title,
noImage: false,
imageOverlay: type.imageOverlay,
image: data.path,
imageIcon: type.imageIcon,
overlay: false,
item: type.item,
mandatory: type.mandatory
})
}
});
self.setState({pictures: n_pictures, showCamera: false})
})
.catch(err => console.error(err));
}你知道怎么解决这个问题吗?
我至少可以在保存相片之前放置一个加载屏幕吗?
发布于 2018-09-20 04:01:33
所以我遇到了同样的问题,在互联网上搜索了一段时间后,我找不到加快速度的答案。
但是,要回答您关于使用加载屏幕的问题,您可能需要查看Javascript promises。对于我的应用程序,我立即将用户重定向到一个新屏幕,并在承诺未解决/拒绝的情况下显示正在加载的图片。一旦它被解决,图片就会显示出来。
我知道这是一个古老的答案,但我将把这个放在这里,给其他可能有类似问题的人。
https://stackoverflow.com/questions/46664665
复制相似问题