feat: BREAKING CHANGE: Express zoom factor always in actual factor value (1, 2, 128, ...) instead of 0.0-1.0 scale (#306)

* Make `zoom` go on "factor" scale

* Clean up `zoom` code

* fix float conversion

* fix zoom interpretation

* Update docs for new zoom scale

* fix float conversion
This commit is contained in:
Marc Rousavy
2021-07-29 11:44:22 +02:00
committed by GitHub
parent 6e2dc4e73b
commit 445af943c3
10 changed files with 46 additions and 41 deletions

View File

@@ -143,7 +143,7 @@ export interface CameraDeviceFormat {
*/
fieldOfView: number;
/**
* The maximum zoom factor
* The maximum zoom factor (e.g. `128`)
*/
maxZoom: number;
/**
@@ -216,27 +216,26 @@ export interface CameraDevice {
*/
isMultiCam: boolean;
/**
* Minimum available zoom factor
* Minimum available zoom factor (e.g. `1`)
*/
minZoom: number;
/**
* Maximum available zoom factor
* Maximum available zoom factor (e.g. `128`)
*/
maxZoom: number;
/**
* The zoom factor where the camera is "neutral".
*
* * For single-physical cameras this property is always `1.0`.
* * For multi cameras this property is a value between `minZoom` and `maxZoom`, where the camera is in _wide-angle_ mode and hasn't switched to the _ultra-wide-angle_ (`0.5`x zoom) or telephoto camera yet.
* * For multi cameras this property is a value between `minZoom` and `maxZoom`, where the camera is in _wide-angle_ mode and hasn't switched to the _ultra-wide-angle_ ("fish-eye") or telephoto camera yet.
*
* Use this value as an initial value for the zoom property if you implement custom zoom. (e.g. reanimated shared value should be initially set to this value)
* @example
* const device = ...
*
* const neutralZoomPercent = (device.neutralZoom - device.minZoom) / (device.maxZoom - device.minZoom)
* const zoomFactor = useSharedValue(neutralZoomPercent) // <-- initial value so it doesn't start at ultra-wide
* const zoom = useSharedValue(device.neutralZoom) // <-- initial value so it doesn't start at ultra-wide
* const cameraProps = useAnimatedProps(() => ({
* zoom: zoomFactor.value
* zoom: zoom.value
* }))
*/
neutralZoom: number;

View File

@@ -61,11 +61,15 @@ export interface CameraProps extends ViewProps {
*/
torch?: 'off' | 'on';
/**
* Specifies the zoom factor of the current camera, in percent. (`0.0` - `1.0`)
* Specifies the zoom factor of the current camera, in "factor"/scale.
*
* This value ranges from `minZoom` (e.g. `1`) to `maxZoom` (e.g. `128`). It is recommended to set this value
* to the CameraDevice's `neutralZoom` per default and let the user zoom out to the fish-eye (ultra-wide) camera
* on demand (if available)
*
* **Note:** Linearly increasing this value always appears logarithmic to the user.
*
* @default 0.0
* @default 1.0
*/
zoom?: number;
/**