[英]react-native-camera freezes app when opened 2 times via navigator
I'm using the https://github.com/lwansbrough/react-native-camera library in a view that is contained inside a simple <Navigator />
component. 我在一个简单的
<Navigator />
组件中包含的视图中使用https://github.com/lwansbrough/react-native-camera库。
Everything works as expected until you navigate back the Home view and try to reload the View with the <Camera />
. 一切正常,直到您导航回“主页”视图并尝试使用
<Camera />
重新加载该视图。 There are no error messages in the console OR in Xcode which makes this extremely hard to pinpoint the problem. 控制台或Xcode中没有错误消息,这使查明问题非常困难。
When I delete the entire <Camera />
component, the navigation works as expected and the view reloads fine. 当我删除整个
<Camera />
组件时,导航将按预期工作,并且视图会重新加载正常。
There is currently an open issue on github https://github.com/lwansbrough/react-native-camera/issues/80 but as time is of the essence, I am wondering if anyone else has found a solution to this problem and can share a fix. 目前在github https://github.com/lwansbrough/react-native-camera/issues/80上有一个未解决的问题,但是由于时间至关重要,我想知道是否有人找到了解决此问题的方法并且可以分享修复。
standard render method: 标准渲染方法:
render() {
return (
<View style={styles.outer}>
<Overlay
modalVisible={this.state.modalVisible}
/>
<Camera
ref="cam"
style={styles.container}
captureTarget={Camera.constants.CaptureTarget.disk}
type={this.state.cameraType}>
<TouchableHighlight style={styles.circlebutton} onPress={this._takePicture}>
<Text>Take Picture</Text>
</TouchableHighlight>
</Camera>
<Image
source={{uri: this.state.imageURI, isStatic:true}}
style={{width: this.state.imageURI ? 100 : 0, height: this.state.imageURI ? 100 : 0, opacity: this.state.imageURI ? 1 : 0}}
/>
</View>
);
}
Try this: 尝试这个:
On Xcode, Go to RCTCamera.xcodeproj
(This is one of the react native libraries) 在Xcode上,转到
RCTCamera.xcodeproj
(这是react本机库之一)
In RCTCameraManager.h
在
RCTCameraManager.h
Add the property @property (nonatomic, strong) RCTCamera *camera;
添加属性
@property (nonatomic, strong) RCTCamera *camera;
In RCTCameraManager.m
在
RCTCameraManager.m
- (UIView *)view
{
return [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
}
Replace With: 用。。。来代替:
- (UIView *)view
{
if(!self.camera){
self.camera = [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
return self.camera;
}
return self.camera;
}
Hope thats help. 希望多数民众赞成在帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.