我正在使用 https://github.com/lwansbrough/react-native-camera包含在简单 <Navigator />
中的 View 中的库组件。
一切都按预期工作,直到您导航回主页 View 并尝试使用 <Camera />
重新加载 View .控制台或 Xcode 中没有错误消息,这使得查明问题变得非常困难。
当我删除整个 <Camera />
组件,导航按预期工作, View 重新加载正常。
目前在github上有一个悬而未决的问题https://github.com/lwansbrough/react-native-camera/issues/80但由于时间紧迫,我想知道是否还有其他人找到了解决此问题的方法并可以共享修复程序。
标准渲染方法:
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>
);
}
最佳答案
试试这个:
在 Xcode 上,转到 RCTCamera.xcodeproj
(这是 React native 库之一)
在 RCTCameraManager.h
添加属性
@property (nonatomic, strong) RCTCamera *camera;
在RCTCameraManager.m
- (UIView *)view
{
return [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
}
替换为:
- (UIView *)view
{
if(!self.camera){
self.camera = [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
return self.camera;
}
return self.camera;
}
希望对您有帮助。
关于javascript - 通过导航器打开 2 次时,react-native-camera 卡住应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33046061/