世博会相机黑色相机屏幕出现在android设备上

时间:2020-09-12 12:17:52

标签: android ios react-native expo expo-camera

samsung galaxy 9

export default class CameraPetpedia extends React.Component{
 state = {
  hasCameraPermission: null,
  hasCamerarollPermission:null,
 };

componentDidMount() {
this.getCameraPermissions();
this.getCameraRollPermissions();
}

async getCameraPermissions() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status === 'granted') {
  this.setState({ hasCameraPermission: true });
} else {
  this.setState({ hasCameraPermission: false });
  console.log('Uh oh! The user has not  granted us camera permission.');
}
}

async getCameraRollPermissions() {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
  this.setState({ hasCamerarollPermission: true });
} else {
  console.log('Uh oh! The user has not granted us permission.');
  this.setState({ hasCamerarollPermission: false });
}
}

takePicture = async () => {
  const {uri} = await this.camera.takePictureAsync();
  const save = await MediaLibrary.createAssetAsync(uri);
  console.log(uri)
 }



render() {
const { hasCameraPermission } = this.state;

if (hasCameraPermission === null) {
    return <View />;
} else if (hasCameraPermission === false) {
    return <Text>Access to camera has been denied.</Text>;
}
return (
    <View>
              
        <Camera style={styles.openCamera}  ref={ref => this.camera = ref} type={this.state.type} focusDepth={1}/>
        <Gallery/>
        {/* <FontAwesome name="bolt" style={styles.flashcamera}/>  */}
        <ClickButton takePhoto={this.takePicture}/>
        {/* Camera Flip or selfie */}
        <Ionicons  name="md-reverse-camera" style={styles.cameraFlip} 
            onPress=
            {() => { this.setState({type:this.state.type === Camera.Constants.Type.back ? Camera.Constants.Type.front: Camera.Constants.Type.back
            });}}/>
    </View>
);
 }
}
当重新加载android设备上的expo时,

相机的工作很棒,但是当我转到其他选项卡并返回到“相机”选项卡时,如图所示,它会显示黑屏。此相机代码在IOS设备上运行良好,但在android设备上运行不佳。请帮我解决这个问题。

0 个答案:

没有答案