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 @@ -270,11 +270,10 @@ +setStagingMode: (stagingMode: boolean) => void, +pendingPhotoCapture: ?PhotoCapture, +setPendingPhotoCapture: (?PhotoCapture) => void, + +camera: { current: ?RNCamera }, }; class CameraModal extends React.PureComponent { - camera: ?RNCamera; - pinchEvent: EventResult; pinchHandler: ReactRef = React.createRef(); tapEvent: EventResult; @@ -518,8 +517,12 @@ this.cancelIndicatorAnimation.setValue(1); } - if (this.props.foreground && !prevProps.foreground && this.camera) { - void this.camera.refreshAuthorizationStatus(); + if ( + this.props.foreground && + !prevProps.foreground && + this.props.camera.current + ) { + void this.props.camera.current.refreshAuthorizationStatus(); } if (this.props.stagingMode && !prevProps.stagingMode) { @@ -750,7 +753,7 @@ autoFocusPointOfInterest={this.props.autoFocusPointOfInterest} style={styles.fill} androidCameraPermissionOptions={null} - ref={this.cameraRef} + ref={this.props.camera} > {this.renderCamera} @@ -759,10 +762,6 @@ ); } - cameraRef = (camera: ?RNCamera) => { - this.camera = camera; - }; - closeButtonRef = ( closeButton: ?React.ElementRef, ) => { @@ -849,7 +848,7 @@ }; takePhoto = async () => { - const { camera } = this; + const camera = this.props.camera.current; invariant(camera, 'camera ref should be set'); this.props.setStagingMode(true); @@ -917,8 +916,8 @@ }; clearPendingImage = () => { - invariant(this.camera, 'camera ref should be set'); - this.camera.resumePreview(); + invariant(this.props.camera.current, 'camera ref should be set'); + this.props.camera.current.resumePreview(); this.props.setStagingMode(false); this.props.setPendingPhotoCapture(); }; @@ -1216,6 +1215,8 @@ const [pendingPhotoCapture, setPendingPhotoCapture] = React.useState(); + const cameraRef = React.useRef(); + return ( ); });