首页 > 解决方案 > 在本机反应中打开相机而不是全屏

问题描述

我正在尝试在视图中打开相机,我已经设置了视图的高度和宽度,但它正在全屏打开。我用过react-native-camerareact-native-image-crop-picker图书馆。下面是我用来实现上面的代码:

rendercamera = () =>{
    ImagePicker.openCamera({
        width: width*0.5,
        height: 400,
        cropping: true,
    }).then(image => {
        console.log(image);
    });
}
render() {
    return (
      <View style={styles.containers}>
        <ScrollView>
          <View style={styles.header}>
            <TouchableOpacity onPress={this._goBack}>
              <Image
                style={styles.backicon}
                source={images.backArrowAn}
              />
            </TouchableOpacity>
            <Text style={styles.headerText}>Add Id Card</Text>
            <View style={styles.backicon}></View>
          </View>

          <View
            style={{
              width: width,
              alignItems: "flex-end",
              justifyContent: "center",
              marginTop: height * 0.12,
              alignSelf: "center",
              alignItems: "flex-end"
            }}
          >
          {this.rendercamera()}
          </View>
        </ScrollView>
      </View>
    );
}

任何人都可以帮忙吗?

标签: androidiosreact-native

解决方案


您的软件包 ImagePicker 没有这样做的能力。尝试使用react-native-camera

<RNCamera
      ref={ref => {
        this.camera = ref;
      }}
      style={{//Your style code
        }}
      type={RNCamera.Constants.Type.back}
      flashMode={RNCamera.Constants.FlashMode.on}
      androidCameraPermissionOptions={{
        title: 'Permission to use camera',
        message: 'We need your permission to use your camera',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel',
      }}
      androidRecordAudioPermissionOptions={{
        title: 'Permission to use audio recording',
        message: 'We need your permission to use your audio',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel',
      }}
      onGoogleVisionBarcodesDetected={({ barcodes }) => {
        console.log(barcodes);
      }}
    />

推荐阅读