react-native-gesture-image-viewer 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +333 -14
  2. package/package.json +25 -5
package/README.md CHANGED
@@ -1,33 +1,352 @@
1
- # react-native-gesture-image-viewer
1
+ # React Native Gesture Image Viewer
2
2
 
3
- react-native-gesture-image-viewer
3
+ > English | [한국어](./README-ko_kr.md)
4
4
 
5
- ## Installation
5
+ ## Overview
6
6
 
7
- ```sh
7
+ Have you ever struggled with implementing complex gesture handling and animations when building image galleries or content viewers in React Native?
8
+
9
+ Existing libraries often have limited customization options or performance issues. `react-native-gesture-image-viewer` is a high-performance **universal gesture viewer** library built on React Native Reanimated and Gesture Handler, providing complete customization and intuitive gesture support for not only images but also videos, custom components, and any other content.
10
+
11
+ ### Key Features
12
+
13
+ - ✅ **Complete Gesture Support** - Pinch zoom, double-tap zoom, swipe navigation, vertical drag dismiss
14
+ - ✅ **High-Performance Animations** - Smooth 60fps animations powered by React Native Reanimated
15
+ - ✅ **Full Customization** - Complete control over components, styles, and behaviors
16
+ - ✅ **External Control API** - Programmatic control from buttons or other components
17
+ - ✅ **Multi-Instance Management** - ID-based independent management of multiple viewers
18
+ - ✅ **Flexible Integration** - Use with FlatList, FlashList, Expo Image, FastImage, and more
19
+ - ✅ **Full TypeScript Support** - Type safety and enhanced developer experience
20
+ - ✅ **Cross-Platform** - iOS, Android, and Web support
21
+ - ✅ **Easy-to-Use API** - Intuitive and simple implementation without complex setup
22
+ - ✅ **Various Environment Support** - Expo Go and New Architecture support
23
+
24
+ ## Quick Start
25
+
26
+ ### Examples & Demo
27
+ - [📁 Example Project](/example/) - Real implementation code with various use cases
28
+ - [🤖 Expo Go](https://snack.expo.dev/@harang/react-native-gesture-image-viewer) - Try it instantly on Snack Expo
29
+
30
+ ### Prerequisites
31
+
32
+ > [!IMPORTANT]
33
+ > `react-native-gesture-image-viewer` is a high-performance viewer library built on [`react-native-reanimated`](https://www.npmjs.com/package/react-native-reanimated) and [`react-native-gesture-handler`](https://www.npmjs.com/package/react-native-gesture-handler).
34
+ > Therefore, you must install React Native Reanimated and Gesture Handler before using this library. Please refer to the official documentation of these libraries for detailed setup guides.
35
+
36
+ ```bash
37
+ npm install react-native-reanimated
38
+ npm install react-native-gesture-handler
39
+ ```
40
+
41
+ #### Minimum Requirements
42
+
43
+ |Library|Minimum Version|
44
+ |:--|:--:|
45
+ |`react`|`>=18.0.0`|
46
+ |`react-native`|`>=0.75.0`|
47
+ |`react-native-gesture-handler`|`>=2.24.0`|
48
+ |`react-native-reanimated`|`>=3.0.0`|
49
+
50
+ #### [React Native Reanimated Setup](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/)
51
+
52
+ Add the plugin to your `babel.config.js`:
53
+
54
+ ```js
55
+ // babel.config.js
56
+ module.exports = {
57
+ presets: [
58
+ ... // don't add it here :)
59
+ ],
60
+ plugins: [
61
+ ...
62
+ // for web
63
+ '@babel/plugin-proposal-export-namespace-from',
64
+ // react-native-reanimated/plugin has to be listed last.
65
+ 'react-native-reanimated/plugin',
66
+ ],
67
+ };
68
+ ```
69
+
70
+ Wrap your Metro config with `wrapWithReanimatedMetroConfig` in `metro.config.js`:
71
+
72
+ ```js
73
+ const {
74
+ wrapWithReanimatedMetroConfig,
75
+ } = require('react-native-reanimated/metro-config');
76
+
77
+ const config = {
78
+ // Your existing Metro configuration options
79
+ };
80
+
81
+ module.exports = wrapWithReanimatedMetroConfig(config);
82
+ ```
83
+
84
+ #### [react-native-gesture-handler Setup](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation)
85
+
86
+ - `react-native-gesture-handler` generally doesn't require additional setup, but please refer to the official documentation for your specific environment.
87
+ - For [using gestures in Android modals](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation#android), you would normally need to wrap modal content with `GestureHandlerRootView`. However, this library already includes `GestureHandlerRootView` internally, so no additional wrapping is needed when using modals.
88
+
89
+ ### Installation
90
+
91
+ ```bash
92
+ # npm
8
93
  npm install react-native-gesture-image-viewer
