LeCodesdocs

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

TypeScript
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

TypeScript
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 camera
  • open() follows the prepare-then-present contract (same as ARScene / QRScanner): the current destination stays visible while camera permission is requested; the swap — and the transition, 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 NativeView over 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. isSupported is 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 & shareshare() a captured photo; openFilePicker as the non-camera way to get an image
  • Networking — the File handle and uploading via FormData