diff --git a/README.md b/README.md index 2dafa2f0d..0f0e9c376 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ To have Play Services [pre-download the model in the background after the app is | `zoom` | `number` | Control the zoom. Default: `1.0` | | `maxZoom` | `number` | Maximum zoom allowed (but not beyond what camera allows). Default: `undefined` (camera default max) | | `onZoom` | Function | Callback when user makes a pinch gesture, regardless of what the `zoom` prop was set to. Returned event contains `zoom`. Ex: `onZoom={(e) => console.log(e.nativeEvent.zoom)}`. | -| `onTapToFocus` | Function | Callback when the user taps the preview to focus, fired alongside the built-in tap-to-focus so an overlay can be shown without suppressing focus and zoom. Returned event contains `x` and `y`, normalized 0-1 in preview space. Requires `focusMode` `'on'`. Ex: `onTapToFocus={(e) => console.log(e.nativeEvent.x, e.nativeEvent.y)}`. | +| `onTapToFocus` | Function | Callback when the user taps the preview to focus, fired alongside the built-in tap-to-focus so an overlay can be shown without suppressing focus and zoom. Returned event contains `x` and `y`, normalized 0-1 in preview space. On iOS, requires `focusMode` `'on'`. Ex: `onTapToFocus={(e) => console.log(e.nativeEvent.x, e.nativeEvent.y)}`. | | `torchMode` | `'on'`/`'off'` | Toggle flash light when camera is active. Default: `off` | | `cameraType` | CameraType.Back/CameraType.Front | Choose what camera to use. Default: `CameraType.Back` | | `onOrientationChange` | Function | Callback when physical device orientation changes. Returned event contains `orientation`. Ex: `onOrientationChange={(event) => console.log(event.nativeEvent.orientation)}`. Use `import { Orientation } from 'react-native-camera-kit'; if (event.nativeEvent.orientation === Orientation.PORTRAIT) { ... }` to understand the new value | diff --git a/android/src/main/java/com/rncamerakit/CKCamera.kt b/android/src/main/java/com/rncamerakit/CKCamera.kt index c577c53c9..62aeacedb 100644 --- a/android/src/main/java/com/rncamerakit/CKCamera.kt +++ b/android/src/main/java/com/rncamerakit/CKCamera.kt @@ -269,12 +269,20 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs }) // Tap to focus + var isMultiTouchGesture = false viewFinder.setOnTouchListener { _, event -> + if (event.actionMasked == MotionEvent.ACTION_DOWN) { + isMultiTouchGesture = false + } else if (event.pointerCount > 1) { + isMultiTouchGesture = true + } if (event.action != MotionEvent.ACTION_UP) { return@setOnTouchListener scaleDetector.onTouchEvent(event) } focusOnPoint(event.x, event.y) - onTapToFocus(event.x, event.y) + if (!isMultiTouchGesture) { + onTapToFocus(event.x, event.y) + } return@setOnTouchListener true } diff --git a/android/src/main/java/com/rncamerakit/events/TapToFocusEvent.kt b/android/src/main/java/com/rncamerakit/events/TapToFocusEvent.kt index 8f7973345..d44aaf2f7 100644 --- a/android/src/main/java/com/rncamerakit/events/TapToFocusEvent.kt +++ b/android/src/main/java/com/rncamerakit/events/TapToFocusEvent.kt @@ -12,6 +12,8 @@ class TapToFocusEvent( ) : Event(surfaceId, viewId) { override fun getEventName(): String = EVENT_NAME + override fun canCoalesce(): Boolean = false + override fun getEventData(): WritableMap = Arguments.createMap().apply { putDouble("x", x) diff --git a/src/CameraProps.ts b/src/CameraProps.ts index 539d96bc0..903054f91 100644 --- a/src/CameraProps.ts +++ b/src/CameraProps.ts @@ -140,7 +140,7 @@ export interface CameraProps extends ViewProps { * without replacing the camera's own gesture handling. * * Coordinates are normalized 0-1 in preview space, matching `onFaceDetected`. - * Requires `focusMode="on"` (the default), since that is when the + * On iOS, requires `focusMode="on"` (the default), since that is when the * tap-to-focus gesture is active. * * Note this is deliberately not called `onFocus`: `ViewProps` already