94
+
95
+ # pnpm
96
+ pnpm add react-native-gesture-image-viewer
97
+
98
+ # yarn
99
+ yarn add react-native-gesture-image-viewer
100
+
101
+ # bun
102
+ bun add react-native-gesture-image-viewer
9
103
  ```
10
104
 
11
105
  ## Usage
12
106
 
107
+ ### Basic Usage
13
108
 
14
- ```js
15
- import { multiply } from 'react-native-gesture-image-viewer';
109
+ `react-native-gesture-image-viewer` is a library focused purely on gesture interactions for complete customization.
110
+ You can create a viewer using any `Modal` of your choice as shown below:
111
+
112
+ ```tsx
113
+ import { Image, Modal } from 'react-native';
114
+ import { GestureImageViewer } from 'react-native-gesture-image-viewer';
16
115
 
17
- // ...
116
+ function App() {
117
+ const images = [...];
118
+ const [visible, setVisible] = useState(false);
18
119
 
19
- const result = await multiply(3, 7);
120
+ // Wrap with useCallback for performance optimization
121
+ const renderImage = useCallback((imageUrl: string) => {
122
+ return <Image source={{ uri: imageUrl }} style={{ width: '100%', height: '100%' }} resizeMode="contain" />;
123
+ }, []);
124
+
125
+ return (
126
+ <Modal visible={visible} onRequestClose={() => setVisible(false)}>
127
+ <GestureImageViewer
128
+ data={images}
129
+ renderImage={renderImage}
130
+ onDismiss={() => setVisible(false)}
131
+ />
132
+ </Modal>
133
+ );
134
+ }
20
135
  ```
21
136
 
137
+ ### Gesture Features
22
138
 
23
- ## Contributing
139
+ `react-native-gesture-image-viewer` supports various gestures essential for viewers. All gestures are enabled by default.
24
140
 
25
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
141
+ ```tsx
142
+ function App() {
143
+ return (
144
+ <GestureImageViewer
145
+ data={images}
146
+ renderImage={renderImage}
147
+ enableDismissGesture
148
+ enableSwipeGesture
149
+ enableZoomGesture
150
+ enableDoubleTapGesture
151
+ enableZoomPanGesture
152
+ />
153
+ )
154
+ }
155
+ ```
26
156
 
