react-native-gesture-image-viewer 1.4.0 → 1.5.0
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 +53 -17
- package/lib/module/GestureViewerManager.js +36 -33
- package/lib/module/GestureViewerManager.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useGestureViewer.js +14 -2
- package/lib/module/useGestureViewer.js.map +1 -1
- package/lib/module/useGestureViewerController.js +55 -4
- package/lib/module/useGestureViewerController.js.map +1 -1
- package/lib/module/useGestureViewerEvent.js +79 -0
- package/lib/module/useGestureViewerEvent.js.map +1 -0
- package/lib/typescript/src/GestureViewerManager.d.ts +8 -34
- package/lib/typescript/src/GestureViewerManager.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +155 -14
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerController.d.ts +54 -11
- package/lib/typescript/src/useGestureViewerController.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerEvent.d.ts +50 -0
- package/lib/typescript/src/useGestureViewerEvent.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/GestureViewerManager.ts +47 -36
- package/src/index.tsx +9 -1
- package/src/types.ts +162 -14
- package/src/useGestureViewer.ts +24 -2
- package/src/useGestureViewerController.ts +58 -7
- package/src/useGestureViewerEvent.ts +96 -0
|
@@ -9,7 +9,7 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
9
9
|
/**
|
|
10
10
|
* When you want to efficiently manage multiple `GestureViewer` instances, you can use the `id` prop to use multiple `GestureViewer` components.
|
|
11
11
|
* @remark `GestureViewer` automatically removes instances from memory when components are unmounted, so no manual memory management is required.
|
|
12
|
-
* @
|
|
12
|
+
* @defaultValue 'default'
|
|
13
13
|
*/
|
|
14
14
|
id?: string;
|
|
15
15
|
/**
|
|
@@ -18,7 +18,7 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
18
18
|
data: T[];
|
|
19
19
|
/**
|
|
20
20
|
* The index of the item to display in the `GestureViewer` when the component is mounted.
|
|
21
|
-
* @
|
|
21
|
+
* @defaultValue 0
|
|
22
22
|
*/
|
|
23
23
|
initialIndex?: number;
|
|
24
24
|
/**
|
|
@@ -44,7 +44,7 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
44
44
|
/**
|
|
45
45
|
* The width of the `GestureViewer`.
|
|
46
46
|
* @remark If you don't set this prop, the width of the `GestureViewer` will be the same as the width of the screen.
|
|
47
|
-
* @
|
|
47
|
+
* @defaultValue screen width
|
|
48
48
|
*/
|
|
49
49
|
width?: number;
|
|
50
50
|
/**
|
|
@@ -57,30 +57,30 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
57
57
|
* **`true`**: Snap mode (`snapToInterval` auto-calculated)
|
|
58
58
|
* - `snapToInterval` is automatically calculated based on `width` and `itemSpacing` values
|
|
59
59
|
* - Use this option when you need item spacing
|
|
60
|
-
* @
|
|
60
|
+
* @defaultValue false
|
|
61
61
|
*
|
|
62
62
|
*/
|
|
63
63
|
useSnap?: boolean;
|
|
64
64
|
/**
|
|
65
65
|
* `dismissThreshold` controls when `onDismiss` is called by applying a threshold value during vertical gestures.
|
|
66
|
-
* @
|
|
66
|
+
* @defaultValue 80
|
|
67
67
|
*/
|
|
68
68
|
dismissThreshold?: number;
|
|
69
69
|
/**
|
|
70
70
|
* Calls `onDismiss` function when swiping down.
|
|
71
71
|
* @remark Useful for closing modals with downward swipe gestures.
|
|
72
|
-
* @
|
|
72
|
+
* @defaultValue true
|
|
73
73
|
*/
|
|
74
74
|
enableDismissGesture?: boolean;
|
|
75
75
|
/**
|
|
76
76
|
* Controls left/right swipe gestures.
|
|
77
77
|
* @remark When `false`, horizontal gestures are disabled.
|
|
78
|
-
* @
|
|
78
|
+
* @defaultValue true
|
|
79
79
|
*/
|
|
80
80
|
enableSwipeGesture?: boolean;
|
|
81
81
|
/**
|
|
82
82
|
* `resistance` controls the range of vertical movement by applying resistance during vertical gestures.
|
|
83
|
-
* @
|
|
83
|
+
* @defaultValue 2
|
|
84
84
|
*/
|
|
85
85
|
resistance?: number;
|
|
86
86
|
/**
|
|
@@ -99,38 +99,179 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
99
99
|
/**
|
|
100
100
|
* By default, the background `opacity` gradually decreases from 1 to 0 during downward swipe gestures.
|
|
101
101
|
* @remark When `false`, this animation is disabled.
|
|
102
|
-
* @
|
|
102
|
+
* @defaultValue true
|
|
103
103
|
*/
|
|
104
104
|
animateBackdrop?: boolean;
|
|
105
105
|
/**
|
|
106
106
|
* Only works when zoom is active, allows moving item position when zoomed.
|
|
107
107
|
* @remark When `false`, gesture movement is disabled during zoom.
|
|
108
|
-
* @
|
|
108
|
+
* @defaultValue true
|
|
109
109
|
*/
|
|
110
110
|
enableZoomPanGesture?: boolean;
|
|
111
111
|
/**
|
|
112
112
|
* Controls two-finger pinch gestures.
|
|
113
113
|
* @remark When `false`, two-finger zoom gestures are disabled.
|
|
114
|
-
* @
|
|
114
|
+
* @defaultValue true
|
|
115
115
|
*/
|
|
116
116
|
enableZoomGesture?: boolean;
|
|
117
117
|
/**
|
|
118
118
|
* Controls double-tap zoom gestures.
|
|
119
119
|
* @remark When `false`, double-tap zoom gestures are disabled.
|
|
120
|
-
* @
|
|
120
|
+
* @defaultValue true
|
|
121
121
|
*/
|
|
122
122
|
enableDoubleTapGesture?: boolean;
|
|
123
123
|
/**
|
|
124
124
|
* The maximum zoom scale.
|
|
125
|
-
* @
|
|
125
|
+
* @defaultValue 2
|
|
126
126
|
*/
|
|
127
127
|
maxZoomScale?: number;
|
|
128
128
|
/**
|
|
129
129
|
* The spacing between items in pixels.
|
|
130
130
|
* @remark Only applied when `useSnap` is `true`.
|
|
131
|
-
* @
|
|
131
|
+
* @defaultValue 0
|
|
132
132
|
*/
|
|
133
133
|
itemSpacing?: number;
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Supported rotation angles in degrees.
|
|
137
|
+
*/
|
|
138
|
+
export type RotationAngle = 0 | 90 | 180 | 270 | 360;
|
|
139
|
+
/**
|
|
140
|
+
* Controller for managing gesture-based image/content viewer interactions.
|
|
141
|
+
* Provides navigation, zoom, and rotation capabilities with state management.
|
|
142
|
+
*/
|
|
143
|
+
export type GestureViewerController = {
|
|
144
|
+
/**
|
|
145
|
+
* Navigates to the specified index in the viewer.
|
|
146
|
+
* Updates the currentIndex in the controller state.
|
|
147
|
+
*
|
|
148
|
+
* @param index - The target index (must be between 0 and totalCount - 1)
|
|
149
|
+
* @throws Will throw an error if index is out of bounds
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* controller.goToIndex(0); // Go to first item
|
|
154
|
+
* controller.goToIndex(controller.totalCount - 1); // Go to last item
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
goToIndex: (index: number) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Navigates to the previous item in the sequence.
|
|
160
|
+
* If already at the first item, behavior depends on implementation (may wrap or do nothing).
|
|
161
|
+
* Updates currentIndex in the controller state.
|
|
162
|
+
*/
|
|
163
|
+
goToPrevious: () => void;
|
|
164
|
+
/**
|
|
165
|
+
* Navigates to the next item in the sequence.
|
|
166
|
+
* If already at the last item, behavior depends on implementation (may wrap or do nothing).
|
|
167
|
+
* Updates currentIndex in the controller state.
|
|
168
|
+
*/
|
|
169
|
+
goToNext: () => void;
|
|
170
|
+
/**
|
|
171
|
+
* Zooms in by the specified multiplier.
|
|
172
|
+
*
|
|
173
|
+
* @param multiplier - The zoom multiplier (0.01 - 1.0). Higher values zoom in more.
|
|
174
|
+
* @defaultValue 0.25
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* controller.zoomIn(); // Zoom in by 25%
|
|
179
|
+
* controller.zoomIn(0.5); // Zoom in by 50%
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
zoomIn: (multiplier?: number) => void;
|
|
183
|
+
/**
|
|
184
|
+
* Zooms out by the specified multiplier.
|
|
185
|
+
*
|
|
186
|
+
* @param multiplier - The zoom multiplier (0.01 - 1.0). Higher values zoom out more.
|
|
187
|
+
* @defaultValue 0.25
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* controller.zoomOut(); // Zoom out by 25%
|
|
192
|
+
* controller.zoomOut(0.1); // Zoom out by 10%
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
zoomOut: (multiplier?: number) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Resets the zoom level to the specified scale.
|
|
198
|
+
*
|
|
199
|
+
* @param scale - The scale to reset to (1.0 = original size)
|
|
200
|
+
* @defaultValue 1.0
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* controller.resetZoom(); // Reset to original size
|
|
205
|
+
* controller.resetZoom(0.5); // Reset to 50% of original size
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
resetZoom: (scale?: number) => void;
|
|
209
|
+
/**
|
|
210
|
+
* Rotates the content by the specified angle.
|
|
211
|
+
*
|
|
212
|
+
* @param angle - Rotation angle in degrees. Must be one of: 0, 90, 180, 270, 360
|
|
213
|
+
* @param clockwise - Direction of rotation when angle is not 0 or 360
|
|
214
|
+
* @defaultValue angle: `90`, clockwise: `true`
|
|
215
|
+
*
|
|
216
|
+
* @remarks
|
|
217
|
+
* - Angle 0 or 360 resets rotation regardless of clockwise parameter
|
|
218
|
+
* - The clockwise parameter only affects rotation when angle is 90, 180, or 270
|
|
219
|
+
* - Rotation is cumulative and affects the current orientation
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* controller.rotate(); // Rotate 90 degrees clockwise
|
|
224
|
+
* controller.rotate(0); // Reset rotation
|
|
225
|
+
* controller.rotate(90, false); // Rotate 90 degrees counter-clockwise
|
|
226
|
+
* controller.rotate(180); // Rotate 180 degrees (clockwise by default)
|
|
227
|
+
* controller.rotate(270, false); // Rotate 270 degrees counter-clockwise
|
|
228
|
+
* controller.rotate(360); // Reset rotation (same as 0)
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
rotate: (angle?: RotationAngle, clockwise?: boolean) => void;
|
|
232
|
+
} & GestureViewerControllerState;
|
|
233
|
+
/**
|
|
234
|
+
* State information for the gesture viewer controller.
|
|
235
|
+
* Contains read-only properties that reflect the current state.
|
|
236
|
+
*/
|
|
237
|
+
export type GestureViewerControllerState = {
|
|
238
|
+
/**
|
|
239
|
+
* The current index of the active item in the viewer.
|
|
240
|
+
*
|
|
241
|
+
* @remarks
|
|
242
|
+
* This value is automatically updated when navigation methods are called.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* console.log(`Currently viewing item ${controller.currentIndex + 1} of ${controller.totalCount}`);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
readonly currentIndex: number;
|
|
250
|
+
/**
|
|
251
|
+
* The total number of items available in the viewer.
|
|
252
|
+
*
|
|
253
|
+
* @remarks
|
|
254
|
+
* This value determines the valid range for currentIndex (0 to totalCount - 1).
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const hasNext = controller.currentIndex < controller.totalCount - 1;
|
|
259
|
+
* const hasPrevious = controller.currentIndex > 0;
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
readonly totalCount: number;
|
|
263
|
+
};
|
|
264
|
+
export type GestureViewerEventType = 'zoomChange' | 'rotationChange';
|
|
265
|
+
export type GestureViewerEventData = {
|
|
266
|
+
zoomChange: {
|
|
267
|
+
scale: number;
|
|
268
|
+
previousScale: number | null;
|
|
269
|
+
};
|
|
270
|
+
rotationChange: {
|
|
271
|
+
rotation: number;
|
|
272
|
+
previousRotation: number | null;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
export type GestureViewerEventCallback<T extends GestureViewerEventType> = (data: GestureViewerEventData[T]) => void;
|
|
135
276
|
export {};
|
|
136
277
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,UAAU,IAAI,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEvG,MAAM,MAAM,iBAAiB,GAAG,OAAO,UAAU,GAAG,OAAO,UAAU,CAAC;AACtE,MAAM,MAAM,mBAAmB,GAAG,OAAO,YAAY,GAAG,OAAO,YAAY,CAAC;AAE5E,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/E,KAAK,oBAAoB,CAAC,EAAE,IAAI,EAAE,SAAS,iBAAiB,GACxD,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,GACxB,EAAE,SAAS,mBAAmB,GAC5B,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,GACxB,iBAAiB,CAAC,EAAE,CAAC,CAAC;AAE5B,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,EAAE,GAAG,OAAO,UAAU;IACjE;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CA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AC,CAAC,SAAS,sBAAsB,IAAI,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGestureViewer.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewer.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,KAAK,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CACxC,kBAAkB,CAAC,CAAC,CAAC,EACrB,YAAY,GAAG,iBAAiB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,CACtG,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,CAAC,GAAG,GAAG,EAAE,yQAoBvC,qBAAqB,CAAC,CAAC,CAAC;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useGestureViewer.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewer.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAE1B,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,KAAK,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CACxC,kBAAkB,CAAC,CAAC,CAAC,EACrB,YAAY,GAAG,iBAAiB,GAAG,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,CACtG,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,CAAC,GAAG,GAAG,EAAE,yQAoBvC,qBAAqB,CAAC,CAAC,CAAC;;;;;;;;;iCAoKf,oBAAoB,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4QlD,CAAC"}
|
|
@@ -1,12 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { GestureViewerController } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to control the gesture viewer programmatically.
|
|
4
|
+
*
|
|
5
|
+
* @param id - Viewer instance identifier (default: 'default')
|
|
6
|
+
* @returns Methods and state for controlling the viewer
|
|
7
|
+
*
|
|
8
|
+
* **Available methods:**
|
|
9
|
+
* - `goToIndex(index: number)` - Navigate to specific index (0 to totalCount-1)
|
|
10
|
+
* - `goToPrevious()` - Navigate to previous item
|
|
11
|
+
* - `goToNext()` - Navigate to next item
|
|
12
|
+
* - `zoomIn(multiplier?: number)` - Zoom in (default: 0.25)
|
|
13
|
+
* - `zoomOut(multiplier?: number)` - Zoom out (default: 0.25)
|
|
14
|
+
* - `resetZoom(scale?: number)` - Reset zoom level (default: 1.0)
|
|
15
|
+
* - `rotate(angle?: 0|90|180|270|360, clockwise?: boolean)` - Rotate content (default: 90° clockwise)
|
|
16
|
+
*
|
|
17
|
+
* **Available state:**
|
|
18
|
+
* - `currentIndex: number` - Current active index (read-only)
|
|
19
|
+
* - `totalCount: number` - Total number of items (read-only)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { goToIndex, goToNext, goToPrevious, zoomIn, zoomOut, resetZoom, rotate, currentIndex, totalCount } = useGestureViewerController();
|
|
24
|
+
*
|
|
25
|
+
* // Navigate to specific index
|
|
26
|
+
* goToIndex(2);
|
|
27
|
+
*
|
|
28
|
+
* // Go to next image
|
|
29
|
+
* goToNext();
|
|
30
|
+
*
|
|
31
|
+
* // Zoom in by 25%
|
|
32
|
+
* zoomIn();
|
|
33
|
+
*
|
|
34
|
+
* // Zoom out by 50%
|
|
35
|
+
* zoomOut(0.5);
|
|
36
|
+
*
|
|
37
|
+
* // Reset to original size
|
|
38
|
+
* resetZoom();
|
|
39
|
+
*
|
|
40
|
+
* // Rotate 90 degrees clockwise
|
|
41
|
+
* rotate();
|
|
42
|
+
*
|
|
43
|
+
* // Rotate 180 degrees
|
|
44
|
+
* rotate(180);
|
|
45
|
+
*
|
|
46
|
+
* // Check current state
|
|
47
|
+
* console.log(`Image ${currentIndex + 1} of ${totalCount}`);
|
|
48
|
+
*
|
|
49
|
+
* // Check navigation availability
|
|
50
|
+
* const canGoNext = currentIndex < totalCount - 1;
|
|
51
|
+
* const canGoPrevious = currentIndex > 0;
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const useGestureViewerController: (id?: string) => GestureViewerController;
|
|
12
55
|
//# sourceMappingURL=useGestureViewerController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGestureViewerController.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewerController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGestureViewerController.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewerController.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAgC,MAAM,SAAS,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,0BAA0B,GAAI,WAAc,KAAG,uBA6C3D,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { GestureViewerEventCallback, GestureViewerEventType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for subscribing to GestureViewer events on the default instance.
|
|
4
|
+
*
|
|
5
|
+
* This hook allows you to listen to specific events from the default GestureViewer instance
|
|
6
|
+
* (with ID 'default'), such as zoom changes or rotation changes. Events are automatically
|
|
7
|
+
* throttled to prevent excessive callback invocations during gestures.
|
|
8
|
+
*
|
|
9
|
+
* @param eventType - The type of event to listen for
|
|
10
|
+
* @param callback - Function to call when the event occurs
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // Listen to zoom changes on the default instance (ID: 'default')
|
|
15
|
+
* useGestureViewerEvent('zoomChange', (data) => {
|
|
16
|
+
* console.log(`Zoom changed from ${data.previousScale} to ${data.scale}`);
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Listen to rotation changes on the default instance (ID: 'default')
|
|
20
|
+
* useGestureViewerEvent('rotationChange', (data) => {
|
|
21
|
+
* console.log(`Rotation changed from ${data.previousRotation}° to ${data.rotation}°`);
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useGestureViewerEvent<T extends GestureViewerEventType>(eventType: T, callback: GestureViewerEventCallback<T>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Hook for subscribing to GestureViewer events with a specific instance ID.
|
|
28
|
+
*
|
|
29
|
+
* Use this overload when you have multiple GestureViewer instances and need
|
|
30
|
+
* to listen to events from a specific one.
|
|
31
|
+
*
|
|
32
|
+
* @param id - The unique identifier of the GestureViewer instance
|
|
33
|
+
* @param eventType - The type of event to listen for
|
|
34
|
+
* @param callback - Function to call when the event occurs
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* // Listen to zoom changes on a specific instance
|
|
39
|
+
* useGestureViewerEvent('gallery', 'zoomChange', (data) => {
|
|
40
|
+
* console.log(`Gallery zoom: ${data.scale}x`);
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Listen to rotation changes on a modal viewer
|
|
44
|
+
* useGestureViewerEvent('modal-viewer', 'rotationChange', (data) => {
|
|
45
|
+
* updateRotationIndicator(data.rotation);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function useGestureViewerEvent<T extends GestureViewerEventType>(id: string, eventType: T, callback: GestureViewerEventCallback<T>): void;
|
|
50
|
+
//# sourceMappingURL=useGestureViewerEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGestureViewerEvent.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewerEvent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAElF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,sBAAsB,EACpE,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACtC,IAAI,CAAC;AAER;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,sBAAsB,EACpE,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACtC,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gesture-image-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
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",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type SharedValue, withTiming } from 'react-native-reanimated';
|
|
2
|
+
import type {
|
|
3
|
+
GestureViewerControllerState,
|
|
4
|
+
GestureViewerEventCallback,
|
|
5
|
+
GestureViewerEventData,
|
|
6
|
+
GestureViewerEventType,
|
|
7
|
+
} from './types';
|
|
2
8
|
import { createBoundsConstraint } from './utils';
|
|
3
9
|
|
|
4
|
-
export type GestureViewerManagerState = {
|
|
5
|
-
currentIndex: number;
|
|
6
|
-
dataLength: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
10
|
class GestureViewerManager {
|
|
10
11
|
private currentIndex = 0;
|
|
11
12
|
private dataLength = 0;
|
|
@@ -17,8 +18,9 @@ class GestureViewerManager {
|
|
|
17
18
|
private maxZoomScale = 2;
|
|
18
19
|
private listRef: any | null = null;
|
|
19
20
|
private enableSwipeGesture = true;
|
|
20
|
-
private listeners = new Set<(state:
|
|
21
|
+
private listeners = new Set<(state: GestureViewerControllerState) => void>();
|
|
21
22
|
private rotation: SharedValue<number> | null = null;
|
|
23
|
+
private eventListeners = new Map<GestureViewerEventType, Set<(data: any) => void>>();
|
|
22
24
|
|
|
23
25
|
private notifyListeners() {
|
|
24
26
|
const state = this.getState();
|
|
@@ -26,7 +28,7 @@ class GestureViewerManager {
|
|
|
26
28
|
this.listeners.forEach((listener) => listener(state));
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
subscribe(listener: (state:
|
|
31
|
+
subscribe(listener: (state: GestureViewerControllerState) => void) {
|
|
30
32
|
this.listeners.add(listener);
|
|
31
33
|
|
|
32
34
|
return () => {
|
|
@@ -34,10 +36,46 @@ class GestureViewerManager {
|
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
addEventListener<T extends GestureViewerEventType>(eventType: T, callback: GestureViewerEventCallback<T>) {
|
|
40
|
+
if (!this.eventListeners.has(eventType)) {
|
|
41
|
+
this.eventListeners.set(eventType, new Set());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.eventListeners.get(eventType)?.add(callback);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
const listeners = this.eventListeners.get(eventType);
|
|
48
|
+
|
|
49
|
+
if (listeners) {
|
|
50
|
+
listeners.delete(callback);
|
|
51
|
+
|
|
52
|
+
if (listeners.size === 0) {
|
|
53
|
+
this.eventListeners.delete(eventType);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private emitEvent<T extends GestureViewerEventType>(eventType: T, data: GestureViewerEventData[T]) {
|
|
60
|
+
const listeners = this.eventListeners.get(eventType);
|
|
61
|
+
|
|
62
|
+
if (listeners) {
|
|
63
|
+
listeners.forEach((callback) => callback(data));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
emitZoomChange = (scale: number, previousScale: number | null) => {
|
|
68
|
+
this.emitEvent('zoomChange', { scale, previousScale });
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
emitRotationChange = (rotation: number, previousRotation: number | null) => {
|
|
72
|
+
this.emitEvent('rotationChange', { rotation, previousRotation });
|
|
73
|
+
};
|
|
74
|
+
|
|
37
75
|
getState() {
|
|
38
76
|
return {
|
|
39
77
|
currentIndex: this.currentIndex,
|
|
40
|
-
|
|
78
|
+
totalCount: this.dataLength,
|
|
41
79
|
};
|
|
42
80
|
}
|
|
43
81
|
|
|
@@ -87,20 +125,6 @@ class GestureViewerManager {
|
|
|
87
125
|
this.rotation = rotation;
|
|
88
126
|
}
|
|
89
127
|
|
|
90
|
-
/**
|
|
91
|
-
* @param angle - The angle to rotate.
|
|
92
|
-
* @default 90 (0, 90, 180, 270, 360)
|
|
93
|
-
* @param clockwise - The direction to rotate.
|
|
94
|
-
* @default true (clockwise)
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* rotate(0) // reset rotation
|
|
98
|
-
* rotate(number, false) // rotate {number} degrees counter-clockwise
|
|
99
|
-
* rotate(90) // rotate 90 degrees clockwise
|
|
100
|
-
* rotate(180) // rotate 180 degrees clockwise
|
|
101
|
-
* rotate(270) // rotate 270 degrees clockwise
|
|
102
|
-
* rotate(360) // rotate 360 degrees clockwise
|
|
103
|
-
*/
|
|
104
128
|
rotate = (angle: 0 | 90 | 180 | 270 | 360 = 90, clockwise = true) => {
|
|
105
129
|
const MAX_ANGLE = 360;
|
|
106
130
|
|
|
@@ -130,11 +154,6 @@ class GestureViewerManager {
|
|
|
130
154
|
this.rotation.value = withTiming(nextAngle);
|
|
131
155
|
};
|
|
132
156
|
|
|
133
|
-
/**
|
|
134
|
-
* @param multiplier - The multiplier to zoom in.
|
|
135
|
-
* @range 0.01 - 1
|
|
136
|
-
* @default 0.25
|
|
137
|
-
*/
|
|
138
157
|
zoomIn = (multiplier = 0.25) => {
|
|
139
158
|
if (!this.scale || !this.translateX || !this.translateY || multiplier < 0.01 || multiplier > 1) {
|
|
140
159
|
return;
|
|
@@ -157,11 +176,6 @@ class GestureViewerManager {
|
|
|
157
176
|
this.translateY.value = withTiming(translateY);
|
|
158
177
|
};
|
|
159
178
|
|
|
160
|
-
/**
|
|
161
|
-
* @param multiplier - The multiplier to zoom out.
|
|
162
|
-
* @range 0.01 - 1
|
|
163
|
-
* @default 0.25
|
|
164
|
-
*/
|
|
165
179
|
zoomOut = (multiplier = 0.25) => {
|
|
166
180
|
if (!this.scale || !this.translateX || !this.translateY || multiplier < 0.01 || multiplier > 1) {
|
|
167
181
|
return;
|
|
@@ -190,10 +204,6 @@ class GestureViewerManager {
|
|
|
190
204
|
this.translateY.value = withTiming(translateY);
|
|
191
205
|
};
|
|
192
206
|
|
|
193
|
-
/**
|
|
194
|
-
* @param scale - The scale to reset to.
|
|
195
|
-
* @default 1
|
|
196
|
-
*/
|
|
197
207
|
resetZoom = (scale = 1) => {
|
|
198
208
|
if (!this.scale || !this.translateX || !this.translateY || scale <= 0 || scale > this.maxZoomScale) {
|
|
199
209
|
return;
|
|
@@ -244,6 +254,7 @@ class GestureViewerManager {
|
|
|
244
254
|
this.translateX = null;
|
|
245
255
|
this.translateY = null;
|
|
246
256
|
this.rotation = null;
|
|
257
|
+
this.eventListeners.clear();
|
|
247
258
|
}
|
|
248
259
|
}
|
|
249
260
|
|
package/src/index.tsx
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export { GestureViewer } from './GestureViewer';
|
|
2
|
-
export type {
|
|
2
|
+
export type {
|
|
3
|
+
GestureViewerController,
|
|
4
|
+
GestureViewerControllerState,
|
|
5
|
+
GestureViewerEventCallback,
|
|
6
|
+
GestureViewerEventData,
|
|
7
|
+
GestureViewerEventType,
|
|
8
|
+
GestureViewerProps,
|
|
9
|
+
} from './types';
|
|
3
10
|
export { useGestureViewerController } from './useGestureViewerController';
|
|
11
|
+
export { useGestureViewerEvent } from './useGestureViewerEvent';
|