|
| 1 | +import { Tab, Tabs } from '@rspress/core/theme'; |
| 2 | + |
| 3 | +# Custom Components |
| 4 | + |
| 5 | +`react-native-gesture-image-viewer` offers powerful complete component customization. You can create gesture-supported items with not only images but any component you want. |
| 6 | + |
| 7 | +## Modal Components |
| 8 | + |
| 9 | +You can create a viewer using any `Modal` of your choice as shown below: |
| 10 | + |
| 11 | +<Tabs> |
| 12 | + <Tab label="Use Modal"> |
| 13 | + ```tsx |
| 14 | + import { FlatList, Image, Modal } from 'react-native'; |
| 15 | + import { GestureViewer } from 'react-native-gesture-image-viewer'; |
| 16 | + |
| 17 | + function App() { |
| 18 | + const images = [...]; |
| 19 | + const [visible, setVisible] = useState(false); |
| 20 | + |
| 21 | + return ( |
| 22 | + <Modal visible={visible} onRequestClose={() => setVisible(false)}> |
| 23 | + <GestureViewer |
| 24 | + data={images} |
| 25 | + renderItem={renderImage} |
| 26 | + ListComponent={FlatList} |
| 27 | + onDismiss={() => setVisible(false)} |
| 28 | + /> |
| 29 | + </Modal> |
| 30 | + ); |
| 31 | + } |
| 32 | + ``` |
| 33 | + </Tab> |
| 34 | + <Tab label="Use React Native Modal"> |
| 35 | + ```tsx |
| 36 | + import { FlatList, Image } from 'react-native'; |
| 37 | + import Modal from 'react-native-modal'; |
| 38 | + import { GestureViewer } from 'react-native-gesture-image-viewer'; |
| 39 | + |
| 40 | + function App() { |
| 41 | + const images = [...]; |
| 42 | + const [visible, setVisible] = useState(false); |
| 43 | + |
| 44 | + return ( |
| 45 | + <Modal |
| 46 | + isVisible={visible} |
| 47 | + onBackButtonPress={() => setVisible(false)} |
| 48 | + onBackdropPress={() => setVisible(false)} |
| 49 | + hasBackdrop={false} |
| 50 | + style={styles.modal} |
| 51 | + useNativeDriver={true} |
| 52 | + hideModalContentWhileAnimating={true} |
| 53 | + animationInTiming={300} |
| 54 | + animationOutTiming={300} |
| 55 | + > |
| 56 | + <GestureViewer |
| 57 | + data={images} |
| 58 | + renderItem={renderImage} |
| 59 | + ListComponent={FlatList} |
| 60 | + onDismiss={() => setVisible(false)} |
| 61 | + /> |
| 62 | + </Modal> |
| 63 | + ); |
| 64 | + } |
| 65 | + ``` |
| 66 | + </Tab> |
| 67 | +</Tabs> |
| 68 | + |
| 69 | +## List Components |
| 70 | + |
| 71 | +Support for any list component like `ScrollView`, `FlatList`, [`FlashList`](https://shopify.github.io/flash-list/) through the `ListComponent` prop. |
| 72 | +The `listProps` provides **type inference based on the selected list component**, ensuring accurate autocompletion and type safety in your IDE. |
| 73 | + |
| 74 | +```tsx |
| 75 | +import { FlashList } from '@shopify/flash-list'; |
| 76 | + |
| 77 | +function App() { |
| 78 | + return ( |
| 79 | + <GestureViewer |
| 80 | + data={images} |
| 81 | + ListComponent={FlashList} |
| 82 | + listProps={{ |
| 83 | + // ✅ FlashList props autocompletion |
| 84 | + }} |
| 85 | + /> |
| 86 | + ); |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Content Components |
| 91 | + |
| 92 | +You can inject various types of content components like [`expo-image`](https://docs.expo.dev/versions/latest/sdk/image/), [`FastImage`](https://github.com/DylanVann/react-native-fast-image), etc., through the `renderItem` prop to use gestures. |
| 93 | + |
| 94 | +```tsx |
| 95 | +import { GestureViewer } from 'react-native-gesture-image-viewer'; |
| 96 | +import { Image } from 'expo-image'; |
| 97 | + |
| 98 | +function App() { |
| 99 | + const renderImage = useCallback((imageUrl: string) => { |
| 100 | + return <Image source={{ uri: imageUrl }} style={{ width: '100%', height: '100%' }} contentFit="contain" />; |
| 101 | + }, []); |
| 102 | + |
| 103 | + return ( |
| 104 | + <GestureViewer |
| 105 | + data={images} |
| 106 | + renderItem={renderImage} |
| 107 | + /> |
| 108 | + ); |
| 109 | +} |
| 110 | +``` |
0 commit comments