Skip to main content

API

Hooks

tip

All of these hooks must be called inside an RNMLKitFaceDetectionContextProvider.

useFacesInPhoto

Custom hook for detecting faces in a photo using ML Kit.

Parameters

  • imageUri?: string - The local URI of the image to detect faces in.

Return Type

  • UseFaceDetectorReturnType: Object

    • clearFaces: Function - Clears the detected faces.
    • error: string | undefined - Any potential errors during detection.
    • status: FaceDetectionState - Status of the face detection.
    • faces: RNMLKitFace[] - Array of detected faces.

Usage

import { useFacesInPhoto } from "@infinitered/react-native-mlkit-face-detection";

function FaceDetectionComponent() {
const { faces, error, status } = useFacesInPhoto('local_uri_of_your_image_uri');
// ... rest of your component
}

useFaceDetector

Hook used to directly access the faceDetector instance provided by the context.

Return Type

  • faceDetector: RNMLKitFaceDetector - Instance of the face detector.

Usage

import { useFaceDetector } from "@infinitered/react-native-mlkit-face-detection";

const faceDetector = useFaceDetector();
// ... rest of your usage

Context

ReactMLKitFaceDetectionContextValue

Represents the context value for ML Kit Face Detection in React.

PropertyDescriptionTypeDefault
faceDetectorInstance of the RNMLKitFaceDetector.RNMLKitFaceDetector-

ReactMLKitFaceDetectionContext

The context for ML Kit Face Detection in React.

PropertyDescriptionTypeDefault
faceDetectorDefault instance of the RNMLKitFaceDetector.RNMLKitFaceDetectorNew instance of RNMLKitFaceDetector

RNMLKitFaceDetectionContextProvider

A provider component for the ML Kit Face Detection context.

PropertyDescriptionTypeDefault
optionsOptions for the face detector.RNMLKitFaceDetectorOptions-
deferInitializationDefer the initialization of the face detector.boolean-
childrenChildren components.ReactNode-

Usage:

import { RNMLKitFaceDetectionContextProvider } from 'path-to-context';

function App() {
return (
<RNMLKitFaceDetectionContextProvider options={yourOptions}>
{/* Your components */}
</RNMLKitFaceDetectionContextProvider>
);
}