Skip to content
  • Android
  • iOS
  • Web

Image Picker

Let users choose an image from their library and inspect the selected asset.

Examples

Quick start

nayan-ui/image-picker
import { imagePicker } from 'nayan-ui/image-picker';

export async function selectImage() {
  const result = await imagePicker.pickFromLibrary({ maxDimension: 1024 });
  if (result.canceled) return null;
  const [image] = result.assets;
  try {
    return { name: image.fileName, width: image.width, height: image.height };
  } finally {
    await imagePicker.release(image.uri);
  }
}

Select multiple photos with bounded size

nayan-ui/image-picker
import { imagePicker } from 'nayan-ui/image-picker';

export async function pickGallery() {
  const result = await imagePicker.pickFromLibrary({ multiple: true, selectionLimit: 4, maxDimension: 1280 });
  if (result.canceled) return null;
  const { assets } = result;
  return { assets, dispose: () => Promise.all(assets.map(({ uri }) => imagePicker.release(uri))) };
}

Capture and crop a profile image

Call from a user action and release the selected URI after copying or displaying it.

nayan-ui/image-picker
import { imagePicker } from 'nayan-ui/image-picker';

export async function takeProfilePhoto() {
  const permission = await imagePicker.requestCameraPermission();
  if (permission.status !== 'granted') return null;
  const result = await imagePicker.launchCamera({ allowsEditing: true, aspect: [1, 1], maxDimension: 512 });
  return result.canceled ? null : result.assets[0] ?? null;
}

Tags