Skip to content

Commit 3980a0e

Browse files
authored
fix: Make useCamera(...) reactive to device changes (#3890)
fix: make useCamera reactive to device changes
1 parent 46240f1 commit 3980a0e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/react-native-vision-camera/src/hooks/useCamera.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useEffect, useMemo } from 'react'
2-
import { getAllCameraDevices } from '../CameraDevices'
32
import { getCameraDevice } from '../devices/getCameraDevice'
43
import type {
54
CameraController,
@@ -26,6 +25,7 @@ import { useCameraSession } from './internal/useCameraSession'
2625
import { useCameraSessionIsRunning } from './internal/useCameraSessionIsRunning'
2726
import { useListenerSubscription } from './internal/useListenerSubscription'
2827
import { useStableCallback } from './internal/useStableCallback'
28+
import { useCameraDevices } from './useCameraDevices'
2929
import { useOrientation } from './useOrientation'
3030

3131
export interface CameraProps {
@@ -256,11 +256,11 @@ export function useCamera({
256256
}, [orientation, outputs])
257257

258258
// 3. Get the input - either find one via position, or use the user provided one
259+
const devices = useCameraDevices()
259260
const input = useMemo(() => {
260261
if (typeof device === 'string') {
261262
// The user passed a `CameraPosition` (e.g. "back") - try to find a device ourselves
262263
const position = device
263-
const devices = getAllCameraDevices()
264264
const foundDevice = getCameraDevice(devices, position)
265265
if (foundDevice == null) {
266266
throw new Error(`This device does not have any "${position}" Cameras!`)
@@ -270,7 +270,7 @@ export function useCamera({
270270
// The user passed an actual device. return as-is.
271271
return device
272272
}
273-
}, [device])
273+
}, [device, devices])
274274

275275
// 4. Configure the session with the input + outputs to create a `CameraController`
276276
const controller = useCameraController(session, input, outputs, {

0 commit comments

Comments
 (0)