1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Mobile: Upgrade to React Native 0.77 (#12179)

This commit is contained in:
Henry Heino
2025-05-19 15:02:18 -07:00
committed by GitHub
parent cbf6d5506f
commit a4dacd65e6
38 changed files with 4191 additions and 3262 deletions

View File

@@ -1,9 +1,14 @@
import * as React from 'react';
import { CameraDirection } from '@joplin/lib/models/settings/builtInMetadata';
import { BarcodeSettings, CameraRatio, CameraView, useCameraPermissions } from 'expo-camera';
import { ForwardedRef, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
import { BarcodeSettings, CameraMountError, CameraRatio, CameraView, useCameraPermissions } from 'expo-camera';
import { ForwardedRef, forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
import useAsyncEffect from '@joplin/lib/hooks/useAsyncEffect';
import { CameraRef, Props } from './types';
import { _ } from '@joplin/lib/locale';
import { Platform } from 'react-native';
import Logger from '@joplin/utils/Logger';
const logger = Logger.create('Camera/expo');
const barcodeScannerSettings: BarcodeSettings = {
// Rocketbook pages use both QR and datamatrix
@@ -11,7 +16,9 @@ const barcodeScannerSettings: BarcodeSettings = {
};
const Camera = (props: Props, ref: ForwardedRef<CameraRef>) => {
const cameraRef = useRef<CameraView>(null);
const [camera, setCamera] = useState<CameraView|null>(null);
const cameraRef = useRef<CameraView>(camera);
cameraRef.current = camera;
useImperativeHandle(ref, () => ({
takePictureAsync: async () => {
@@ -42,12 +49,31 @@ const Camera = (props: Props, ref: ForwardedRef<CameraRef>) => {
}
}, [hasPermission, props.onHasPermission]);
const onMountError = useCallback((event: CameraMountError) => {
const message = _('Error starting camera: %s', event.message);
logger.error(message);
}, []);
useAsyncEffect(async (event) => {
// iOS issue workaround: Since upgrading to Expo SDK 52, closing and reopening the camera on iOS
// never emits onCameraReady. As a workaround, call .resumePreview and wait for it to resolve,
// rather than relying on the CameraView's onCameraReady prop.
if (Platform.OS === 'ios') {
// Work around an issue on iOS where the onCameraReady callback is never called.
// Instead, wait for the preview to start using resumePreview:
await camera.resumePreview();
if (event.cancelled) return;
props.onCameraReady();
}
}, [camera, props.onCameraReady]);
return <CameraView
ref={cameraRef}
ref={setCamera}
style={props.style}
facing={props.cameraType === CameraDirection.Front ? 'front' : 'back'}
ratio={props.ratio as CameraRatio}
onCameraReady={props.onCameraReady}
onCameraReady={Platform.OS === 'android' ? props.onCameraReady : undefined}
onMountError={onMountError}
animateShutter={false}
barcodeScannerSettings={barcodeScannerSettings}
onBarcodeScanned={props.codeScanner.onBarcodeScanned}

View File

@@ -18,6 +18,9 @@ import ScannedBarcodes from './ScannedBarcodes';
import { CameraRef } from './Camera/types';
import Camera from './Camera';
import { CameraResult } from './types';
import Logger from '@joplin/utils/Logger';
const logger = Logger.create('CameraView');
interface Props {
themeId: number;
@@ -130,6 +133,7 @@ const CameraViewComponent: React.FC<Props> = props => {
const codeScanner = useBarcodeScanner();
const onCameraReady = useCallback(() => {
logger.debug('Camera ready');
setCameraReady(true);
}, []);