React 本机相机在第二次调用时不起作用



React 原生相机在 Android 中的第二次调用时不起作用。第二次调用时,应用崩溃。我正在使用 反应原生:0.56.0 反应原生相机:1.6.4当我使用最新版本的 react-native-camera 时也是如此。我无法将 react-native 更新为最新版本,因为我有另一个与最新版本不兼容的软件包,并且在模拟器上工作正常,只有真实设备的问题

扫描结果为

我的相机屏幕

class CameraScreen extends Component {
  constructor(props) {
    super(props);
    this.state = {
      boltIconIsPressed: false,
    };
  }
  renderError() {
    Alert.alert(
      'Error',
      'Something went wrong, Try again!',
      [
        { text: 'Ok', style: 'cancel' },
      ],  
    );
    this.props.navigation.goBack();
  }
render() {
    if (this.props.isFocused) {
    return (
      <View style={styles.container}>
        <RNCamera
          ref={ref => {
            this.camera = ref;
          }}
          style={styles.preview}
          type={RNCamera.Constants.Type.back}
          flashMode={this.state.boltIconIsPressed ? RNCamera.Constants.FlashMode.off : RNCamera.Constants.FlashMode.on}
          onMountError={this.renderError.bind(this)}
          permissionDialogTitle={'Permission to use camera'}
          permissionDialogMessage={'We need your permission to use your camera phone'}
        />
        <View 
          style={{ flex: 0, 
                   flexDirection: 'row', 
                   justifyContent: 'center',
                   backgroundColor: 'transparent' }}
        >
          <Button
             outline
             rounded
             style={styles.capture}
             onPress={() => this.props.navigation.navigate('gallery')}
          >
            <Icon
              type='Entypo'
              name='image'
              style={{ color: '#862d59', }}
            />
        </Button>
          <Button
            outline
            rounded
            onPress={this.takePicture.bind(this)}
            style={styles.capture}
          >
            <Icon
              type='SimpleLineIcons'
              name='camera'
              style={{ color: '#862d59', }}
            />
          </Button>
          <Button
            outline
            rounded
            style={styles.capture}
            onPress={() => this.setState({ boltIconIsPressed: 
                       !this.state.boltIconIsPressed })}
          >
            <Icon
              type='MaterialCommunityIcons'
              name={this.state.boltIconIsPressed ? "flash-off" : "flash"}
              style={{ color: '#862d59', }}
            />
          </Button>
          </View>
         </View>
    );
   }
    return (
        <View />
      );
  }
  takePicture = async function () {
    let data = null;
    if (this.camera) {
      const options = { 
        width: 1800,
        base64: true,
      };
      console.log(data);
      data = await this.camera.takePictureAsync(options);
      this.props.navigation.navigate('uploadscreen', {
        image: data,
      });
    }
  };
}
export default withNavigationFocus(CameraScreen);

提前致谢

我收到此错误,因为我没有存储空间来保存拍摄的图像。要使其正常工作,请将其添加到 AndroidManifest.xml 文件中

android:largeHeap="true"

相关内容

  • 没有找到相关文章

最新更新