BNA

BNA UI
24

MediaPicker

A versatile component for selecting images and videos from device gallery or camera with preview capabilities.

Installation

pnpm dlx bna-ui add media-picker

Usage

import { MediaPicker } from '@/components/ui/media-picker';
<MediaPicker
  mediaType='all'
  multiple={true}
  maxSelection={5}
  onSelectionChange={(assets) => console.log(assets)}
/>

Examples

Default

Image Only

Video Only

Multiple Selection

With Preview

Quality Settings

API Reference

MediaPicker

The main component for selecting media from device gallery or camera.

PropTypeDefaultDescription
childrenReactNode-Custom trigger element. If not provided, uses default button.
styleViewStyle-Additional styles to apply to the container.
sizeButtonSize-Size of the default button trigger.
variantButtonVariant-Variant of the default button trigger.
iconComponentType<LucideProps>-Icon for the default button trigger.
disabledbooleanfalseWhether the media picker is disabled.
mediaType'image' | 'video' | 'all''all'Type of media to allow selection.
multiplebooleanfalseWhether to allow multiple selection.
maxSelectionnumber10Maximum number of items that can be selected.
quality'low' | 'medium' | 'high''high'Quality of selected media.
buttonTextstring-Text for the default button trigger.
placeholderstring-Placeholder text (currently unused).
gallerybooleanfalseWhether to show custom gallery modal.
showPreviewbooleantrueWhether to show preview of selected media.
previewSizenumber80Size of preview thumbnails in pixels.
selectedAssetsMediaAsset[][]Controlled selected assets.
onSelectionChange(assets: MediaAsset[]) => void-Callback when selection changes.
onError(error: string) => void-Callback when an error occurs.

MediaAsset

The interface for media assets returned by the picker.

PropertyTypeDescription
idstringUnique identifier for the asset.
uristringLocal URI of the selected media.
type'image' | 'video'Type of the media asset.
widthnumber?Width of the media in pixels.
heightnumber?Height of the media in pixels.
durationnumber?Duration in seconds for videos.
filenamestring?Original filename of the media.
fileSizenumber?File size in bytes.

Permissions

The MediaPicker component requires the following permissions:

  • iOS: NSPhotoLibraryUsageDescription in Info.plist
  • Android: READ_EXTERNAL_STORAGE permission

The component automatically requests these permissions when first used.

Features

  • Multiple Media Types: Support for images, videos, or both
  • Gallery Integration: Custom gallery modal or system picker
  • Preview Support: Show thumbnails of selected media
  • Quality Control: Adjustable media quality settings
  • Batch Selection: Select multiple items with configurable limits
  • Error Handling: Comprehensive error handling and callbacks
  • Accessibility: Built-in accessibility features
  • Theme Integration: Respects your app's theme colors

Accessibility

The MediaPicker component is built with accessibility in mind:

  • Proper labeling for screen readers
  • Keyboard navigation support
  • High contrast support for buttons and indicators
  • Semantic structure for better navigation
  • Error announcements for screen readers

Notes

  • The component uses expo-image-picker and expo-media-library for media selection
  • Permissions are automatically requested when needed
  • Selected assets are stored in memory during the session
  • Preview thumbnails are generated automatically
  • Video duration and file size information is included when available