@@ -2,9 +2,24 @@ import { beforeAll, describe, expect, it } from 'react-native-harness'
22import type {
33 CameraDevice ,
44 CameraDeviceFactory ,
5+ MeteringMode ,
56} from 'react-native-vision-camera'
67import { CommonResolutions , VisionCamera } from 'react-native-vision-camera'
78
9+ const getSupportedMeteringModes = ( device : CameraDevice ) : MeteringMode [ ] => {
10+ const modes : MeteringMode [ ] = [ ]
11+ if ( device . supportsExposureMetering ) {
12+ modes . push ( 'AE' )
13+ }
14+ if ( device . supportsFocusMetering ) {
15+ modes . push ( 'AF' )
16+ }
17+ if ( device . supportsWhiteBalanceMetering ) {
18+ modes . push ( 'AWB' )
19+ }
20+ return modes
21+ }
22+
823describe ( 'VisionCamera - Controller' , ( ) => {
924 let factory : CameraDeviceFactory
1025 let backDevice : CameraDevice
@@ -487,6 +502,64 @@ describe('VisionCamera - Controller', () => {
487502 }
488503 } )
489504
505+ it ( 'locks metering modes after focusTo with locked adaptiveness' , async ( context ) => {
506+ const modes = getSupportedMeteringModes ( backDevice )
507+ if ( modes . length === 0 ) {
508+ return context . skip ( 'focusTo locked: no supported metering modes' )
509+ }
510+ const session = await VisionCamera . createCameraSession ( false )
511+ const photoOutput = VisionCamera . createPhotoOutput ( {
512+ targetResolution : CommonResolutions . HD_4_3 ,
513+ containerFormat : 'jpeg' ,
514+ quality : 0.8 ,
515+ qualityPrioritization : 'balanced' ,
516+ } )
517+ const [ controller ] = await session . configure ( [
518+ {
519+ input : backDevice ,
520+ outputs : [ { output : photoOutput , mirrorMode : 'auto' } ] ,
521+ constraints : [ ] ,
522+ } ,
523+ ] )
524+ if ( controller == null ) throw new Error ( 'no controller' )
525+ await session . start ( )
526+
527+ try {
528+ const point = VisionCamera . createNormalizedMeteringPoint ( 0.5 , 0.5 )
529+ await controller . focusTo ( point , {
530+ modes,
531+ responsiveness : 'snappy' ,
532+ adaptiveness : 'locked' ,
533+ autoResetAfter : null ,
534+ } )
535+
536+ if ( modes . includes ( 'AF' ) ) {
537+ expect ( controller . focusMode ) . toBe ( 'locked' )
538+ }
539+ if ( modes . includes ( 'AE' ) ) {
540+ expect ( controller . exposureMode ) . toBe ( 'locked' )
541+ }
542+ if ( modes . includes ( 'AWB' ) ) {
543+ expect ( controller . whiteBalanceMode ) . toBe ( 'locked' )
544+ }
545+
546+ await controller . resetFocus ( )
547+ if ( modes . includes ( 'AF' ) ) {
548+ expect ( controller . focusMode ) . toBe ( 'continuous-auto-focus' )
549+ }
550+ if ( modes . includes ( 'AE' ) ) {
551+ expect ( controller . exposureMode ) . toBe ( 'continuous-auto-exposure' )
552+ }
553+ if ( modes . includes ( 'AWB' ) ) {
554+ expect ( controller . whiteBalanceMode ) . toBe (
555+ 'continuous-auto-white-balance' ,
556+ )
557+ }
558+ } finally {
559+ await session . stop ( )
560+ }
561+ } )
562+
490563 it ( 'enables low-light boost via CameraController.configure when supported' , async ( context ) => {
491564 const lowLightDevice = factory . cameraDevices . find (
492565 ( d ) => d . supportsLowLightBoost ,
0 commit comments