You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/docs/guides/ANIMATED.mdx
+21-7
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,17 @@ While you can use any animation library to animate the `zoom` property (or use n
21
21
22
22
### Implementation
23
23
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
+
24
35
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):
25
36
26
37
```tsx
@@ -68,14 +79,17 @@ export function App() {
68
79
}
69
80
```
70
81
71
-
### Explanation
82
+
### Min, Max and Neutral Zoom
72
83
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:
0 commit comments