feat: Implement focus() on Android (#2523)

* feat: Implement `focus()` on Android

* Throw if not supported

* Do focus in example

* Format

* fix: Properly convert layer point to camera coordinates

* Fix

* Set trigger back to IDLE

* Fix rotation maybe?

* Rotated by

* fix: Fix display point calculation

* Try other

* Invoke `capture` callback on same thread

* Center metering rectangle

* Reset AF Trigger to IDLE

* Reset it to it's default AF mode again, i dont even know anymore

* Update CameraPage.tsx

* Format

* Apply options to repeating

* Set

* Use scene mode

* Update CameraPage.tsx

* Update CameraDeviceDetails.kt

* It fucking works

* Update PersistentCameraCaptureSession.kt

* Update PersistentCameraCaptureSession.kt

* Update PersistentCameraCaptureSession.kt

* Create CameraCaptureSession+setRepeatingRequestAndWait.kt

* Oh my god it works

* Also focus AE

* Cancel reset request

* Rename to AF

* Format

* Update PersistentCameraCaptureSession.kt
This commit is contained in:
Marc Rousavy
2024-02-08 15:16:58 +01:00
committed by GitHub
parent fce6616964
commit fb1d82ad9a
14 changed files with 288 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
import * as React from 'react'
import { useRef, useState, useCallback, useMemo } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { GestureResponderEvent, StyleSheet, Text, View } from 'react-native'
import { PinchGestureHandler, PinchGestureHandlerGestureEvent, TapGestureHandler } from 'react-native-gesture-handler'
import {
CameraProps,
@@ -125,6 +125,16 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
//#endregion
//#region Tap Gesture
const onFocusTap = useCallback(
({ nativeEvent: event }: GestureResponderEvent) => {
if (!device?.supportsFocus) return
camera.current?.focus({
x: event.locationX,
y: event.locationY,
})
},
[device?.supportsFocus],
)
const onDoubleTap = useCallback(() => {
onFlipCameraPressed()
}, [onFlipCameraPressed])
@@ -173,7 +183,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
<View style={styles.container}>
{device != null && (
<PinchGestureHandler onGestureEvent={onPinchGesture} enabled={isActive}>
<Reanimated.View style={StyleSheet.absoluteFill}>
<Reanimated.View onTouchEnd={onFocusTap} style={StyleSheet.absoluteFill}>
<TapGestureHandler onEnded={onDoubleTap} numberOfTaps={2}>
<ReanimatedCamera
style={StyleSheet.absoluteFill}
@@ -186,8 +196,8 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
onStopped={() => 'Camera stopped!'}
format={format}
fps={fps}
photoHdr={enableHdr}
videoHdr={enableHdr}
photoHdr={format?.supportsPhotoHdr && enableHdr}
videoHdr={format?.supportsVideoHdr && enableHdr}
lowLightBoost={device.supportsLowLightBoost && enableNightMode}
enableZoomGesture={false}
animatedProps={cameraAnimatedProps}