Add face detection#787
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, cross-platform face detection API to <Camera />, emitting per-frame face bounding boxes (normalized) and head-pose angles, implemented natively with Apple Vision (iOS) and ML Kit (Android), plus docs and an example UI.
Changes:
- Adds new JS/Fabric props + event types for face detection (
faceDetectionEnabled,faceDetectionThrottleMs,onFaceDetected,onFaceDetectionInstallStatus). - Implements iOS face detection via
AVCaptureVideoDataOutput+ Vision request with native throttling. - Implements Android face detection via a CameraX
ImageAnalysisanalyzer using unbundled ML Kit + install-state eventing.
Reviewed changes
Copilot reviewed 20 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/specs/CameraNativeComponent.ts | Extends codegen spec with face detection props/events. |
| src/CameraProps.ts | Adds public TS types for face payloads + install state. |
| src/Camera.ios.tsx | Applies -1 sentinel default for faceDetectionThrottleMs. |
| src/Camera.android.tsx | Applies -1 sentinel default for faceDetectionThrottleMs. |
| ios/ReactNativeCameraKit/SimulatorCamera.swift | Adds no-op protocol stubs for simulator implementation. |
| ios/ReactNativeCameraKit/RealCamera.swift | Adds Vision queue, video output plumbing, orientation handling, and per-frame callback. |
| ios/ReactNativeCameraKit/FaceDetector.swift | New Vision-based detector with throttling + coordinate adjustment. |
| ios/ReactNativeCameraKit/CameraView.swift | Wires new props into camera instance + event emission. |
| ios/ReactNativeCameraKit/CameraProtocol.swift | Extends camera protocol with face detection methods. |
| ios/ReactNativeCameraKit/CKCameraViewComponentView.mm | Emits Fabric onFaceDetected event with typed payload. |
| ios/ReactNativeCameraKit/CKCameraManager.mm | Exports iOS Old Arch props for face detection enable/throttle + event. |
| example/src/CameraExample.tsx | Adds UI toggle + overlay rendering for detected faces and install banner. |
| example/ios/Podfile.lock | Bumps example pod version to match updated library version. |
| example/images/faceDetection.png | Adds example UI icon asset. |
| android/src/oldarch/java/com/rncamerakit/CKCameraManager.kt | Registers new events + props for Old Arch. |
| android/src/newarch/java/com/rncamerakit/CKCameraManager.kt | Registers new events + props for New Arch. |
| android/src/main/java/com/rncamerakit/events/FaceDetectionInstallStatusEvent.kt | New event for ML Kit module install lifecycle. |
| android/src/main/java/com/rncamerakit/events/FaceDetectedEvent.kt | New event carrying face payload array. |
| android/src/main/java/com/rncamerakit/FaceAnalyzer.kt | New CameraX analyzer: module install + throttled ML Kit detection. |
| android/src/main/java/com/rncamerakit/CKCamera.kt | Binds additional ImageAnalysis use case + mirrors front-camera bounds. |
| android/build.gradle | Adds unbundled ML Kit face detection dependency. |
| README.md | Documents new face detection props/events and Android pre-download option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
scarlac
approved these changes
May 7, 2026
scarlac
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds real-time face detection to
<Camera />, available on both iOS and Android via a single cross-platform API. Face detection is opt-in (faceDetectionEnabled) and emits one event per frame with bounding boxes (normalized 0–1, top-left, preview-space) and head-pose Euler angles (degrees) for each detected face.API added
faceDetectionEnabled: booleanfalse— zero cost when off.faceDetectionThrottleMs: number100. Hot-updatable on Android without rebinding.onFaceDetected: (event) => voidfacesarray when no faces detected.onFaceDetectionInstallStatus: (event) => voidImplementation
iOS — Apple Vision (
VNDetectFaceRectanglesRequest, revision 3). Built into the OS, no extra dependency, no module download.FaceDetector.swiftowns the Vision request, throttling, and coordinate transform.RealCameraattaches anAVCaptureVideoDataOutputonly while detection is enabled, dispatching frames on a dedicatedvisionQueue(off the session queue and off main).currentVisionOrientationis recomputed on device-orientation and camera-flip changes so Vision sees an upright image; front-camera mirroring is handled via*MirroredCGImagePropertyOrientationvalues.SimulatorCameragets no-op stubs.Android — Google ML Kit, unbundled variant (
com.google.android.gms:play-services-mlkit-face-detection:17.1.0). The model is downloaded by Play Services on first use rather than bundled in the APK.FaceAnalyzer.kt(anImageAnalysis.Analyzer) owns module-install lifecycle, throttling, and detection.ImageAnalysisuse case is added to the existing CameraX binding so face detection coexists with barcode scanning.MIN_FACE_SIZE = 0.15,PERFORMANCE_MODE_FAST, tracking enabled, no landmarks/classifications — keeps inference cheap.CKCamera.onFaceDetectedso JS coordinates match what the user sees in the (auto-mirrored) preview.onFaceDetectionInstallStatusso apps can show a loading state on first run. README documents the optional<meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="face" />manifest tag for apps that want Play Services to pre-download the model after install (no APK size impact).Notes for reviewers
AVCaptureVideoDataOutput(iOS) or faceImageAnalysisuse case (Android) is attached unlessfaceDetectionEnabledistrue.CKCameraManager.mm/oldarch/CKCameraManager.kt) and Fabric (CKCameraViewComponentView.mm/newarch/CKCameraManager.kt). Codegen spec updated insrc/specs/CameraNativeComponent.ts.boundsX/Y/Width/Heightas0–1in top-left preview space, with positive yaw = head-turned-right. iOS converts Vision's bottom-left origin and radians; Android divides MLKit's pixel rectangles by upright image dimensions and mirrors the front camera.play-services-mlkit-face-detection:17.1.0(unbundled — does not increase APK size).