diff --git a/native/media/camera-modal.react.js b/native/media/camera-modal.react.js
--- a/native/media/camera-modal.react.js
+++ b/native/media/camera-modal.react.js
@@ -250,10 +250,11 @@
+isActive: boolean,
+flashMode: number,
+changeFlashMode: () => void,
+ +useFrontCamera: boolean,
+ +switchCamera: () => void,
};
type State = {
+zoom: number,
- +useFrontCamera: boolean,
+hasCamerasOnBothSides: boolean,
+autoFocusPointOfInterest: ?{
x: number,
@@ -315,7 +316,6 @@
this.state = {
zoom: 0,
- useFrontCamera: props.deviceCameraInfo.defaultUseFrontCamera,
hasCamerasOnBothSides: props.deviceCameraInfo.hasCamerasOnBothSides,
autoFocusPointOfInterest: undefined,
stagingMode: false,
@@ -666,7 +666,7 @@
if (this.state.hasCamerasOnBothSides) {
switchCameraButton = (
) : null;
- const type = this.state.useFrontCamera
+ const type = this.props.useFrontCamera
? RNCamera.Constants.Type.front
: RNCamera.Constants.Type.back;
return (
@@ -855,14 +855,14 @@
invariant(camera, 'camera ref should be set');
this.setState({ stagingMode: true });
- // We avoid flipping this.state.useFrontCamera if we discover we don't
+ // We avoid flipping this.props.useFrontCamera if we discover we don't
// actually have a back camera since it causes a bit of lag, but this
// means there are cases where it is false but we are actually using the
// front camera
const { hasCamerasOnBothSides, defaultUseFrontCamera } =
this.props.deviceCameraInfo;
const usingFrontCamera =
- this.state.useFrontCamera ||
+ this.props.useFrontCamera ||
(!hasCamerasOnBothSides && defaultUseFrontCamera);
const startTime = Date.now();
@@ -929,12 +929,6 @@
});
};
- switchCamera = () => {
- this.setState((prevState: State) => ({
- useFrontCamera: !prevState.useFrontCamera,
- }));
- };
-
updateZoom = ([zoom]: [number]) => {
this.setState({ zoom });
};
@@ -1197,6 +1191,14 @@
});
}, []);
+ const [useFrontCamera, setUseFrontCamera] = React.useState(
+ deviceCameraInfo.defaultUseFrontCamera,
+ );
+
+ const switchCamera = React.useCallback(() => {
+ setUseFrontCamera(prevUseFrontCamera => !prevUseFrontCamera);
+ }, []);
+
return (
);
});