|
1 | 1 | import React, {useRef} from 'react'; |
2 | | -import {Alert, View} from 'react-native'; |
| 2 | +import {Alert, Platform, View} from 'react-native'; |
3 | 3 | import {RESULTS} from 'react-native-permissions'; |
4 | 4 | import {useAnimatedStyle, useSharedValue, withSequence, withTiming} from 'react-native-reanimated'; |
5 | 5 | import type {PhotoFile} from 'react-native-vision-camera'; |
@@ -74,14 +74,19 @@ function Camera({onCapture, onPicked, shouldAcceptMultipleFiles = false, onLayou |
74 | 74 | cameraLoadingReasonAttributes, |
75 | 75 | } = useNativeCamera({context: 'Camera', onFocusStart, onFocusCleanup}); |
76 | 76 |
|
77 | | - // Prioritize photoResolution over videoResolution so the format selector picks a 4032x3024 |
78 | | - // format instead of the 5712x4284 (24.5MP) format that videoResolution:'max' would select. |
79 | | - // This cuts capture time roughly in half while maintaining the same output photo resolution. |
80 | | - // Use screen dimensions for video resolution since we only need enough for the preview. |
| 77 | + // Prioritize photoResolution so the format selector picks the configured PHOTO_WIDTH/PHOTO_HEIGHT |
| 78 | + // format. videoResolution is platform-specific: |
| 79 | + // - iOS: match the photo target — `takeSnapshot` reads from the video pipeline, so a smaller |
| 80 | + // video resolution would degrade the snapshot capture quality. |
| 81 | + // - Android: keep screen dimensions — `takeSnapshot` is a GPU screenshot of the preview surface |
| 82 | + // and doesn't depend on video resolution; constraining to screen size avoids burning GPU on a |
| 83 | + // higher-than-needed preview. |
81 | 84 | const format = useCameraFormat(device, [ |
82 | 85 | {photoAspectRatio: CONST.RECEIPT_CAMERA.PHOTO_ASPECT_RATIO}, |
83 | 86 | {photoResolution: {width: CONST.RECEIPT_CAMERA.PHOTO_WIDTH, height: CONST.RECEIPT_CAMERA.PHOTO_HEIGHT}}, |
84 | | - {videoResolution: {width: windowHeight, height: windowWidth}}, |
| 87 | + Platform.OS === 'ios' |
| 88 | + ? {videoResolution: {width: CONST.RECEIPT_CAMERA.PHOTO_WIDTH, height: CONST.RECEIPT_CAMERA.PHOTO_HEIGHT}} |
| 89 | + : {videoResolution: {width: windowHeight, height: windowWidth}}, |
85 | 90 | ]); |
86 | 91 | const cameraAspectRatio = getCameraAspectRatio(format, isInLandscapeMode); |
87 | 92 | const fps = format ? Math.min(Math.max(30, format.minFps), format.maxFps) : 30; |
|
0 commit comments