0

I am following Expo Docs for using a camera, at the onPress I can see that the state of type gets changed from 0 to 1 and vice-versa at pressing the flip, but the camera is always on back.

this is my CameraComponent code

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>
    );
  }
}
David Schumann
  • 13,380
  • 9
  • 75
  • 96
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123

1 Answers1

0

You put the Camera type prop on an Icon, but its a prop that needs to go to the Camera component.