Skip to content
  • Android
  • iOS
  • Web

Camera

Open the camera capture flow and read a photo’s URI and dimensions.

Examples

Quick start

Call from a user action. Capture requires a supported camera, camera permission, and a secure context on the web.

nayan-ui/camera
import { camera } from 'nayan-ui/camera';

export async function captureSize() {
  const photo = await camera.takePhoto({ maxDimension: 1024 });
  if (!photo) return null;
  try {
    return { width: photo.width, height: photo.height };
  } finally {
    await camera.release(photo.uri);
  }
}

Request camera access before capture

Start from a user action. Release the returned URI after saving or displaying the photo.

nayan-ui/camera
import { camera } from 'nayan-ui/camera';

export async function captureSquare() {
  if (!(await camera.isAvailable())) return null;
  const current = await camera.getPermission();
  if (current.requiresSettings) return null;
  const access = current.status === 'granted' ? current : await camera.requestPermission();
  if (access.status !== 'granted') return null;
  const photo = await camera.takePhoto({
    allowsEditing: true, aspect: [1, 1], format: 'jpeg', quality: 0.85, maxDimension: 1024
  });
  if (!photo) return null;
  return { photo, dispose: () => camera.release(photo.uri) };
}

Tags