簡體   English   中英

通過導航器打開2次后,react-native-camera會凍結應用程序

[英]react-native-camera freezes app when opened 2 times via navigator

我在一個簡單的<Navigator />組件中包含的視圖中使用https://github.com/lwansbrough/react-native-camera庫。

一切正常,直到您導航回“主頁”視圖並嘗試使用<Camera />重新加載該視圖。 控制台或Xcode中沒有錯誤消息,這使查明問題非常困難。

當我刪除整個<Camera />組件時,導航將按預期工作,並且視圖會重新加載正常。

目前在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本機庫之一)

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;
}

希望多數民眾贊成在幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM