簡體   English   中英

世博,ReactNative,相機不翻轉

[英]Expo, ReactNative, Camera does not Flip

我正在跟蹤Expo Docs以使用相機,在onPress我可以看到按下翻蓋時類型的狀態從0更改為1 ,反之亦然,但是相機始終在背面。

這是我的CameraComponent代碼

export default class CameraComponent extends Component {
  state = {
    hasCameraPermission: null,
    type: Camera.Constants.Type.back,
  };

  async componentWillMount() {
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({ hasCameraPermission: status === 'granted' });
  }

  render() {
    console.log('camera ==>', this.state.type);
    const { hasCameraPermission } = this.state;
    if (hasCameraPermission === null) {
      return <View />;
    } else if (hasCameraPermission === false) {
      return <Text>No access to camera</Text>;
    }
    return (
      <View style={{ flex: 1 }}>
        <Camera style={{ flex: 1 }}>
          <View style={{flex: 1,backgroundColor: 'transparent',flexDirection:'row',}}/>
          <View style={{flexDirection: 'row',justifyContent: 'space-between',paddingHorizontal: 10, marginBottom: 15,alignItems: 'flex-end',}}>
            <Icon name="md-reverse-camera"
              onPress={() => { console.log('flip pressed');
                this.setState({
                  type:
                    this.state.type === Camera.Constants.Type.back
                      ? Camera.Constants.Type.front
                      : Camera.Constants.Type.back,
                });
              }}
            />
          </View>
        </Camera>
      </View>
    );
  }
}

您將“攝影機” type道具放在“圖標”上,但它需要轉到“ Camera組件。

暫無
暫無

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

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