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 @@ -274,11 +274,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; @@ -522,8 +521,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) { @@ -754,7 +757,7 @@ autoFocusPointOfInterest={this.props.autoFocusPointOfInterest} style={styles.fill} androidCameraPermissionOptions={null} - ref={this.cameraRef} + ref={this.props.camera} > {this.renderCamera} @@ -763,10 +766,6 @@ ); } - cameraRef = (camera: ?RNCamera) => { - this.camera = camera; - }; - closeButtonRef = ( closeButton: ?React.ElementRef, ) => { @@ -853,7 +852,7 @@ }; takePhoto = async () => { - const { camera } = this; + const camera = this.props.camera.current; invariant(camera, 'camera ref should be set'); this.props.setStagingMode(true); @@ -921,8 +920,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(); }; @@ -1217,6 +1216,8 @@ const [pendingPhotoCapture, setPendingPhotoCapture] = React.useState(); + const cameraRef = React.useRef(); + return ( ); });