Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/ui-image-gallery.md
1---2title: Use Galeria for Image Galleries and Lightbox3impact: MEDIUM4impactDescription:5native shared element transitions, pinch-to-zoom, pan-to-close6tags: images, gallery, lightbox, expo-image, ui7---89## Use Galeria for Image Galleries and Lightbox1011For image galleries with lightbox (tap to fullscreen), use `@nandorojo/galeria`.12It provides native shared element transitions with pinch-to-zoom, double-tap13zoom, and pan-to-close. Works with any image component including `expo-image`.1415**Incorrect (custom modal implementation):**1617```tsx18function ImageGallery({ urls }: { urls: string[] }) {19const [selected, setSelected] = useState<string | null>(null)2021return (22<>23{urls.map((url) => (24<Pressable key={url} onPress={() => setSelected(url)}>25<Image source={{ uri: url }} style={styles.thumbnail} />26</Pressable>27))}28<Modal visible={!!selected} onRequestClose={() => setSelected(null)}>29<Image source={{ uri: selected! }} style={styles.fullscreen} />30</Modal>31</>32)33}34```3536**Correct (Galeria with expo-image):**3738```tsx39import { Galeria } from '@nandorojo/galeria'40import { Image } from 'expo-image'4142function ImageGallery({ urls }: { urls: string[] }) {43return (44<Galeria urls={urls}>45{urls.map((url, index) => (46<Galeria.Image index={index} key={url}>47<Image source={{ uri: url }} style={styles.thumbnail} />48</Galeria.Image>49))}50</Galeria>51)52}53```5455**Single image:**5657```tsx58import { Galeria } from '@nandorojo/galeria'59import { Image } from 'expo-image'6061function Avatar({ url }: { url: string }) {62return (63<Galeria urls={[url]}>64<Galeria.Image>65<Image source={{ uri: url }} style={styles.avatar} />66</Galeria.Image>67</Galeria>68)69}70```7172**With low-res thumbnails and high-res fullscreen:**7374```tsx75<Galeria urls={highResUrls}>76{lowResUrls.map((url, index) => (77<Galeria.Image index={index} key={url}>78<Image source={{ uri: url }} style={styles.thumbnail} />79</Galeria.Image>80))}81</Galeria>82```8384**With FlashList:**8586```tsx87<Galeria urls={urls}>88<FlashList89data={urls}90renderItem={({ item, index }) => (91<Galeria.Image index={index}>92<Image source={{ uri: item }} style={styles.thumbnail} />93</Galeria.Image>94)}95numColumns={3}96estimatedItemSize={100}97/>98</Galeria>99```100101Works with `expo-image`, `SolitoImage`, `react-native` Image, or any image102component.103104Reference: [Galeria](https://github.com/nandorojo/galeria)105