Skip to content

Add the React Native component

Documents @snap4id-sdk/app-embed 1.0.0

With React Native, @snap4id-sdk/app-embed is the whole host side: it opens the page, injects the bridge before the page’s scripts, answers every message, runs the store purchase, finishes it after the unlock, delivers the files and recovers after a kill. You write a client config and one screen.

All SDK source code (packages, examples and these docs) is in the public GitHub repository lradomski10m/snap4id-sdk.

  • Your partner id from Snap4ID onboarding, and one consumable in-app purchase product in each store whose id you gave Snap4ID at onboarding (your app does not configure it: the page names it and shows its store price).
  • An Expo app (SDK 58, React Native 0.88) with a development build (expo-dev-client): the component has native code, so Expo Go does not work.
  • The snippets use Expo Router with the layout of the default npx create-expo-app template (SDK 58): routes in src/app/, the client in src/snap4id.ts. The template’s root layout is a tab bar with demo screens: replace it with the Stack of step 3 and src/app/index.tsx with your own home screen, then delete the template’s demo files (src/app/explore.tsx, src/components/, src/hooks/, src/constants/, src/global.css): nothing uses them any more, and some of them fail tsc and npx expo lint. Or keep your tabs and add flow as a full-screen route of the root Stack. Routes in app/ instead (older templates)? Import the client from '../src/snap4id'. Another navigator works the same way: start the client and mount <Snap4IdResume> in your root component, and render <Snap4IdFlow> on a full-screen screen of your own, below an opaque header.
  • Decided who checks purchases (choose your setup). This page lets Snap4ID check them; for your own backend you add one callback (step 2).
Terminal window
npx expo install expo-dev-client react-native-webview expo-iap expo-file-system expo-media-library expo-sharing expo-constants
npm install @snap4id-sdk/app-embed

Add the component’s config plugin to the plugins of app.json (npx expo install has already added expo-iap and some of the others there; keep them):

{
"expo": {
"plugins": ["@snap4id-sdk/app-embed", "expo-iap"]
}
}

(In an app.config.ts, the same list: plugins: ['@snap4id-sdk/app-embed', 'expo-iap'].) The config plugin writes the camera and photo-library usage texts and the Android camera permission. expo-media-library adds broader Android media permissions of its own: to trim them before a Play release, see config plugin. Rebuild the app.

src/snap4id.ts
import { createSnap4IdClient } from '@snap4id-sdk/app-embed';
export const snap4id = createSnap4IdClient({
partnerId: 'your-partner-id',
purchases: 'built-in',
onCompleted: async (completion) => {
// Called at least once per paid job until it resolves: key your work by completion.jobId.
await snap4id.downloadArtifacts(completion); // copies the files into your app's storage
},
onError: (error) => console.warn(error.code, error.message),
// Your backend checks receipts? Add onVerifyPurchase: see Set up payments → Your backend.
});
// src/app/_layout.tsx (replaces the template's tab layout)
import { Snap4IdResume } from '@snap4id-sdk/app-embed';
import { Stack } from 'expo-router';
import { useEffect } from 'react';
import { snap4id } from '../snap4id';
export default function Layout() {
useEffect(() => {
void snap4id.start(); // recovery: unfinished purchases, paid jobs not yet delivered
}, []);
return (
<>
{/* An opaque header: the flow's WebView must start below it (a transparent header covers the page). */}
<Stack screenOptions={{ headerTransparent: false }}>
<Stack.Screen name="index" options={{ title: 'My photos' }} />
<Stack.Screen name="flow" options={{ title: '' }} />
</Stack>
<Snap4IdResume client={snap4id} />
</>
);
}
src/app/flow.tsx
import { Snap4IdFlow } from '@snap4id-sdk/app-embed';
import { useNavigation } from 'expo-router';
import { snap4id } from '../snap4id';
// Your app's own analytics consent for Snap4ID's page; undefined ⇒ analytics stay off.
const statisticsConsent: boolean | undefined = undefined;
export default function Flow() {
const navigation = useNavigation();
return (
<Snap4IdFlow
client={snap4id}
consent={{ statistics: statisticsConsent }}
onStateChange={({ title }) => navigation.setOptions({ title })}
onClose={() => navigation.goBack()}
/>
);
}

Render it full screen under your own, opaque header (or, without a header, inside a safe-area view): the page has no chrome of its own. Open it from your home screen with router.push('/flow'). To reopen a job, pass jobId.

What onCompleted receives and how to show, save and share the stored files: receiving the files.

Run it on a simulator against the SDK’s fake Snap4ID page with the fake store, no Snap4ID or store account needed: fake store (two small dev-only additions to src/snap4id.ts, then npm run fake-page in the SDK checkout). A complete, copyable app is in the SDK repository under examples/partner-app: try it now.

Already have store code (or RevenueCat)? Use your own store code instead of 'built-in'. All options: component details and the component API.