react-native-gesture-image-viewer 0.3.0 → 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.
- package/README.md +333 -14
- package/lib/module/ImageViewerRegistry.js +24 -0
- package/lib/module/ImageViewerRegistry.js.map +1 -1
- package/lib/module/useGestureImageViewer.js +30 -20
- package/lib/module/useGestureImageViewer.js.map +1 -1
- package/lib/module/useImageViewerController.js +22 -8
- package/lib/module/useImageViewerController.js.map +1 -1
- package/lib/typescript/src/ImageViewerRegistry.d.ts +3 -0
- package/lib/typescript/src/ImageViewerRegistry.d.ts.map +1 -1
- package/lib/typescript/src/useGestureImageViewer.d.ts.map +1 -1
- package/lib/typescript/src/useImageViewerController.d.ts.map +1 -1
- package/package.json +25 -5
- package/src/ImageViewerRegistry.ts +36 -0
- package/src/useGestureImageViewer.ts +35 -25
- package/src/useImageViewerController.ts +23 -9
package/README.md
CHANGED
|
@@ -1,33 +1,352 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React Native Gesture Image Viewer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> English | [한국어](./README-ko_kr.md)
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
+
`react-native-gesture-image-viewer` supports various gestures essential for viewers. All gestures are enabled by default.
|
|
24
140
|
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
352
|
+
[MIT](./LICENSE)
|
|
@@ -3,12 +3,29 @@
|
|
|
3
3
|
import ImageViewerManager from "./ImageViewerManager.js";
|
|
4
4
|
class ImageViewerRegistry {
|
|
5
5
|
managers = new Map();
|
|
6
|
+
subscribers = new Map();
|
|
7
|
+
subscribeToManager(id, callback) {
|
|
8
|
+
if (!this.subscribers.has(id)) {
|
|
9
|
+
this.subscribers.set(id, new Set());
|
|
10
|
+
}
|
|
11
|
+
this.subscribers.get(id)?.add(callback);
|
|
12
|
+
const manager = this.managers.get(id) || null;
|
|
13
|
+
callback(manager);
|
|
14
|
+
return () => {
|
|
15
|
+
const subscribers = this.subscribers.get(id);
|
|
16
|
+
subscribers?.delete(callback);
|
|
17
|
+
if (subscribers && subscribers.size === 0) {
|
|
18
|
+
this.subscribers.delete(id);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
6
22
|
createManager(id) {
|
|
7
23
|
if (this.managers.has(id)) {
|
|
8
24
|
return this.managers.get(id) || null;
|
|
9
25
|
}
|
|
10
26
|
const manager = new ImageViewerManager();
|
|
11
27
|
this.managers.set(id, manager);
|
|
28
|
+
this.notifySubscribers(id, manager);
|
|
12
29
|
return manager;
|
|
13
30
|
}
|
|
14
31
|
getManager(id) {
|
|
@@ -19,6 +36,13 @@ class ImageViewerRegistry {
|
|
|
19
36
|
if (manager) {
|
|
20
37
|
manager.cleanUp();
|
|
21
38
|
this.managers.delete(id);
|
|
39
|
+
this.notifySubscribers(id, null);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
notifySubscribers(id, manager) {
|
|
43
|
+
const listeners = this.subscribers.get(id);
|
|
44
|
+
if (listeners) {
|
|
45
|
+
[...listeners].forEach(callback => callback(manager));
|
|
22
46
|
}
|
|
23
47
|
}
|
|
24
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ImageViewerManager","ImageViewerRegistry","managers","Map","
|
|
1
|
+
{"version":3,"names":["ImageViewerManager","ImageViewerRegistry","managers","Map","subscribers","subscribeToManager","id","callback","has","set","Set","get","add","manager","delete","size","createManager","notifySubscribers","getManager","deleteManager","cleanUp","listeners","forEach","registry"],"sourceRoot":"../../src","sources":["ImageViewerRegistry.ts"],"mappings":";;AAAA,OAAOA,kBAAkB,MAAM,yBAAsB;AAErD,MAAMC,mBAAmB,CAAC;EAChBC,QAAQ,GAAG,IAAIC,GAAG,CAA6B,CAAC;EAChDC,WAAW,GAAG,IAAID,GAAG,CAA4D,CAAC;EAE1FE,kBAAkBA,CAACC,EAAU,EAAEC,QAAsD,EAAE;IACrF,IAAI,CAAC,IAAI,CAACH,WAAW,CAACI,GAAG,CAACF,EAAE,CAAC,EAAE;MAC7B,IAAI,CAACF,WAAW,CAACK,GAAG,CAACH,EAAE,EAAE,IAAII,GAAG,CAAC,CAAC,CAAC;IACrC;IAEA,IAAI,CAACN,WAAW,CAACO,GAAG,CAACL,EAAE,CAAC,EAAEM,GAAG,CAACL,QAAQ,CAAC;IAEvC,MAAMM,OAAO,GAAG,IAAI,CAACX,QAAQ,CAACS,GAAG,CAACL,EAAE,CAAC,IAAI,IAAI;IAE7CC,QAAQ,CAACM,OAAO,CAAC;IAEjB,OAAO,MAAM;MACX,MA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CAACC,OAAO,CAAEf,QAAQ,IAAKA,QAAQ,CAACM,OAAO,CAAC,CAAC;IACzD;EACF;AACF;AAEA,OAAO,MAAMU,QAAQ,GAAG,IAAItB,mBAAmB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -30,10 +30,9 @@ export const useGestureImageViewer = ({
|
|
|
30
30
|
} = useWindowDimensions();
|
|
31
31
|
const width = customWidth || screenWidth;
|
|
32
32
|
const [isZoomed, setIsZoomed] = useState(false);
|
|
33
|
-
const [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
33
|
+
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
|
34
|
+
const [manager, setManager] = useState(null);
|
|
35
|
+
const unsubscribeRef = useRef(null);
|
|
37
36
|
const initialTranslateY = useSharedValue(0);
|
|
38
37
|
const initialTranslateX = useSharedValue(0);
|
|
39
38
|
const startScale = useSharedValue(1);
|
|
@@ -47,15 +46,26 @@ export const useGestureImageViewer = ({
|
|
|
47
46
|
runOnJS(setIsZoomed)(currentScale > 1);
|
|
48
47
|
});
|
|
49
48
|
useEffect(() => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const handleManagerChange = manager => {
|
|
50
|
+
unsubscribeRef.current?.();
|
|
51
|
+
unsubscribeRef.current = null;
|
|
52
|
+
setManager(manager);
|
|
53
|
+
if (manager) {
|
|
54
|
+
setCurrentIndex(manager.getState().currentIndex);
|
|
55
|
+
unsubscribeRef.current = manager.subscribe(state => {
|
|
56
|
+
setCurrentIndex(state.currentIndex);
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setCurrentIndex(0);
|
|
61
|
+
};
|
|
62
|
+
const unsubscribeFromRegistry = registry.subscribeToManager(id, handleManagerChange);
|
|
63
|
+
return () => {
|
|
64
|
+
unsubscribeFromRegistry();
|
|
65
|
+
unsubscribeRef.current?.();
|
|
66
|
+
};
|
|
56
67
|
}, [id]);
|
|
57
68
|
useEffect(() => {
|
|
58
|
-
const manager = registry.getManager(id);
|
|
59
69
|
if (!manager) {
|
|
60
70
|
return;
|
|
61
71
|
}
|
|
@@ -63,17 +73,16 @@ export const useGestureImageViewer = ({
|
|
|
63
73
|
manager.setEnableSwipeGesture(enableSwipeGesture);
|
|
64
74
|
manager.setCurrentIndex(initialIndex);
|
|
65
75
|
manager.notifyStateChange();
|
|
66
|
-
}, [dataLength, enableSwipeGesture, initialIndex,
|
|
76
|
+
}, [dataLength, enableSwipeGesture, initialIndex, manager]);
|
|
67
77
|
useEffect(() => {
|
|
68
|
-
const manager = registry.getManager(id);
|
|
69
78
|
if (!manager || !flatListRef.current) {
|
|
70
79
|
return;
|
|
71
80
|
}
|
|
72
81
|
manager.setFlatListRef(flatListRef.current);
|
|
73
|
-
}, [
|
|
82
|
+
}, [manager]);
|
|
74
83
|
useEffect(() => {
|
|
75
|
-
onIndexChange?.(
|
|
76
|
-
}, [
|
|
84
|
+
onIndexChange?.(currentIndex);
|
|
85
|
+
}, [currentIndex, onIndexChange]);
|
|
77
86
|
useEffect(() => {
|
|
78
87
|
translateY.value = 0;
|
|
79
88
|
translateX.value = 0;
|
|
@@ -99,10 +108,11 @@ export const useGestureImageViewer = ({
|
|
|
99
108
|
}
|
|
100
109
|
const contentOffset = event.nativeEvent.contentOffset;
|
|
101
110
|
const newIndex = Math.round(contentOffset.x / width);
|
|
102
|
-
if (newIndex !==
|
|
103
|
-
const manager = registry.getManager(id);
|
|
111
|
+
if (newIndex !== currentIndex && newIndex >= 0 && newIndex < dataLength) {
|
|
104
112
|
if (manager) {
|
|
105
113
|
manager.setCurrentIndex(newIndex);
|
|
114
|
+
setCurrentIndex(newIndex);
|
|
115
|
+
manager.notifyStateChange();
|
|
106
116
|
}
|
|
107
117
|
translateX.value = withTiming(0);
|
|
108
118
|
translateY.value = withTiming(0);
|
|
@@ -111,7 +121,7 @@ export const useGestureImageViewer = ({
|
|
|
111
121
|
startScale.value = withTiming(1);
|
|
112
122
|
scale.value = withTiming(1);
|
|
113
123
|
}
|
|
114
|
-
}, [
|
|
124
|
+
}, [manager, currentIndex, dataLength, width, enableSwipeGesture, translateX, translateY, scale, initialTranslateX, initialTranslateY, startScale]);
|
|
115
125
|
const dismissGesture = useMemo(() => {
|
|
116
126
|
return Gesture.Pan().minDistance(10).averageTouches(true).activeOffsetY([-10, 10]).failOffsetX([-10, 10]).enabled(!isZoomed).onUpdate(event => {
|
|
117
127
|
translateY.value = event.translationY / resistance;
|
|
@@ -209,7 +219,7 @@ export const useGestureImageViewer = ({
|
|
|
209
219
|
};
|
|
210
220
|
}, [animateBackdrop]);
|
|
211
221
|
return {
|
|
212
|
-
currentIndex
|
|
222
|
+
currentIndex,
|
|
213
223
|
dataLength,
|
|
214
224
|
translateY,
|
|
215
225
|
flatListRef,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","InteractionManager","useWindowDimensions","Gesture","Easing","interpolate","runOnJS","useAnimatedReaction","useAnimatedStyle","useSharedValue","withSpring","withTiming","registry","useGestureImageViewer","data","initialIndex","onIndexChange","onDismiss","width","customWidth","dismissThreshold","resistance","animateBackdrop","enableDismissGesture","enableSwipeGesture","enableZoomGesture","enableDoubleTapGesture","enableZoomPanGesture","maxZoomScale","id","screenWidth","height","screenHeight","isZoomed","setIsZoomed","managerState","setManagerState","currentIndex","dataLength","length","initialTranslateY","initialTranslateX","startScale","translateY","translateX","scale","backdropOpacity","flatListRef","value","currentScale","manager","getManager","getState","subscribe","setDataLength","setEnableSwipeGesture","setCurrentIndex","notifyStateChange","current","setFlatListRef","runAfterInteractions","scrollToIndex","index","animated","cancel","onMomentumScrollEnd","event","contentOffset","nativeEvent","newIndex","Math","round","x","dismissGesture","Pan","minDistance","averageTouches","activeOffsetY","failOffsetX","enabled","onUpdate","translationY","onEnd","damping","stiffness","zoomPinchGesture","Pinch","onBegin","duration","easing","bezier","zoomPanGesture","maxTranslateX","maxTranslateY","max","min","translationX","doubleTapGesture","Tap","numberOfTaps","nextScale","zoomGesture","Simultaneous","animatedStyle","transform","backdropStyle","opacity"],"sourceRoot":"../../src","sources":["useGestureImageViewer.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzE,SACEC,kBAAkB,EAGlBC,mBAAmB,QACd,cAAc;AACrB,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,MAAM,EACNC,WAAW,EACXC,OAAO,EACPC,mBAAmB,EACnBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,yBAAyB;AAEhC,SAASC,QAAQ,QAAQ,0BAAuB;AAQhD,OAAO,MAAMC,qBAAqB,GAAGA,CAAU;EAC7CC,IAAI;EACJC,YAAY,GAAG,CAAC;EAChBC,aAAa;EACbC,SAAS;EACTC,KAAK,EAAEC,WAAW;EAClBC,gBAAgB,GAAG,EAAE;EACrBC,UAAU,GAAG,CAAC;EACd;EACA;EACAC,eAAe,GAAG,IAAI;EACtBC,oBAAoB,GAAG,IAAI;EAC3BC,kBAAkB,GAAG,IAAI;EACzBC,iBAAiB,GAAG,IAAI;EACxBC,sBAAsB,GAAG,IAAI;EAC7BC,oBAAoB,GAAG,IAAI;EAC3BC,YAAY,GAAG,CAAC;EAChBC,EAAE,GAAG;AACwB,CAAC,KAAK;EACnC,MAAM;IAAEX,KAAK,EAAEY,WAAW;IAAEC,MAAM,EAAEC;EAAa,CAAC,GAAG9B,mBAAmB,CAAC,CAAC;EAC1E,MAAMgB,KAAK,GAAGC,WAAW,IAAIW,WAAW;EAExC,MAAM,CAACG,QAAQ,EAAEC,WAAW,CAAC,GAAGlC,QAAQ,CAAC,KAAK,CAAC;EAE/C,MAAM,CAACmC,YAAY,EAAEC,eAAe,CAAC,GAAGpC,QAAQ,CAA0B;IACxEqC,YAAY,EAAEtB,YAAY;IAC1BuB,UA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IAEXpC,mBAAmB;IAEnBsC,aAAa;IACbE;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","InteractionManager","useWindowDimensions","Gesture","Easing","interpolate","runOnJS","useAnimatedReaction","useAnimatedStyle","useSharedValue","withSpring","withTiming","registry","useGestureImageViewer","data","initialIndex","onIndexChange","onDismiss","width","customWidth","dismissThreshold","resistance","animateBackdrop","enableDismissGesture","enableSwipeGesture","enableZoomGesture","enableDoubleTapGesture","enableZoomPanGesture","maxZoomScale","id","screenWidth","height","screenHeight","isZoomed","setIsZoomed","currentIndex","setCurrentIndex","manager","setManager","unsubscribeRef","initialTranslateY","initialTranslateX","startScale","translateY","translateX","scale","backdropOpacity","flatListRef","dataLength","length","value","currentScale","handleManagerChange","current","getState","subscribe","state","unsubscribeFromRegistry","subscribeToManager","setDataLength","setEnableSwipeGesture","notifyStateChange","setFlatListRef","runAfterInteractions","scrollToIndex","index","animated","cancel","onMomentumScrollEnd","event","contentOffset","nativeEvent","newIndex","Math","round","x","dismissGesture","Pan","minDistance","averageTouches","activeOffsetY","failOffsetX","enabled","onUpdate","translationY","onEnd","damping","stiffness","zoomPinchGesture","Pinch","onBegin","duration","easing","bezier","zoomPanGesture","maxTranslateX","maxTranslateY","max","min","translationX","doubleTapGesture","Tap","numberOfTaps","nextScale","zoomGesture","Simultaneous","animatedStyle","transform","backdropStyle","opacity"],"sourceRoot":"../../src","sources":["useGestureImageViewer.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACzE,SACEC,kBAAkB,EAGlBC,mBAAmB,QACd,cAAc;AACrB,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,MAAM,EACNC,WAAW,EACXC,OAAO,EACPC,mBAAmB,EACnBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,yBAAyB;A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useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { registry } from "./ImageViewerRegistry.js";
|
|
5
5
|
export const useImageViewerController = (id = 'default') => {
|
|
6
6
|
const [state, setState] = useState({
|
|
7
7
|
currentIndex: 0,
|
|
8
8
|
dataLength: 0
|
|
9
9
|
});
|
|
10
|
+
const [manager, setManager] = useState(null);
|
|
11
|
+
const unsubscribeRef = useRef(null);
|
|
10
12
|
useEffect(() => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const handleManagerChange = newManager => {
|
|
14
|
+
unsubscribeRef.current?.();
|
|
15
|
+
unsubscribeRef.current = null;
|
|
16
|
+
setManager(newManager);
|
|
17
|
+
if (newManager) {
|
|
18
|
+
setState(newManager.getState());
|
|
19
|
+
unsubscribeRef.current = newManager.subscribe(setState);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
setState({
|
|
23
|
+
currentIndex: 0,
|
|
24
|
+
dataLength: 0
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const unsubscribeFromRegistry = registry.subscribeToManager(id, handleManagerChange);
|
|
28
|
+
return () => {
|
|
29
|
+
unsubscribeFromRegistry();
|
|
30
|
+
unsubscribeRef.current?.();
|
|
31
|
+
};
|
|
17
32
|
}, [id]);
|
|
18
|
-
const manager = registry.getManager(id);
|
|
19
33
|
const noopFunction = useMemo(() => () => {}, []);
|
|
20
34
|
return {
|
|
21
35
|
goToIndex: manager?.goToIndex || noopFunction,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useMemo","useState","registry","useImageViewerController","id","state","setState","currentIndex","dataLength","manager","
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","useRef","useState","registry","useImageViewerController","id","state","setState","currentIndex","dataLength","manager","setManager","unsubscribeRef","handleManagerChange","newManager","current","getState","subscribe","unsubscribeFromRegistry","subscribeToManager","noopFunction","goToIndex","goToPrevious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AEhD,OAAO;IACLqB,SAAS,EAAEX,OAAO,EAAEW,SAAS,IAAID,YAAY;IAC7CE,YAAY,EAAEZ,OAAO,EAAEY,YAAY,IAAIF,YAAY;IACnDG,QAAQ,EAAEb,OAAO,EAAEa,QAAQ,IAAIH,YAAY;IAC3CZ,YAAY,EAAEF,KAAK,CAACE,YAAY;IAChCgB,UAAU,EAAElB,KAAK,CAACG;EACpB,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import ImageViewerManager from './ImageViewerManager';
|
|
2
2
|
declare class ImageViewerRegistry {
|
|
3
3
|
private managers;
|
|
4
|
+
private subscribers;
|
|
5
|
+
subscribeToManager(id: string, callback: (manager: ImageViewerManager | null) => void): () => void;
|
|
4
6
|
createManager(id: string): ImageViewerManager | null;
|
|
5
7
|
getManager(id: string): ImageViewerManager | null;
|
|
6
8
|
deleteManager(id: string): void;
|
|
9
|
+
notifySubscribers(id: string, manager: ImageViewerManager | null): void;
|
|
7
10
|
}
|
|
8
11
|
export declare const registry: ImageViewerRegistry;
|
|
9
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageViewerRegistry.d.ts","sourceRoot":"","sources":["../../../src/ImageViewerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,cAAM,mBAAmB;IACvB,OAAO,CAAC,QAAQ,CAAyC;
|
|
1
|
+
{"version":3,"file":"ImageViewerRegistry.d.ts","sourceRoot":"","sources":["../../../src/ImageViewerRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,cAAM,mBAAmB;IACvB,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,WAAW,CAAwE;IAE3F,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,KAAK,IAAI;IAsBrF,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAapD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAIjD,aAAa,CAAC,EAAE,EAAE,MAAM;IAWxB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI;CAOjE;AAED,eAAO,MAAM,QAAQ,qBAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGestureImageViewer.d.ts","sourceRoot":"","sources":["../../../src/useGestureImageViewer.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,KAAK,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAC7C,uBAAuB,CAAC,CAAC,CAAC,EAC1B,aAAa,GAAG,iBAAiB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,CACvG,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,CAAC,GAAG,GAAG,EAAE,mPAkB5C,0BAA0B,CAAC,CAAC,CAAC;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useGestureImageViewer.d.ts","sourceRoot":"","sources":["../../../src/useGestureImageViewer.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAEvD,KAAK,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAC7C,uBAAuB,CAAC,CAAC,CAAC,EAC1B,aAAa,GAAG,iBAAiB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,CACvG,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,CAAC,GAAG,GAAG,EAAE,mPAkB5C,0BAA0B,CAAC,CAAC,CAAC;;;;;;;;iCAwGpB,oBAAoB,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;CA0LlD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImageViewerController.d.ts","sourceRoot":"","sources":["../../../src/useImageViewerController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useImageViewerController.d.ts","sourceRoot":"","sources":["../../../src/useImageViewerController.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB,GAAI,WAAc;;;;;;CA0CtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gesture-image-viewer",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
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.
|
|
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.
|
|
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",
|
|
@@ -2,6 +2,29 @@ import ImageViewerManager from './ImageViewerManager';
|
|
|
2
2
|
|
|
3
3
|
class ImageViewerRegistry {
|
|
4
4
|
private managers = new Map<string, ImageViewerManager>();
|
|
5
|
+
private subscribers = new Map<string, Set<(manager: ImageViewerManager | null) => void>>();
|
|
6
|
+
|
|
7
|
+
subscribeToManager(id: string, callback: (manager: ImageViewerManager | null) => void) {
|
|
8
|
+
if (!this.subscribers.has(id)) {
|
|
9
|
+
this.subscribers.set(id, new Set());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.subscribers.get(id)?.add(callback);
|
|
13
|
+
|
|
14
|
+
const manager = this.managers.get(id) || null;
|
|
15
|
+
|
|
16
|
+
callback(manager);
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
const subscribers = this.subscribers.get(id);
|
|
20
|
+
|
|
21
|
+
subscribers?.delete(callback);
|
|
22
|
+
|
|
23
|
+
if (subscribers && subscribers.size === 0) {
|
|
24
|
+
this.subscribers.delete(id);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
5
28
|
|
|
6
29
|
createManager(id: string): ImageViewerManager | null {
|
|
7
30
|
if (this.managers.has(id)) {
|
|
@@ -10,6 +33,9 @@ class ImageViewerRegistry {
|
|
|
10
33
|
|
|
11
34
|
const manager = new ImageViewerManager();
|
|
12
35
|
this.managers.set(id, manager);
|
|
36
|
+
|
|
37
|
+
this.notifySubscribers(id, manager);
|
|
38
|
+
|
|
13
39
|
return manager;
|
|
14
40
|
}
|
|
15
41
|
|
|
@@ -23,6 +49,16 @@ class ImageViewerRegistry {
|
|
|
23
49
|
if (manager) {
|
|
24
50
|
manager.cleanUp();
|
|
25
51
|
this.managers.delete(id);
|
|
52
|
+
|
|
53
|
+
this.notifySubscribers(id, null);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
notifySubscribers(id: string, manager: ImageViewerManager | null) {
|
|
58
|
+
const listeners = this.subscribers.get(id);
|
|
59
|
+
|
|
60
|
+
if (listeners) {
|
|
61
|
+
[...listeners].forEach((callback) => callback(manager));
|
|
26
62
|
}
|
|
27
63
|
}
|
|
28
64
|
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
withSpring,
|
|
17
17
|
withTiming,
|
|
18
18
|
} from 'react-native-reanimated';
|
|
19
|
-
import type
|
|
19
|
+
import type ImageViewerManager from './ImageViewerManager';
|
|
20
20
|
import { registry } from './ImageViewerRegistry';
|
|
21
21
|
import type { GestureImageViewerProps } from './types';
|
|
22
22
|
|
|
@@ -49,10 +49,10 @@ export const useGestureImageViewer = <T = any>({
|
|
|
49
49
|
|
|
50
50
|
const [isZoomed, setIsZoomed] = useState(false);
|
|
51
51
|
|
|
52
|
-
const [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
|
53
|
+
const [manager, setManager] = useState<ImageViewerManager | null>(null);
|
|
54
|
+
|
|
55
|
+
const unsubscribeRef = useRef<(() => void) | null>(null);
|
|
56
56
|
|
|
57
57
|
const initialTranslateY = useSharedValue(0);
|
|
58
58
|
const initialTranslateX = useSharedValue(0);
|
|
@@ -75,20 +75,32 @@ export const useGestureImageViewer = <T = any>({
|
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
useEffect(() => {
|
|
78
|
-
const
|
|
78
|
+
const handleManagerChange = (manager: ImageViewerManager | null) => {
|
|
79
|
+
unsubscribeRef.current?.();
|
|
80
|
+
unsubscribeRef.current = null;
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
82
|
+
setManager(manager);
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
if (manager) {
|
|
85
|
+
setCurrentIndex(manager.getState().currentIndex);
|
|
86
|
+
unsubscribeRef.current = manager.subscribe((state) => {
|
|
87
|
+
setCurrentIndex(state.currentIndex);
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
85
91
|
|
|
86
|
-
|
|
92
|
+
setCurrentIndex(0);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const unsubscribeFromRegistry = registry.subscribeToManager(id, handleManagerChange);
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
unsubscribeFromRegistry();
|
|
99
|
+
unsubscribeRef.current?.();
|
|
100
|
+
};
|
|
87
101
|
}, [id]);
|
|
88
102
|
|
|
89
103
|
useEffect(() => {
|
|
90
|
-
const manager = registry.getManager(id);
|
|
91
|
-
|
|
92
104
|
if (!manager) {
|
|
93
105
|
return;
|
|
94
106
|
}
|
|
@@ -97,21 +109,19 @@ export const useGestureImageViewer = <T = any>({
|
|
|
97
109
|
manager.setEnableSwipeGesture(enableSwipeGesture);
|
|
98
110
|
manager.setCurrentIndex(initialIndex);
|
|
99
111
|
manager.notifyStateChange();
|
|
100
|
-
}, [dataLength, enableSwipeGesture, initialIndex,
|
|
112
|
+
}, [dataLength, enableSwipeGesture, initialIndex, manager]);
|
|
101
113
|
|
|
102
114
|
useEffect(() => {
|
|
103
|
-
const manager = registry.getManager(id);
|
|
104
|
-
|
|
105
115
|
if (!manager || !flatListRef.current) {
|
|
106
116
|
return;
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
manager.setFlatListRef(flatListRef.current);
|
|
110
|
-
}, [
|
|
120
|
+
}, [manager]);
|
|
111
121
|
|
|
112
122
|
useEffect(() => {
|
|
113
|
-
onIndexChange?.(
|
|
114
|
-
}, [
|
|
123
|
+
onIndexChange?.(currentIndex);
|
|
124
|
+
}, [currentIndex, onIndexChange]);
|
|
115
125
|
|
|
116
126
|
useEffect(() => {
|
|
117
127
|
translateY.value = 0;
|
|
@@ -145,11 +155,11 @@ export const useGestureImageViewer = <T = any>({
|
|
|
145
155
|
const contentOffset = event.nativeEvent.contentOffset;
|
|
146
156
|
const newIndex = Math.round(contentOffset.x / width);
|
|
147
157
|
|
|
148
|
-
if (newIndex !==
|
|
149
|
-
const manager = registry.getManager(id);
|
|
150
|
-
|
|
158
|
+
if (newIndex !== currentIndex && newIndex >= 0 && newIndex < dataLength) {
|
|
151
159
|
if (manager) {
|
|
152
160
|
manager.setCurrentIndex(newIndex);
|
|
161
|
+
setCurrentIndex(newIndex);
|
|
162
|
+
manager.notifyStateChange();
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
translateX.value = withTiming(0);
|
|
@@ -161,8 +171,8 @@ export const useGestureImageViewer = <T = any>({
|
|
|
161
171
|
}
|
|
162
172
|
},
|
|
163
173
|
[
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
manager,
|
|
175
|
+
currentIndex,
|
|
166
176
|
dataLength,
|
|
167
177
|
width,
|
|
168
178
|
enableSwipeGesture,
|
|
@@ -309,7 +319,7 @@ export const useGestureImageViewer = <T = any>({
|
|
|
309
319
|
}, [animateBackdrop]);
|
|
310
320
|
|
|
311
321
|
return {
|
|
312
|
-
currentIndex
|
|
322
|
+
currentIndex,
|
|
313
323
|
dataLength,
|
|
314
324
|
translateY,
|
|
315
325
|
flatListRef,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type ImageViewerManager from './ImageViewerManager';
|
|
2
3
|
import type { ImageViewerManagerState } from './ImageViewerManager';
|
|
3
4
|
import { registry } from './ImageViewerRegistry';
|
|
4
5
|
|
|
@@ -8,19 +9,32 @@ export const useImageViewerController = (id = 'default') => {
|
|
|
8
9
|
dataLength: 0,
|
|
9
10
|
});
|
|
10
11
|
|
|
12
|
+
const [manager, setManager] = useState<ImageViewerManager | null>(null);
|
|
13
|
+
const unsubscribeRef = useRef<(() => void) | null>(null);
|
|
14
|
+
|
|
11
15
|
useEffect(() => {
|
|
12
|
-
const
|
|
16
|
+
const handleManagerChange = (newManager: ImageViewerManager | null) => {
|
|
17
|
+
unsubscribeRef.current?.();
|
|
18
|
+
unsubscribeRef.current = null;
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
20
|
+
setManager(newManager);
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
if (newManager) {
|
|
23
|
+
setState(newManager.getState());
|
|
24
|
+
unsubscribeRef.current = newManager.subscribe(setState);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
setState({ currentIndex: 0, dataLength: 0 });
|
|
29
|
+
};
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
const unsubscribeFromRegistry = registry.subscribeToManager(id, handleManagerChange);
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
unsubscribeFromRegistry();
|
|
35
|
+
unsubscribeRef.current?.();
|
|
36
|
+
};
|
|
37
|
+
}, [id]);
|
|
24
38
|
|
|
25
39
|
const noopFunction = useMemo(() => () => {}, []);
|
|
26
40
|
|