【问题标题】:Expo, ReactNative, Camera does not FlipExpo,ReactNative,相机不翻转
【发布时间】:2018-03-01 12:16:00
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    您将 Camera type 道具放在图标上,但它的道具需要转到 Camera 组件。

    【讨论】:

    • 那太愚蠢了 :) 我缺少 type={this.state.type} 的相机标签,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多