Installation
-
Install the packages
Terminal window npx expo install react-native-mediapipe-posedetection react-native-vision-camera react-native-worklets-core -
Add the worklets Babel plugin
Frame processors run as worklets, so
babel.config.jsneeds the worklets plugin:babel.config.js module.exports = function (api) {api.cache(true);return {presets: ['babel-preset-expo'],plugins: [['react-native-worklets-core/plugin']],};}; -
Configure the plugins in
app.jsonapp.json {"expo": {"plugins": [["react-native-vision-camera",{"cameraPermissionText": "$(PRODUCT_NAME) uses the camera to track your body pose."}],["react-native-mediapipe-posedetection",{"assetsPaths": ["./assets/models/"]}]]}}The second plugin copies every file in
assets/models/into the native projects. See Model files for which model to download. -
Build a development client
This library contains native code, so it won’t run in Expo Go.
Terminal window npx expo prebuild --cleannpx expo run:ios # or: npx expo run:androidOr build with EAS:
eas build --profile development.
-
Install the packages
Terminal window npm install react-native-mediapipe-posedetection react-native-vision-camera react-native-worklets-core -
Add the worklets Babel plugin
babel.config.js module.exports = {presets: ['module:@react-native/babel-preset'],plugins: [['react-native-worklets-core/plugin']],}; -
Make sure the New Architecture is on
It’s the default from React Native 0.76. On older versions:
android/gradle.properties newArchEnabled=trueTerminal window cd ios && RCT_NEW_ARCH_ENABLED=1 pod install -
Add camera permissions
ios/YourApp/Info.plist <key>NSCameraUsageDescription</key><string>$(PRODUCT_NAME) uses the camera to track your body pose.</string>android/app/src/main/AndroidManifest.xml <uses-permission android:name="android.permission.CAMERA" /> -
Install pods and add a model file
Terminal window cd ios && pod installThen add a
.taskmodel to both platforms as described in Model files. -
Rebuild the app
Native code changed, so do a full rebuild rather than a Metro reload.
Ask for camera permission at runtime
Section titled “Ask for camera permission at runtime”VisionCamera needs permission before the camera will start:
import { useCameraPermission } from 'react-native-vision-camera';
const { hasPermission, requestPermission } = useCameraPermission();
useEffect(() => { if (!hasPermission) requestPermission();}, [hasPermission, requestPermission]);Next: get a model file.