React Native SDK
React Native quickstart for @layers/amba-react-native — install, configure, on-device session persistence, push registration, Apple/Google sign-in. Bare-RN-first; Expo flavors shown as sub-tabs.
@layers/amba-react-native is the React Native SDK. Same API as every other Amba SDK; sessions and anonymous identity are persisted on-device so users stay signed in across app restarts.
This page is bare React Native first — every snippet uses non-Expo libraries by default, with the Expo equivalent as a sub-tab. If you're on the Expo managed workflow, use @layers/amba-expo instead — same runtime, plus a config plugin that wires native config at prebuild time.
1. Install
Core package (both flavors):
Peer libraries for Apple/Google sign-in and push:
The runtime call into @layers/amba-react-native is identical either way — once you have an identity token (Apple/Google) or a push token (APNs/FCM), pass it to Amba.auth.signInWithSocial(...) / Amba.push.register(...) unchanged. Only the producer library differs.
Metro config for monorepos
If you consume @layers/amba-react-native via pnpm/yarn workspaces, point Metro at the workspace root so it can resolve hoisted dependencies:
Without watchFolders + resolver.nodeModulesPaths, Metro only looks in this package's local node_modules and fails with "Unable to resolve module @layers/amba-react-native".
2. Configure on app boot
Put AMBA_API_KEY=amb_dev_ck_XXXX in a .env file at the project root. react-native-config injects it at build time into Config.AMBA_API_KEY (no process.env indirection needed). See the react-native-config setup guide for the iOS / Android native config wiring (one-time).
Amba.configure() is idempotent — calling it again with the same key is a no-op. The default on-device storage adapter is installed automatically; if you need a different store (MMKV, Keychain) construct an AmbaClient directly and pass your own storage.
3. First event + first sign-in
Amba.events.track is authenticated server-side. Mint an anonymous session before the first track call:
Identical code on bare RN and Expo — @layers/amba-react-native is the only import either flavor needs at this layer. The default on-device storage adapter persists the session across app restarts; your users stay signed in across reboots.
4. Sign in with Apple
Add the Sign In with Apple capability in Xcode (Signing & Capabilities → + Capability → Sign In with Apple). One-time per target.
5. Sign in with Google
Configure your OAuth client IDs in Google's API credentials console. The iOS client ID and Android client ID must match the bundle ID / package name of each platform build.
6. Push registration
@notifee/react-native is a renderer for incoming notifications — it does not produce APNs/FCM tokens. The tokens come from the platform-native push module: PushNotificationIOS (built into React Native) for APNs, and Firebase Messaging (@react-native-firebase/messaging) for FCM. Notifee handles permissions on both platforms.
Call this once after sign-in (or after the user opts in). Tokens rotate; re-call on app cold-start to refresh. On real iOS hardware only — APNs token issuance is disabled on the simulator.
7. Collections
Same DSL as the web SDK — identical code on bare RN and Expo:
@layers/amba-react-native carries the full where DSL (eq, ne, gt, gte, lt, lte, in, notIn, like, ilike, isNull, isNotNull, plus and, or, not) — see the Web SDK page for the full operator surface.
8. Storage uploads
Storage uploads use the standard presign → PUT → commit flow. Where the flavors diverge is in how you read a local file into bytes — bare RN typically uses react-native-blob-util (full-featured filesystem + multipart helpers); Expo uses expo-file-system.
Bare React Native vs. Expo workflow
| Concern | Bare RN | Expo managed |
|---|---|---|
| Install | pnpm add + pod-install | npx expo install |
| Native iOS configuration | Edit Info.plist / Entitlements.plist directly | Use the @layers/amba-expo config plugin |
| Native Android configuration | Edit AndroidManifest.xml directly | Use the @layers/amba-expo config plugin |
| Apple sign-in capability | Add via Xcode → Signing & Capabilities | expo-apple-authentication adds it on expo prebuild |
| Push entitlements | Add via Xcode + Google Services file | @layers/amba-expo plugin adds APNs entitlement + reads google-services.json |
| Best for | Existing native iOS / Android codebases adding RN | Greenfield apps, EAS Build, OTA updates |
Either workflow runs the same @layers/amba-react-native runtime — the difference is only in how native config files get written.
Common pitfalls
Amba.configure()called inside a component render — calls happen on every re-render and racily replace the singleton. Always wrap inuseEffect(..., [])or call at module scope above your root component.- Push registration on simulators — APNs requires a real device. In bare RN,
PushNotificationIOS.requestPermissions()resolves without issuing a token on the simulator; in Expo,Notifications.getDevicePushTokenAsyncreturnsnull(the Expo snippet short-circuits whenDevice.isDeviceis false). Guard accordingly. - Sessions lost on app upgrade — the default on-device store persists across upgrades but a full app reinstall clears it. If you need cross-install persistence (rare), use iCloud Keychain on iOS + Backup Manager on Android via a custom
AmbaStorageadapter. - Hermes performance — on Hermes, React Native 0.73+ is required for full SDK performance. Earlier versions fall back to a slower JS-only path that's ~3× slower.
See also
- Expo SDK — the config plugin layer on top of this package.
- Client API reference — HTTP endpoint reference for every namespace.
- Code samples — same operations side-by-side with the other 7 SDKs.