---
title: Locking AE/AF/AWB
description: Manually locking Focus, Exposure and White-Balance
---

import { Tab, Tabs } from 'fumadocs-ui/components/tabs'

Exposure, Focus and White-Balance are typically automatically adjusted as the scene changes.
For pro-Camera apps, you can manually adjust Exposure Duration/ISO, Focus Lens Position and White-Balance Temperature and Tint Value and lock them in-place, if the device supports it.

### Setting specific values

#### Setting custom Exposure Duration/ISO

If the [`CameraDevice`](/api/react-native-vision-camera/hybrid-objects/CameraDevice) supports Exposure Locking (see [`supportsExposureLocking`](/api/react-native-vision-camera/hybrid-objects/CameraDevice#supportsexposurelocking)) you can set a custom Exposure Duration/ISO via [`setExposureLocked(...)`](/api/react-native-vision-camera/hybrid-objects/CameraController#setexposurelocked):

```ts
const controller = ...
const format = ...
if (controller.device.supportsExposureLocking) {
  const exposureDuration = 1 / 60
  const iso = 200
  await controller.setExposureLocked(exposureDuration, iso)
}
```

> [!WARNING]
> Make sure the given `exposureDuration` value is inside the current [`CameraController`](/api/react-native-vision-camera/hybrid-objects/CameraController)'s [`minExposureDuration`](/api/react-native-vision-camera/hybrid-objects/CameraController#minexposureduration) and [`maxExposureDuration`](/api/react-native-vision-camera/hybrid-objects/CameraController#maxexposureduration) bounds.
>
> Make sure the given `iso` value is inside the currently selected [`CameraController`](/api/react-native-vision-camera/hybrid-objects/CameraController)'s [`minISO`](/api/react-native-vision-camera/hybrid-objects/CameraController#miniso) and [`maxISO`](/api/react-native-vision-camera/hybrid-objects/CameraController#maxiso) bounds.

#### Setting custom Focus Lens Position

If the [`CameraDevice`](/api/react-native-vision-camera/hybrid-objects/CameraDevice) supports Focus Locking (see [`supportsFocusLocking`](/api/react-native-vision-camera/hybrid-objects/CameraDevice#supportsfocuslocking)) you can set a custom Focus Lens Position via [`setFocusLocked(...)`](/api/react-native-vision-camera/hybrid-objects/CameraController#setfocuslocked):

```ts
const controller = ...
if (controller.device.supportsFocusLocking) {
  const lensPosition = 0.5
  await controller.setFocusLocked(lensPosition)
}
```

> [!WARNING]
> Make sure the given `lensPosition` value is between `0.0` and `1.0`.

#### Setting custom White Balance Temperature and Tint

If the [`CameraDevice`](/api/react-native-vision-camera/hybrid-objects/CameraDevice) supports White-Balance Locking (see [`supportsWhiteBalanceLocking`](/api/react-native-vision-camera/hybrid-objects/CameraDevice#supportswhitebalancelocking)) you can set custom White Balance Temperature and Tint values via [`setWhiteBalanceLocked(...)`](/api/react-native-vision-camera/hybrid-objects/CameraController#setwhitebalancelocked):

```ts
const controller = ...
if (controller.device.supportsWhiteBalanceLocking) {
  const temperature = 4500
  const tint = 20
  await controller.setWhiteBalanceLocked(temperature, tint)
}
```

> [!WARNING]
> A good range for `temperature` is between 2500K and 8000K, and a good value for `tint` is usually between -150 and 150.

### Getting current values

At any point in time you can get the Camera's current Exposure, Focus or White-Balance values.

#### Getting current Exposure Duration/ISO

To get the current exposure values (for example to use VisionCamera as a light meter) use [`exposureDuration`](/api/react-native-vision-camera/hybrid-objects/CameraController#exposureduration) or [`iso`](/api/react-native-vision-camera/hybrid-objects/CameraController#iso):

```ts
const controller = ...
console.log(controller.exposureDuration)
console.log(controller.iso)
```

#### Getting current Focus Lens Position

To figure out how far away the current focus point is, simply get the current [`lensPosition`](/api/react-native-vision-camera/hybrid-objects/CameraController#lensposition):

```ts
const controller = ...
console.log(controller.lensPosition) // between 0...1
```

#### Getting current White Balance Gains

Lastly, the [`CameraController`](/api/react-native-vision-camera/hybrid-objects/CameraController) also exposes its current White-Balance Gains via [`whiteBalanceGains`](/api/react-native-vision-camera/hybrid-objects/CameraController#whitebalancegains):

```ts
const controller = ...
console.log(controller.whiteBalanceGains)
```

> [!WARNING]
> If the device does not support manual control over AE/AF/AWB, invalid values (e.g. `0`) will be returned.

### Locking current values

To lock the current Exposure/Focus/White-Balance values at their current value (for example, after a [tap to focus](tap-to-focus) action), use [`lockCurrentExposure()`](/api/react-native-vision-camera/hybrid-objects/CameraController#lockcurrentexposure), [`lockCurrentFocus()`](/api/react-native-vision-camera/hybrid-objects/CameraController#lockcurrentfocus) or [`lockCurrentWhiteBalance()`](/api/react-native-vision-camera/hybrid-objects/CameraController#lockcurrentwhitebalance):

```ts
const controller = ...
const meteringPoint = ...
await controller.focusTo(meteringPoint, {
  autoResetAfter: null
})

if (controller.device.supportsExposureLocking) {
  await controller.lockCurrentExposure()
}
if (controller.device.supportsFocusLocking) {
  await controller.lockCurrentFocus()
}
if (controller.device.supportsWhiteBalanceLocking) {
  await controller.lockCurrentWhiteBalance()
}
```

To reset Exposure/Focus/White-Balance back to auto, use [`resetFocus()`](/api/react-native-vision-camera/hybrid-objects/CameraController#resetfocus):

```ts
const controller = ...
await controller.resetFocus()
```

### Reacting to subject area changes

Once you lock AE/AF/AWB, the Camera keeps those values frozen no matter what the user points the device at. That's usually fine for a deliberate tap-to-focus, but if the user pans the Camera away from the subject, the scene becomes very under- or over-exposed and out-of-focus; so the locked values no longer make sense.

VisionCamera fires an [`onSubjectAreaChanged()`](/api/react-native-vision-camera/hybrid-objects/CameraController#addsubjectareachangedlistener) listener whenever the scene substantially changes - for example, when the focus point drifts off the previously-focused subject. You can listen for this event and automatically reset AE/AF/AWB back to continuously auto-adjusting via [`resetFocus()`](/api/react-native-vision-camera/hybrid-objects/CameraController#resetfocus):

<Tabs items={["<Camera /> (view)", "useCamera(...) (hook)", "CameraSession (imperative)"]} groupId="api-style" persist>
<Tab value="<Camera /> (view)">
```tsx
function App() {
  const camera = useRef<Camera>(null)

  return (
    <Camera
      style={StyleSheet.absoluteFill}
      isActive={true}
      device="back"
      ref={camera}
      // [!code ++:3]
      onSubjectAreaChanged={() => {
        camera.current?.resetFocus()
      }}
    />
  )
}
```
</Tab>
<Tab value="useCamera(...) (hook)">
```tsx
function App() {
  const camera = useCamera({
    isActive: true,
    device: 'back',
    // [!code ++:3]
    onSubjectAreaChanged: () => {
      camera?.resetFocus()
    }
  })
}
```
</Tab>
<Tab value="CameraSession (imperative)">
```tsx
const session = ...
const controller = await session.configure(...)
// [!code ++:3]
const listener = controller.addSubjectAreaChangedListener(() => {
  controller.resetFocus()
})
```
</Tab>
</Tabs>