27
- ## License
157
+ |Property|Description|Default|
158
+ |:--:|:-----|:--:|
159
+ |`enableDismissGesture`|Calls `onDismiss` function when swiping down. Useful for closing modals with downward swipe gestures.|`true`|
160
+ |`enableSwipeGesture`|Controls left/right swipe gestures. When `false`, horizontal gestures are disabled.|`true`|
161
+ |`enableZoomGesture`|Controls two-finger pinch gestures. When `false`, two-finger zoom gestures are disabled.|`true`|
162
+ |`enableDoubleTapGesture`|Controls double-tap zoom gestures. When `false`, double-tap zoom gestures are disabled.|`true`|
163
+ |`enableZoomPanGesture`|Only works when zoom is active, allows moving item position when zoomed. When `false`, gesture movement is disabled during zoom.|`true`|
164
+
165
+ ### Custom Components
166
+
167
+ `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.
168
+
169
+ #### List Components
170
+
171
+ Support for `FlatList`, `FlashList`, `ScrollView` (⚠️ coming soon), and other list components through the `ListComponent` prop.
172
+ You can also customize the props of each supported list component through `listProps`.
173
+
174
+ ```tsx
175
+ function App() {
176
+ return (
177
+ <GestureImageViewer
178
+ data={images}
179
+ ListComponent={FlatList}
180
+ listProps={{
181
+ // ....
182
+ }}
183
+ />
184
+ );
185
+ }
186
+ ```
28
187
 
29
- MIT
188
+ #### Content Components
30
189
 
31
- ---
190
+ You can inject various types of content components like `expo-image`, `FastImage`, etc., through the `renderImage` prop to use gestures.
191
+
192
+ ```tsx
193
+ import { GestureImageViewer } from 'react-native-gesture-image-viewer';
194
+ import { Image } from 'expo-image';
195
+
196
+ function App() {
197
+ const renderImage = useCallback((imageUrl: string) => {
198
+ return <Image source={{ uri: imageUrl }} style={{ width: '100%', height: '100%' }} contentFit="contain" />;
199
+ }, []);
200
+
201
+ return (
202
+ <GestureImageViewer
203
+ data={images}
204
+ renderImage={renderImage}
205
+ />
206
+ );
207
+ }
208
+ ```
209
+
210
+ ### External Control API
211
+
212
+ `react-native-gesture-image-viewer` provides powerful hooks for programmatic control from buttons or other components.
213
+
214
+ ```tsx
215
+ import { GestureImageViewer, useImageViewerController } from 'react-native-gesture-image-viewer';
216
+
217
+ function App() {
218
+ const { goToIndex, goToPrevious, goToNext, currentIndex, totalCount } = useImageViewerController();
219
+
220
+ return (
221
+ <View>
222
+ <GestureImageViewer
223
+ data={images}
224
+ renderImage={renderImage}
225
+ />
226
+ <View
227
+ style={{
228
+ position: 'absolute',
229
+ bottom: 40,
230
+ left: 0,
231
+ right: 0,
232
+ gap: 10,
233
+ flexDirection: 'column',
234
+ }}
235
+ >
236
+ <Feather.Button name="chevron-left" onPress={goToPrevious} />
237
+ <Button title="Jump to index 2" onPress={() => goToIndex(2)} />
238
+ <Feather.Button name="chevron-right" onPress={goToNext} />
239
+ <Text>{`${currentIndex + 1} / ${totalCount}`}</Text>
240
+ </View>
241
+ </View>
242
+ );
243
+ }
244
+ ```
245
+
246
+ ### Style Customization
247
+
248
+ You can customize the styling of `GestureImageViewer`.
249
+
250
+ ```tsx
251
+ import { GestureImageViewer } from 'react-native-gesture-image-viewer';
252
+
253
+ function App() {
254
+ return (
255
+ <GestureImageViewer
256
+ animateBackdrop={false}
257
+ width={400}
258
+ containerStyle={{ /* ... */ }}
259
+ backdropStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.90)' }}
260
+ renderContainer={(children) => <View style={{ flex: 1 }}>{children}</View>}
261
+ />
262
+ );
263
+ }
264
+ ```
265
+
266
+ |Property|Description|Default|
267
+ |:--:|:-----|:--:|
268
+ |`animateBackdrop`|By default, the background `opacity` gradually decreases from 1 to 0 during downward swipe gestures. When `false`, this animation is disabled.|`true`|
269
+ |`width`|The width of content items. Default is window width.|`Dimensions width`|
270
+ |`containerStyle`|Allows custom styling of the container that wraps the list component.|`flex: 1`|
271
+ |`backdropStyle`|Allows customization of the viewer's background style.|`backgroundColor: black; StyleSheet.absoluteFill;`|
272
+ |`renderContainer`|Allows custom wrapper component around `<GestureImageViewer />`.||
273
+
274
+ ### Multi-Instance Management
275
+
276
+ When you want to efficiently manage multiple `GestureImageViewer` instances, you can use the `id` prop to use multiple `GestureImageViewer` components.
277
+ `GestureImageViewer` automatically removes instances from memory when components are unmounted, so no manual memory management is required.
278
+
279
+ > The default `id` value is `default`.
280
+
281
+ ```tsx
282
+ import { GestureImageViewer, useImageViewerController } from 'react-native-gesture-image-viewer';
283
+
284
+ const firstViewerId = 'firstViewerId';
285
+ const secondViewerId = 'secondViewerId';
286
+
287
+ function App() {
288
+ const { currentIndex: firstCurrentIndex, totalCount: firstTotalCount } = useImageViewerController(firstViewerId);
289
+ const { currentIndex: secondCurrentIndex, totalCount: secondTotalCount } = useImageViewerController(secondViewerId);
290
+
291
+ return (
292
+ <View>
293
+ <GestureImageViewer
294
+ id={firstViewerId}
295
+ data={images}
296
+ renderImage={renderImage}
297
+ />
298
+ <GestureImageViewer
299
+ id={secondViewerId}
300
+ data={images}
301
+ renderImage={renderImage}
302
+ />
303
+ </View>
304
+ );
305
+ }
306
+ ```
307
+
308
+ ### Additional Props
309
+
310
+ #### `onIndexChange`
311
+ The `onIndexChange` callback function is called when the `index` value changes.
312
+
313
+ ```tsx
314
+ import { GestureImageViewer } from 'react-native-gesture-image-viewer';
315
+
316
+ function App() {
317
+ const [currentIndex, setCurrentIndex] = useState(0);
318
+
319
+ return (
320
+ <GestureImageViewer
321
+ onIndexChange={setCurrentIndex}
322
+ />
323
+ );
324
+ }
325
+ ```
326
+
327
+ #### `initialIndex` (default: `0`)
328
+ Sets the initial index value.
329
+
330
+ #### `dismissThreshold` (default: `80`)
331
+ `dismissThreshold` controls when `onDismiss` is called by applying a threshold value during vertical gestures.
332
+
333
+ #### `resistance` (default: `2`)
334
+ `resistance` controls the range of vertical movement by applying resistance during vertical gestures.
335
+
336
+ #### `maxZoomScale` (default: `2`)
337
+ Controls the maximum zoom scale multiplier.
338
+
339
+ ## Performance Optimization Tips
340
+
341
+ - Wrap the `renderImage` function with `useCallback` to prevent unnecessary re-renders.
342
+ - For large images, we recommend using `FastImage` or `expo-image`.
343
+ - For handling many images, we recommend using `FlashList`.
344
+ - Test on actual devices (performance may be limited in simulators).
345
+
346
+ ## Contributing
347
+
348
+ For details on how to contribute to the project and set up the development environment, please refer to the [Contributing Guide](CONTRIBUTING.md).
349
+
350
+ ## License
32
351
 
33
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
352
+ [MIT](./LICENSE)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-gesture-image-viewer",
3
- "version": "0.3.1",
4
- "description": "react-native-gesture-image-viewer",
3
+ "version": "0.3.2",
4
+ "description": "🖼️ A highly customizable and easy-to-use React Native image viewer with gesture support and external controls",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
7
7
  "exports": {
@@ -43,7 +43,27 @@
43
43
  "keywords": [
44
44
  "react-native",
45
45
  "ios",
46
- "android"
46
+ "android",
47
+ "web",
48
+ "expo",
49
+ "image-viewer",
50
+ "image-gallery",
51
+ "gesture",
52
+ "pinch-to-zoom",
53
+ "swipe",
54
+ "zoom",
55
+ "customizable",
56
+ "modal",
57
+ "carousel",
58
+ "slider",
59
+ "photo-viewer",
60
+ "image-carousel",
61
+ "touch-gestures",
62
+ "react-native-reanimated",
63
+ "react-native-gesture-handler",
64
+ "lightbox",
65
+ "gallery",
66
+ "viewer"
47
67
  ],
48
68
  "repository": {
49
69
  "type": "git",
@@ -64,7 +84,7 @@
64
84
  "@changesets/cli": "^2.29.5",
65
85
  "@commitlint/config-conventional": "^19.6.0",
66
86
  "@evilmartians/lefthook": "^1.5.0",
67
- "@react-native/babel-preset": "0.78.2",
87
+ "@react-native/babel-preset": "0.79.5",
68
88
  "@types/babel__core": "^7",
69
89
  "@types/jest": "^29.5.5",
70
90
  "@types/react": "^19.0.12",
@@ -72,7 +92,7 @@
72
92
  "del-cli": "^5.1.0",
73
93
  "jest": "^29.7.0",
74
94
  "react": "19.0.0",
75
- "react-native": "0.79.4",
95
+ "react-native": "0.79.5",
76
96
  "react-native-builder-bob": "^0.40.12",
77
97
  "react-native-gesture-handler": "^2.24.0",
78
98
  "react-native-reanimated": "^3.18.0",