npx gluestack-ui@alpha add image-viewerimport {
ImageViewer,
ImageViewerTrigger,
ImageViewerContent,
ImageViewerCloseButton,
ImageViewerNavigation,
ImageViewerCounter,
} from '@/components/ui/image-viewer';
export default () => (
<ImageViewer images={images}>
<ImageViewerTrigger>
<Image source={{ uri: '...' }} />
</ImageViewerTrigger>
<ImageViewerContent>
<ImageViewerCloseButton />
<ImageViewerNavigation />
<ImageViewerCounter />
</ImageViewerContent>
</ImageViewer>
);
| Prop | Type | Default | Description |
|---|---|---|---|
images | ImageItem[] | - | Array of images to display. Each item should have url and optional alt. |
defaultOpen | boolean | false | Whether the viewer is open by default (uncontrolled). |
isOpen | boolean | - | Controlled open state. Use with onOpenChange for controlled mode. |
onOpenChange | (isOpen: boolean) => void | - | Callback when open state changes. |
initialIndex | number | 0 | Index of the image to show initially. |
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Content to render as the trigger (usually an Image). |
onPress | () => void | - | Additional callback when trigger is pressed. |
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Child components like CloseButton, Navigation, Counter. |
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional Tailwind classes for styling. |
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional Tailwind classes for styling. |
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional Tailwind classes for styling. |
interface ImageItem {
url: string;
alt?: string;
}
interface ImageViewerProps {
images: ImageItem[];
defaultOpen?: boolean;
isOpen?: boolean;
onOpenChange?: (isOpen: boolean) => void;
initialIndex?: number;
}