世博会,ReactNative,相机不会翻转

时间:2018-03-01 12:16:00

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

我正在关注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>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您将相机type支柱放在一个Icon上,但它是一个需要转到Camera组件的道具。