react-native-gesture-image-viewer 2.1.2 → 2.1.3
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 +1 -1
- package/lib/module/GestureTrigger.js.map +1 -1
- package/lib/module/GestureViewer.js +37 -30
- package/lib/module/GestureViewer.js.map +1 -1
- package/lib/module/GestureViewerManager.js.map +1 -1
- package/lib/module/GestureViewerRegistry.js.map +1 -1
- package/lib/module/WebPagingFixStyle.js.map +1 -1
- package/lib/module/useGestureViewer.js +168 -173
- package/lib/module/useGestureViewer.js.map +1 -1
- package/lib/module/useGestureViewerController.js.map +1 -1
- package/lib/module/useGestureViewerEvent.js.map +1 -1
- package/lib/module/useGestureViewerState.js.map +1 -1
- package/lib/module/utils/index.js +14 -16
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/src/GestureTrigger.d.ts +1 -1
- package/lib/typescript/src/GestureTrigger.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerManager.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerRegistry.d.ts.map +1 -1
- package/lib/typescript/src/WebPagingFixStyle.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewer.d.ts +11 -10
- package/lib/typescript/src/useGestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerController.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerEvent.d.ts.map +1 -1
- package/lib/typescript/src/useGestureViewerState.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/package.json +86 -80
- package/src/GestureTrigger.tsx +9 -2
- package/src/GestureViewer.tsx +46 -21
- package/src/GestureViewerManager.ts +33 -6
- package/src/GestureViewerRegistry.ts +1 -0
- package/src/WebPagingFixStyle.tsx +1 -0
- package/src/types.ts +44 -32
- package/src/useGestureViewer.ts +267 -220
- package/src/useGestureViewerController.ts +1 -0
- package/src/useGestureViewerEvent.ts +5 -1
- package/src/useGestureViewerState.ts +1 -0
- package/src/utils/index.ts +31 -15
package/src/utils/index.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { FlatList as RNFlatList, ScrollView as RNScrollView } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
FlatList as GestureFlatList,
|
|
4
|
+
ScrollView as GestureScrollView,
|
|
5
|
+
} from 'react-native-gesture-handler';
|
|
6
|
+
|
|
3
7
|
import type { FlatListComponent, ScrollViewComponent } from '../types';
|
|
8
|
+
|
|
4
9
|
import { FlashList } from './FlashList';
|
|
5
10
|
|
|
6
|
-
export const isScrollViewLike = (
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
export const isScrollViewLike = (
|
|
12
|
+
component: React.ComponentType<any>,
|
|
13
|
+
): component is ScrollViewComponent =>
|
|
14
|
+
component === RNScrollView || component === GestureScrollView;
|
|
9
15
|
|
|
10
|
-
export const isFlatListLike = (
|
|
16
|
+
export const isFlatListLike = (
|
|
17
|
+
component: React.ComponentType<any>,
|
|
18
|
+
): component is FlatListComponent<any> => {
|
|
11
19
|
if (component === RNFlatList || component === GestureFlatList || isFlashListLike(component)) {
|
|
12
20
|
return true;
|
|
13
21
|
}
|
|
@@ -25,7 +33,15 @@ export const isFlashListLike = (component: React.ComponentType<any>): boolean =>
|
|
|
25
33
|
|
|
26
34
|
export const createBoundsConstraint =
|
|
27
35
|
({ width, height }: { width: number; height: number }) =>
|
|
28
|
-
({
|
|
36
|
+
({
|
|
37
|
+
scale,
|
|
38
|
+
translateX,
|
|
39
|
+
translateY,
|
|
40
|
+
}: {
|
|
41
|
+
translateX: number;
|
|
42
|
+
translateY: number;
|
|
43
|
+
scale: number;
|
|
44
|
+
}) => {
|
|
29
45
|
'worklet';
|
|
30
46
|
|
|
31
47
|
if (scale <= 1) {
|
|
@@ -51,7 +67,7 @@ export const createLoopData = <T>(dataRef: React.RefObject<T[]>, enableLoop: boo
|
|
|
51
67
|
return data;
|
|
52
68
|
}
|
|
53
69
|
|
|
54
|
-
const lastItem = data
|
|
70
|
+
const lastItem = data.at(-1);
|
|
55
71
|
const firstItem = data[0];
|
|
56
72
|
|
|
57
73
|
if (lastItem === undefined || firstItem === undefined) {
|
|
@@ -67,32 +83,32 @@ export const getLoopAdjustedIndex = (
|
|
|
67
83
|
enableLoop: boolean,
|
|
68
84
|
): { realIndex: number; needsJump: boolean; jumpToIndex?: number } => {
|
|
69
85
|
if (!enableLoop || originalDataLength <= 1) {
|
|
70
|
-
return {
|
|
86
|
+
return { needsJump: false, realIndex: scrollIndex };
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
if (scrollIndex === 0) {
|
|
74
90
|
return {
|
|
75
|
-
realIndex: originalDataLength - 1,
|
|
76
|
-
needsJump: true,
|
|
77
91
|
jumpToIndex: originalDataLength,
|
|
92
|
+
needsJump: true,
|
|
93
|
+
realIndex: originalDataLength - 1,
|
|
78
94
|
};
|
|
79
95
|
} else if (scrollIndex === originalDataLength + 1) {
|
|
80
96
|
return {
|
|
81
|
-
realIndex: 0,
|
|
82
|
-
needsJump: true,
|
|
83
97
|
jumpToIndex: 1,
|
|
98
|
+
needsJump: true,
|
|
99
|
+
realIndex: 0,
|
|
84
100
|
};
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
return { realIndex: scrollIndex - 1
|
|
103
|
+
return { needsJump: false, realIndex: scrollIndex - 1 };
|
|
88
104
|
};
|
|
89
105
|
|
|
90
106
|
export const createScrollAction = (listRef: any, width: number) => ({
|
|
91
107
|
scrollTo: (index: number, animated: boolean) => {
|
|
92
108
|
if (listRef?.scrollToIndex) {
|
|
93
|
-
listRef.scrollToIndex({
|
|
109
|
+
listRef.scrollToIndex({ animated, index });
|
|
94
110
|
} else if (listRef?.scrollTo) {
|
|
95
|
-
listRef.scrollTo({ x: index * width
|
|
111
|
+
listRef.scrollTo({ animated, x: index * width });
|
|
96
112
|
}
|
|
97
113
|
},
|
|
98
114
|
});
|