React Native · Components
Gallery
Photo and video gallery (same API as Gallery on web): grid, masonry or rows layout, groups by date, virtual scrolling (even with 100,000 items only the visible ones are drawn), multiple selection by long-pressing and dragging, a full-screen view (Lightbox), infinite scroll and pagination.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Google Photos style: rows grouped by day, sticky headers, selection
Pinterest style masonry: loads as you scroll (with skeleton boxes)
Reels feed: vertical videos, swipe up to move on like Instagram
Upload to a server: progress ring, processing, error (tap to retry), an image that fails to load and renderItem
Paged grid: 240 items, 24 per page
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Gallery
componentPhoto and video gallery (same API as Gallery on web): grid, masonry or rows layout, groups by date, virtual scrolling (even with 100,000 items only the visible ones are drawn), multiple selection by long-pressing and dragging, a full-screen view (Lightbox), infinite scroll and pagination.
Examples
Lightbox
componentFull-screen view (same API as Lightbox on web): navigate by swiping sideways or up, zoom with two fingers and a double tap, close by pulling down. Videos play in the library's player.
Examples
mediaType
functionType of the item: inferred from the URL extension when type is omitted.
formatDuration
functionFormats a duration as 1:05 or 1:02:05.
Examples
GalleryAction
interfaceAn action in the selection bar (e.g. Share, Delete).
| Name | Type | Description |
|---|---|---|
label | string | Button text. |
icon? | IconProp | Icon: a name or an element. |
tone? | "neutral" | "danger" | Red when "danger". |
onClick | (items: GalleryItem[], clear: () => void) => unknown | Called with the selected items. If it returns a Promise the button shows loading until it finishes. Call clear() to end the selection. |
GalleryRenderContext
interfaceInformation passed to the GalleryProps.renderItem function.
| Name | Type | Description |
|---|---|---|
index | number | Index of the item. |
width | number | Width of the box. |
height | number | Height of the box. |
selected | boolean | The item is selected. |
selecting | boolean | The gallery is in selection mode. |
children | ReactNode | The built-in render: thumbnail, video badge, status and title. |
How a selected item is shown.
Settings of the Gallery page buttons (with pageSize).
GalleryPressEvent
interfaceEvent of a Gallery item tap.
| Name | Type | Description |
|---|---|---|
preventDefault | () => void | Prevents the full-screen view from opening. |
nativeEvent | GestureResponderEvent["nativeEvent"] | The press event. |
GalleryProps
interfaceProps of Gallery.
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly GalleryItem[] | Items. When grouping, give them sorted in group order (e.g. by date). | |
layout? | GalleryLayout | "grid" | Layout: "grid" equal squares, "masonry" Pinterest-style columns, "rows" Google Photos-style rows (each row fills the width). |
columns? | number | Fixed column count. If omitted, fitted to the width based on itemWidth. | |
itemWidth? | number | 120` (3 columns on a phone) | Target item width in grid and masonry. |
minColumns? | number | 3` in grid, `2` in masonry | Minimum column count when columns is not given. |
rowHeight? | number | 160 | Target row height in the rows layout. |
aspectRatio? | number | 1 | Cell ratio in the grid (width / height). |
gap? | number | 2 | Gap between items. |
groupBy? | GalleryGroupBy | ((item: GalleryItem, index: number) => string) | Grouping: "day" | "month" | "year" by the item's date field ("Today", "Yesterday", "Tuesday, October 28"…), or a function returning a group name from an item. | |
groupLabel? | (key: string, info: { count: number; start: number; }) => ReactNode | Group heading. If omitted the date or group name is written. | |
stickyHeaders? | boolean | true | Group headings stick to the top while scrolling. |
stickyOffset? | number | 0 | Distance of the sticky heading from the top. |
selectable? | boolean | false | Multiple selection (like iOS Photos): a long press starts selection; sliding without lifting the finger selects the ones in between too. In selection mode a tap selects/deselects, and a sideways swipe selects by dragging. Near the edge the list scrolls by itself. |
selected? | readonly string[] | Ids of the selected items in controlled use. | |
defaultSelected? | readonly string[] | Initially selected ones in uncontrolled use. | |
onSelectedChange? | (selected: string[]) => void | With the ids when the selection changes. | |
selectionStyle? | GallerySelectionStyle | "shrink" | Look of a selected item. |
selectionActions? | readonly GalleryAction[] | Actions in the selection bar. | |
selectionBar? | boolean | true | A selection bar at the bottom while there is a selection. |
effect? | EffectProp | Effect or effects of the tiles (e.g. "scale", "shine"). Defaults to UIProvider appearance.defaults.gallery.effect. | |
appear? | "fade" | "scale" | "none" | "fade" | Reveal when an image loads. |
rounded? | boolean | false` (edge to edge on a phone) | Rounded corners. |
videoPreview? | "hover" | "visible" | "none" | "none" | Preview in videos: "visible" the video nearest the center of the screen plays muted (phone feeds), "none". The "hover" of web does not exist on a phone; it behaves like "none". preview can be given for a light preview. |
videoFrames? | boolean | true | For videos without a poster, a frame is extracted and used as the poster. |
titles? | "hover" | "always" | Show item titles below the box ("hover" is not shown on a phone). | |
overlay? | (item: GalleryItem, index: number) => ReactNode | Extra content drawn on top of the box (e.g. a like badge). | |
renderItem? | (item: GalleryItem, context: GalleryRenderContext) => ReactNode | Render the inside of the box yourself; the built-in render comes in context.children. | |
onRetry? | (item: GalleryItem, index: number) => void | When an item with status="error" is tapped; when given, "Retry" shows on the tile. | |
lightbox? | boolean | LightboxOptions | true | Full-screen view that opens on tap. false turns it off. |
onItemClick? | (item: GalleryItem, index: number, event: GalleryPressEvent) => void | When an item is tapped (outside selection mode). event.preventDefault() does not open full screen. | |
onLoadMore? | () => unknown | Fetches the next items. If it returns a Promise skeletons show until it finishes. | |
hasMore? | boolean | false | There are more items to fetch. |
loadMore? | "scroll" | "button" | "scroll" | Next items: "scroll" near the end, "button" with a button. |
loading? | boolean | Loading: a skeleton grid when there are no items, skeleton boxes at the bottom otherwise. | |
pageSize? | number | Pagination: this many items per page. When total is given, items is the current page. | |
page? | number | Controlled page (starts at 1). | |
defaultPage? | number | 1 | Initial page. |
onPageChange? | (page: number) => void | When the page changes. | |
total? | number | Total item count for server-side pagination. | |
pagination? | GalleryPaginationOptions | Look of the page buttons. | |
height? | number | Height of the gallery. If omitted it fills its container (flex: 1). The gallery scrolls in its own scroll area; only visible items are drawn. | |
overscan? | number | 600 | Distance drawn ahead above and below the visible area. |
empty? | ReactNode | Content shown when there are no items. | |
label? | string | "Galeri" | Screen reader name. |
header? | ReactNode | Content added above the scroll area (header, filters); scrolls with it. | |
style? | StyleProp<ViewStyle> | Container style. | |
ref? | Ref<ViewRef> | Access to the container. | |
testID? | string | Test id. |
GalleryLayout
typeGallery layout.
GalleryMediaType
typeType of a gallery item.
GalleryGroupBy
typeBuilt-in grouping: by day, month or year of the item's date field.
LightboxAction
interfaceExtra action button in the top bar.
| Name | Type | Description |
|---|---|---|
label | string | Button name; for screen readers. |
icon | IconProp | Icon: a name or an element. |
tone? | "neutral" | "danger" | Red when "danger". |
onClick | (item: GalleryItem, index: number) => unknown | Called with the current item when tapped. If it returns a Promise the button shows loading until it finishes. |
LightboxRect
interfaceA rectangle on screen (window coordinates).
| Name | Type | Description |
|---|---|---|
x | number | Left edge (screen coordinates). |
y | number | Top edge (screen coordinates). |
width | number | Width. |
height | number | Height. |
LightboxOptions
interfaceSettings of the full-screen view (also given via Gallery lightbox).
| Name | Type | Default | Description |
|---|---|---|---|
mode? | "horizontal" | "vertical" | "horizontal" | Transition direction: "horizontal" swiping sideways (like photo apps), "vertical" swiping up like Reels / TikTok; videos play when they come on screen. |
loop? | boolean | false | Wrap from the end to the start (and from the start to the end). |
thumbnails? | boolean | true | A thumbnail strip at the bottom (horizontal only, wide screens: tablet). |
zoom? | boolean | true | Zoom on images: with two fingers and a double tap. When zoomed in, pan with a finger. |
preload? | number | 1 | Number of items prepared ahead on both sides of the visible one. |
download? | boolean | false | Download button: on a phone it opens the system share sheet ("Save image", "Save to Files" are there). |
share? | boolean | ((item: GalleryItem, index: number) => LightboxShareContent) | false` (when on, the item's address and title) | Share button (the system share sheet). When a function is given it returns the content to share: share={(item) => ({ url: \https://…/photo/${item.id}\ })}. |
slideshow? | boolean | number | false` (4000 ms when on) | Slideshow button. A number is the duration of each item (ms); videos advance when they end. |
captions? | boolean | true | Show the title and description at the bottom. |
videoFrames? | boolean | true | For videos without a poster, a frame is extracted and used as the poster. |
actions? | readonly LightboxAction[] | Extra action buttons. See LightboxAction. |
LightboxProps
interfaceProps of Lightbox.
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly GalleryItem[] | Items to show. | |
open? | boolean | Whether it is open in controlled use. | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | When it opens or closes. | |
index? | number | Index of the shown item in controlled use. | |
defaultIndex? | number | 0 | Initial index in uncontrolled use. |
onIndexChange? | (index: number) => void | With the new index when the item changes. | |
onReachEnd? | () => void | When nearing the last items; for fetching the next page in infinite lists. | |
originRect? | (index: number) => LightboxRect | null | undefined | On-screen location (window coordinates) of the thumbnail the image grows out of / returns to on open and close. Gallery provides it itself. | |
onRatio? | (item: GalleryItem, ratio: number) => void | Reports the measured aspect ratio. | |
label? | string | "Galeri" | Screen reader name. |
selectable? | boolean | false | Selection: a circle in the top bar that selects the current item. |
selected? | readonly string[] | Ids of the selected items (id, otherwise src). | |
onSelectedChange? | (selected: string[]) => void | With the ids when the selection changes. | |
mode? | "horizontal" | "vertical" | "horizontal" | Transition direction: "horizontal" swiping sideways (like photo apps), "vertical" swiping up like Reels / TikTok; videos play when they come on screen. |
loop? | boolean | false | Wrap from the end to the start (and from the start to the end). |
thumbnails? | boolean | true | A thumbnail strip at the bottom (horizontal only, wide screens: tablet). |
zoom? | boolean | true | Zoom on images: with two fingers and a double tap. When zoomed in, pan with a finger. |
preload? | number | 1 | Number of items prepared ahead on both sides of the visible one. |
download? | boolean | false | Download button: on a phone it opens the system share sheet ("Save image", "Save to Files" are there). |
share? | boolean | ((item: GalleryItem, index: number) => LightboxShareContent) | false` (when on, the item's address and title) | Share button (the system share sheet). When a function is given it returns the content to share: share={(item) => ({ url: \https://…/photo/${item.id}\ })}. |
slideshow? | boolean | number | false` (4000 ms when on) | Slideshow button. A number is the duration of each item (ms); videos advance when they end. |
captions? | boolean | true | Show the title and description at the bottom. |
videoFrames? | boolean | true | For videos without a poster, a frame is extracted and used as the poster. |
actions? | readonly LightboxAction[] | Extra action buttons. See LightboxAction. |
Status on the server: "uploading" (percentage with progress), "processing" (e.g. a video being transcoded), "error" failed. Not given for a ready item.
GalleryItem
interfaceAn item of Gallery and Lightbox.
| Name | Type | Description |
|---|---|---|
id? | string | Unique id; used for selection. Defaults to src. |
src | string | Full-size image or video address (opens in the full-screen view). |
thumbnail? | string | Thumbnail shown in the grid. Give it to avoid downloading large files in the grid; otherwise src is used for images and poster for videos. |
type? | GalleryMediaType | Type. If omitted it is inferred from the address's extension (.mp4, .webm, .mov → video). |
width? | number | Original width and height (px). Only the ratio is used; when given, the masonry and rows layouts draw correctly before images load and the page does not shift. Otherwise the ratio is measured when the image loads. |
height? | number | Original height (px). See width. |
alt? | string | Alternative text of the image (screen reader). |
title? | ReactNode | Title; shown on top and in the caption in full screen. |
description? | ReactNode | Description; shown at the bottom in full screen. |
poster? | string | Cover image of the video. |
preview? | string | A short, light preview video played when it comes on screen (videoPreview="visible"). If omitted src is played muted. |
duration? | number | Video duration (seconds); shown in the corner like 1:24. |
date? | Date | string | number | Date; used for grouping with groupBy="day" | "month" | "year". |
placeholder? | string | Color shown until the image loads (e.g. the image's dominant color #8a9bb0) or a small blurred image (data:image/...). |
disabled? | boolean | Cannot be selected. |
status? | GalleryItemStatus | Status on the server. When given, the tile shows a progress ring, "Processing" or an error, and the item does not open in full screen (it can be selected; e.g. to delete failed ones). While uploading, a local preview of the file (a file:// address) can be given as src. |
progress? | number | Progress while status="uploading", 0–1. Spins indeterminately if omitted. |
statusText? | ReactNode | Your own text next to the status (e.g. "Compressing…", the error reason). |