Prerequisites
- A working React Native quickstart
- One mounted
NosmaiCameraView - An Expo development build or native React Native application, not Expo Go
Pause and resume the camera
Use the public methods when navigation keeps the screen mounted but hides it:
await NosmaiCameraSdk.pauseCamera(); await NosmaiCameraSdk.resumeCamera();
Serialize focus events so a late resume cannot run after cleanup begins.
Switch the camera
Await the result and disable the control while switching:
const switched = await NosmaiCameraSdk.switchCamera(); if (!switched) return;
A false result means a rapid or concurrent request was safely skipped; operational failures reject with a typed SDK error.
Clean up before remounting
Unmount the camera view and await cleanup before creating a new owner:
await NosmaiCameraSdk.cleanup();
Remove SDK event subscriptions in the same route cleanup. Do not mount the next camera screen until the cleanup Promise settles.
Verify it worked
Switch lenses, background and foreground the app, then navigate away and back ten times. The OS camera indicator must turn off after cleanup, listeners must not duplicate, and one Fabric camera view must own the session.
Common errors
| Error or symptom | Cause | Fix |
|---|---|---|
E_OPERATION_CANCELLED | Cleanup superseded a queued camera operation | Ignore the stale operation and wait for cleanup before remounting |
| Camera2 device error | Another controller or old view still owns Android camera hardware | Await cleanup and keep one mounted camera view |
| Events fire more than once | Subscriptions survived route teardown | Call remove() on every SDK subscription during cleanup |