Skip to content

Commit 8e520c4

Browse files
authored
docs: Update zooming
1 parent d60d58b commit 8e520c4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

docs/docs/guides/ANIMATED.mdx

+21-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ While you can use any animation library to animate the `zoom` property (or use n
2121

2222
### Implementation
2323

24+
#### Overview
25+
26+
1. Make the Camera View animatable using `Reanimated.createAnimatedComponent`
27+
2. Make the Camera's `zoom` property animatable using `addWhitelistedNativeProps`
28+
> Note that this might not be needed in the future, see: [reanimated#1409](https://github.com/software-mansion/react-native-reanimated/pull/1409)
29+
3. Create a SharedValue using [`useSharedValue`](https://docs.swmansion.com/react-native-reanimated/docs/api/useSharedValue) which represents the zoom state (from `0` to `1`)
30+
4. Use [`useAnimatedProps`](https://docs.swmansion.com/react-native-reanimated/docs/api/useAnimatedProps) to map the zoom SharedValue to the zoom property.
31+
5. We apply the animated props to the `ReanimatedCamera` component's `animatedProps` property.
32+
33+
#### Code
34+
2435
The following example implements a button which smoothly zooms to a random value using [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated):
2536

2637
```tsx
@@ -68,14 +79,17 @@ export function App() {
6879
}
6980
```
7081

71-
### Explanation
82+
### Min, Max and Neutral Zoom
7283

73-
1. The `Camera` was made animatable using `Reanimated.createAnimatedComponent`
74-
2. The `zoom` property is added to the whitelisted native props to make it animatable.
75-
> Note that this might not be needed in the future, see: [reanimated#1409](https://github.com/software-mansion/react-native-reanimated/pull/1409)
76-
3. Using [`useSharedValue`](https://docs.swmansion.com/react-native-reanimated/docs/api/useSharedValue), we're creating a shared value that holds the value for the `zoom` property.
77-
4. Using the [`useAnimatedProps`](https://docs.swmansion.com/react-native-reanimated/docs/api/useAnimatedProps) hook, we apply the shared value to Camera's `zoom` property.
78-
5. We apply the animated props to the `ReanimatedCamera` component's `animatedProps` property.
84+
A Camera device has different minimum, maximum and neutral zoom values. Those values are expressed through the `CameraDevice`'s [`minZoom`](/docs/api/interfaces/cameradevice.cameradevice-1#minzoom), [`maxZoom`](/docs/api/interfaces/cameradevice.cameradevice-1#maxzoom) and [`neutralZoom`](/docs/api/interfaces/cameradevice.cameradevice-1#neutralzoom) props, and are represented in "scale". So if the `maxZoom` property of a device is `2`, that means the view can be enlarged by twice it's zoom, aka the viewport halves.
85+
86+
* The `minZoom` value is always `1`.
87+
* The `maxZoom` value can have very high values (such as `128`), but often you want to clamp this value to something realistic like `16`.
88+
* The `neutralZoom` value is often `1`, but can be smaller than `1` for devices with "fish-eye" (ultra-wide-angle) cameras. In those cases, the user expects to be at whatever zoom value `neutralZoom` is (e.g. `2`) per default, and if he tries to zoom out even more, he goes to `minZoom` (`1`), which switches over to the "fish-eye" (ultra-wide-angle) camera as seen in this GIF:
89+
90+
<div align="center">
91+
<img src="https://developer.android.com/images/training/camera/multi-camera-4.gif" width="45%" />
92+
</div>
7993

8094
### Logarithmic scale
8195

0 commit comments

Comments
 (0)