react-native-gesture-image-viewer 2.0.0-beta.3 → 2.0.0-beta.5
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 +43 -19
- package/lib/module/GestureTrigger.js +82 -0
- package/lib/module/GestureTrigger.js.map +1 -0
- package/lib/module/GestureViewer.js +14 -8
- package/lib/module/GestureViewer.js.map +1 -1
- package/lib/module/GestureViewerManager.js +5 -5
- package/lib/module/GestureViewerManager.js.map +1 -1
- package/lib/module/GestureViewerRegistry.js +11 -0
- package/lib/module/GestureViewerRegistry.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useGestureViewer.js +140 -71
- package/lib/module/useGestureViewer.js.map +1 -1
- package/lib/module/useGestureViewerController.js +17 -66
- package/lib/module/useGestureViewerController.js.map +1 -1
- package/lib/module/useGestureViewerState.js +78 -0
- package/lib/module/useGestureViewerState.js.map +1 -0
- package/lib/typescript/src/GestureTrigger.d.ts +55 -0
- package/lib/typescript/src/GestureTrigger.d.ts.map +1 -0
- package/lib/typescript/src/GestureViewer.d.ts +2 -2
- package/lib/typescript/src/GestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerManager.d.ts +5 -8
- package/lib/typescript/src/GestureViewerManager.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerRegistry.d.ts +5 -0
- package/lib/typescript/src/GestureViewerRegistry.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +116 -58
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewer.d.ts +9 -8
- package/lib/typescript/src/useGestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerController.d.ts +10 -21
- package/lib/typescript/src/useGestureViewerController.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerState.d.ts +35 -0
- package/lib/typescript/src/useGestureViewerState.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/GestureTrigger.tsx +86 -0
- package/src/GestureViewer.tsx +15 -9
- package/src/GestureViewerManager.ts +9 -9
- package/src/GestureViewerRegistry.ts +16 -0
- package/src/index.tsx +4 -1
- package/src/types.ts +116 -60
- package/src/useGestureViewer.ts +180 -77
- package/src/useGestureViewerController.ts +19 -76
- package/src/useGestureViewerState.ts +85 -0
package/src/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { FlatList as RNFlatList, ScrollView as RNScrollView, StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
import type { FlatList as GHFlatList, ScrollView as GHScrollView } from 'react-native-gesture-handler';
|
|
4
|
+
import type { WithTimingConfig } from 'react-native-reanimated';
|
|
4
5
|
|
|
5
6
|
export type FlatListComponent = typeof RNFlatList | typeof GHFlatList;
|
|
6
7
|
export type ScrollViewComponent = typeof RNScrollView | typeof GHScrollView;
|
|
@@ -13,7 +14,31 @@ type ConditionalListProps<LC> = LC extends FlatListComponent
|
|
|
13
14
|
? React.ComponentProps<LC>
|
|
14
15
|
: GetComponentProps<LC>;
|
|
15
16
|
|
|
16
|
-
export
|
|
17
|
+
export type TriggerRect = {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface TriggerAnimationConfig extends WithTimingConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Animation duration in milliseconds
|
|
27
|
+
* @defaultValue 300
|
|
28
|
+
*/
|
|
29
|
+
duration?: WithTimingConfig['duration'];
|
|
30
|
+
/**
|
|
31
|
+
* Animation easing function
|
|
32
|
+
* @defaultValue Easing.bezier(0.25, 0.1, 0.25, 1.0)
|
|
33
|
+
*/
|
|
34
|
+
easing?: WithTimingConfig['easing'];
|
|
35
|
+
/**
|
|
36
|
+
* Callback function called after animation completion
|
|
37
|
+
*/
|
|
38
|
+
onAnimationComplete?: () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface GestureViewerProps<T = any, LC = typeof RNScrollView> {
|
|
17
42
|
/**
|
|
18
43
|
* When you want to efficiently manage multiple `GestureViewer` instances, you can use the `id` prop to use multiple `GestureViewer` components.
|
|
19
44
|
* @remark `GestureViewer` automatically removes instances from memory when components are unmounted, so no manual memory management is required.
|
|
@@ -29,22 +54,29 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
29
54
|
* @defaultValue 0
|
|
30
55
|
*/
|
|
31
56
|
initialIndex?: number;
|
|
32
|
-
/**
|
|
33
|
-
* A callback function that is called when the index of the item changes.
|
|
34
|
-
*/
|
|
35
|
-
onIndexChange?: (index: number) => void;
|
|
36
57
|
/**
|
|
37
58
|
* A callback function that is called when the `GestureViewer` is dismissed.
|
|
38
59
|
*/
|
|
39
60
|
onDismiss?: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* A callback function that is called when the dismiss interaction starts.
|
|
63
|
+
* @remarks Useful to hide external UI (e.g., headers, buttons) while the dismiss gesture/animation is in progress.
|
|
64
|
+
*/
|
|
65
|
+
onDismissStart?: () => void;
|
|
40
66
|
/**
|
|
41
67
|
* A callback function that is called to render the item.
|
|
42
68
|
*/
|
|
43
69
|
renderItem: (item: T, index: number) => React.ReactElement;
|
|
44
70
|
/**
|
|
45
71
|
* A callback function that is called to render the container.
|
|
72
|
+
* @remarks Useful for composing additional UI (e.g., close button, toolbars) around the viewer.
|
|
73
|
+
* The second argument provides control helpers such as `dismiss()` to close the viewer.
|
|
74
|
+
*
|
|
75
|
+
* @param children - The viewer content to be rendered inside your container.
|
|
76
|
+
* @param helpers - Control helpers for the viewer. Currently includes `dismiss()`.
|
|
77
|
+
* @returns A React element that wraps and renders the provided `children`.
|
|
46
78
|
*/
|
|
47
|
-
renderContainer?: (children: React.ReactElement) => React.ReactElement;
|
|
79
|
+
renderContainer?: (children: React.ReactElement, helpers: { dismiss: () => void }) => React.ReactElement;
|
|
48
80
|
/**
|
|
49
81
|
* Support for any list component like `ScrollView`, `FlatList`, `FlashList` through the `ListComponent` prop.
|
|
50
82
|
*/
|
|
@@ -55,44 +87,6 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
55
87
|
* @defaultValue screen width
|
|
56
88
|
*/
|
|
57
89
|
width?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Enables snap scrolling mode.
|
|
60
|
-
*
|
|
61
|
-
* @remark
|
|
62
|
-
* **`false` (default)**: Paging mode (`pagingEnabled: true`)
|
|
63
|
-
* - Scrolls by full screen size increments
|
|
64
|
-
*
|
|
65
|
-
* **`true`**: Snap mode (`snapToInterval` auto-calculated)
|
|
66
|
-
* - `snapToInterval` is automatically calculated based on `width` and `itemSpacing` values
|
|
67
|
-
* - Use this option when you need item spacing
|
|
68
|
-
* @defaultValue false
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
useSnap?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* `dismissThreshold` controls when `onDismiss` is called by applying a threshold value during vertical gestures.
|
|
74
|
-
* @defaultValue 80
|
|
75
|
-
*/
|
|
76
|
-
dismissThreshold?: number;
|
|
77
|
-
// swipeThreshold?: number;
|
|
78
|
-
// velocityThreshold?: number;
|
|
79
|
-
/**
|
|
80
|
-
* Calls `onDismiss` function when swiping down.
|
|
81
|
-
* @remark Useful for closing modals with downward swipe gestures.
|
|
82
|
-
* @defaultValue true
|
|
83
|
-
*/
|
|
84
|
-
enableDismissGesture?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Controls left/right swipe gestures.
|
|
87
|
-
* @remark When `false`, horizontal gestures are disabled.
|
|
88
|
-
* @defaultValue true
|
|
89
|
-
*/
|
|
90
|
-
enableSwipeGesture?: boolean;
|
|
91
|
-
/**
|
|
92
|
-
* `resistance` controls the range of vertical movement by applying resistance during vertical gestures.
|
|
93
|
-
* @defaultValue 2
|
|
94
|
-
*/
|
|
95
|
-
resistance?: number;
|
|
96
90
|
/**
|
|
97
91
|
* The props to pass to the list component.
|
|
98
92
|
* @remark The `listProps` provides **type inference based on the selected list component**, ensuring accurate autocompletion and type safety in your IDE.
|
|
@@ -107,45 +101,105 @@ export interface GestureViewerProps<T = any, LC = typeof RNFlatList> {
|
|
|
107
101
|
*/
|
|
108
102
|
containerStyle?: StyleProp<ViewStyle>;
|
|
109
103
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @remark
|
|
104
|
+
* Dismiss gesture options. Calls `onDismiss` function when swiping down.
|
|
105
|
+
* @remark Useful for closing modals with downward swipe gestures.
|
|
106
|
+
*/
|
|
107
|
+
dismiss?: {
|
|
108
|
+
/**
|
|
109
|
+
* When `false`, dismiss gesture is disabled.
|
|
110
|
+
* @defaultValue true
|
|
111
|
+
*/
|
|
112
|
+
enabled?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* `threshold` controls when `onDismiss` is called by applying a threshold value during vertical gestures.
|
|
115
|
+
* @defaultValue 80
|
|
116
|
+
*/
|
|
117
|
+
threshold?: number;
|
|
118
|
+
/**
|
|
119
|
+
* `resistance` controls the range of vertical movement by applying resistance during dismiss gestures.
|
|
120
|
+
* @defaultValue 2
|
|
121
|
+
*/
|
|
122
|
+
resistance?: number;
|
|
123
|
+
/**
|
|
124
|
+
* By default, the background `opacity` gradually decreases from 1 to 0 during downward swipe gestures.
|
|
125
|
+
* @remark When `false`, this animation is disabled.
|
|
126
|
+
* @defaultValue true
|
|
127
|
+
*/
|
|
128
|
+
fadeBackdrop?: boolean;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Controls left/right swipe gestures.
|
|
132
|
+
* @remark When `false`, horizontal gestures are disabled.
|
|
112
133
|
* @defaultValue true
|
|
113
134
|
*/
|
|
114
|
-
|
|
135
|
+
enableHorizontalSwipe?: boolean;
|
|
115
136
|
/**
|
|
116
137
|
* Only works when zoom is active, allows moving item position when zoomed.
|
|
117
138
|
* @remark When `false`, gesture movement is disabled during zoom.
|
|
118
139
|
* @defaultValue true
|
|
119
140
|
*/
|
|
120
|
-
|
|
141
|
+
enablePanWhenZoomed?: boolean;
|
|
121
142
|
/**
|
|
122
143
|
* Controls two-finger pinch gestures.
|
|
123
144
|
* @remark When `false`, two-finger zoom gestures are disabled.
|
|
124
145
|
* @defaultValue true
|
|
125
146
|
*/
|
|
126
|
-
|
|
147
|
+
enablePinchZoom?: boolean;
|
|
127
148
|
/**
|
|
128
149
|
* Controls double-tap zoom gestures.
|
|
129
150
|
* @remark When `false`, double-tap zoom gestures are disabled.
|
|
130
151
|
* @defaultValue true
|
|
131
152
|
*/
|
|
132
|
-
|
|
153
|
+
enableDoubleTapZoom?: boolean;
|
|
133
154
|
/**
|
|
134
155
|
* Enables infinite loop navigation.
|
|
135
156
|
* @defaultValue false
|
|
136
157
|
*/
|
|
137
158
|
enableLoop?: boolean;
|
|
138
159
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
160
|
+
* Enables snap scrolling mode.
|
|
161
|
+
*
|
|
162
|
+
* @remark
|
|
163
|
+
* **`false` (default)**: Paging mode (`pagingEnabled: true`)
|
|
164
|
+
* - Scrolls by full screen size increments
|
|
165
|
+
*
|
|
166
|
+
* **`true`**: Snap mode (`snapToInterval` auto-calculated)
|
|
167
|
+
* - `snapToInterval` is automatically calculated based on `width` and `itemSpacing` values
|
|
168
|
+
* - Use this option when you need item spacing
|
|
169
|
+
* @defaultValue false
|
|
170
|
+
*
|
|
141
171
|
*/
|
|
142
|
-
|
|
172
|
+
enableSnapMode?: boolean;
|
|
143
173
|
/**
|
|
144
174
|
* The spacing between items in pixels.
|
|
145
|
-
* @remark Only applied when `
|
|
175
|
+
* @remark Only applied when `enableSnapMode` is `true`.
|
|
146
176
|
* @defaultValue 0
|
|
147
177
|
*/
|
|
148
178
|
itemSpacing?: number;
|
|
179
|
+
/**
|
|
180
|
+
* The maximum zoom scale.
|
|
181
|
+
* @defaultValue 2
|
|
182
|
+
*/
|
|
183
|
+
maxZoomScale?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Trigger-based animation settings
|
|
186
|
+
* @remarks You can customize animation duration, easing, and system reduce-motion behavior.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* <GestureViewer
|
|
191
|
+
* triggerAnimation={{
|
|
192
|
+
* duration: 250,
|
|
193
|
+
* easing: Easing.out(Easing.cubic),
|
|
194
|
+
* reduceMotion: 'system',
|
|
195
|
+
* onAnimationComplete: () => {
|
|
196
|
+
* console.log('Animation complete');
|
|
197
|
+
* },
|
|
198
|
+
* }}
|
|
199
|
+
* />
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
triggerAnimation?: TriggerAnimationConfig;
|
|
149
203
|
}
|
|
150
204
|
|
|
151
205
|
/**
|
|
@@ -167,8 +221,10 @@ export type GestureViewerController = {
|
|
|
167
221
|
*
|
|
168
222
|
* @example
|
|
169
223
|
* ```typescript
|
|
224
|
+
* const { totalCount } = useGestureViewerState();
|
|
225
|
+
*
|
|
170
226
|
* controller.goToIndex(0); // Go to first item
|
|
171
|
-
* controller.goToIndex(
|
|
227
|
+
* controller.goToIndex(totalCount - 1); // Go to last item
|
|
172
228
|
* ```
|
|
173
229
|
*/
|
|
174
230
|
goToIndex: (index: number) => void;
|
|
@@ -252,13 +308,13 @@ export type GestureViewerController = {
|
|
|
252
308
|
* ```
|
|
253
309
|
*/
|
|
254
310
|
rotate: (angle?: RotationAngle, clockwise?: boolean) => void;
|
|
255
|
-
}
|
|
311
|
+
};
|
|
256
312
|
|
|
257
313
|
/**
|
|
258
314
|
* State information for the gesture viewer controller.
|
|
259
315
|
* Contains read-only properties that reflect the current state.
|
|
260
316
|
*/
|
|
261
|
-
export type
|
|
317
|
+
export type GestureViewerState = {
|
|
262
318
|
/**
|
|
263
319
|
* The current index of the active item in the viewer.
|
|
264
320
|
*
|
|
@@ -267,7 +323,7 @@ export type GestureViewerControllerState = {
|
|
|
267
323
|
*
|
|
268
324
|
* @example
|
|
269
325
|
* ```typescript
|
|
270
|
-
* console.log(`Currently viewing item ${
|
|
326
|
+
* console.log(`Currently viewing item ${currentIndex + 1} of ${totalCount}`);
|
|
271
327
|
* ```
|
|
272
328
|
*/
|
|
273
329
|
readonly currentIndex: number;
|
|
@@ -280,8 +336,8 @@ export type GestureViewerControllerState = {
|
|
|
280
336
|
*
|
|
281
337
|
* @example
|
|
282
338
|
* ```typescript
|
|
283
|
-
* const hasNext =
|
|
284
|
-
* const hasPrevious =
|
|
339
|
+
* const hasNext = currentIndex < totalCount - 1;
|
|
340
|
+
* const hasPrevious = currentIndex > 0;
|
|
285
341
|
* ```
|
|
286
342
|
*/
|
|
287
343
|
readonly totalCount: number;
|