infinitered / react-native-mlkit

The definitive MLKit wrapper for React Native and Expo
https://docs.infinite.red/react-native-mlkit/
185 stars 13 forks source link

Introduce Hooks- and Context-based API for face detection, and document #35

Closed trevor-coleman closed 1 year ago

trevor-coleman commented 1 year ago

Refactors the face detection API to use a hook- and context- based approach, which greatly simplifies things for the user.

// App.tsx

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

function App() {
  return (
    <RNMLKitFaceDetectionContextProvider>
      {/* rest of your app goes here */}
    </RNMLKitFaceDetectionContextProvider>
  );
}

And then in the component:

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

function FaceDetectionComponent() {
  const { faces, error, status } = useFacesInPhoto('local_uri_of_your_image_uri');

  if (error) {
    return <Text>Error: {error}</Text>;
  }

  return (<View>
    {faces.map((face) => (
      <View key={face.trackingId}>
        <Text>{JSON.stringify(face)}</Text>
      </View>
    ))}
  </View>)
}
changeset-bot[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: 5eb60a9ff8e323fa7e8c047d4107ebfa6f3fd541

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages | Name | Type | | ---------------------------------------------- | ----- | | @infinitered/react-native-mlkit-face-detection | Minor | | docusaurus | Patch | | @infinitered/infinite-red-ai | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR