CameraView
The device camera — live preview plus still-photo capture — as a
Presentable: open it fullscreen, Router.push it, or embed it among a
screen's children as a live preview node. takePhoto() returns a
File (a host buffer handle), so a shot can go straight into a texture
(Texture2D.load(file)), an upload (FormData), or the share sheet (share(file)).
Host-optional — guard with CameraView.isSupported.
At a glance
const camera = CameraView() // back camera by default
await camera.open() // asks permission, presents the preview
const photo = await camera.takePhoto()
camera.close()
share(photo, 'My shot')API
CameraView.isSupported: boolean // static — does this host have a camera?
CameraView(options?: { facingMode?: 'front' | 'back' }) // default 'back'
camera.open(opts?: { transition }): Promise<void> // request permission, present the preview
camera.setFacingMode(mode: 'front' | 'back'): Promise<void> // switch while the preview is live
camera.takePhoto(): Promise<File> // host-encoded still image
camera.close(): void // dismiss, release the cameraopen()follows the prepare-then-present contract (same asARScene/QRScanner): the current destination stays visible while camera permission is requested; the swap — and thetransition, if you pass one — happens once the camera is ready. It rejects if permission is denied, the host has no camera, or another navigation superseded it — handle it.- A camera is a full
NativeViewover the host-registered"camera"view:Router.push(camera)works, and it embeds as a layout node — a live viewfinder inside your screen, sized by its styles.isSupportedis exactly "did this host register the view". - Each
CameraView()is an instance, but the device camera is one session — don't keep two open at once.
Note
lifecycle — the camera stays claimed until close(). Always close when leaving the
screen (onClose), or the camera (and its OS indicator) stays on.
See also
- QRScanner — the scanning flavour of the camera
- Files & share —
share()a captured photo;openFilePickeras the non-camera way to get an image - Networking — the
Filehandle and uploading viaFormData