react-native-gesture-image-viewer 2.4.0 → 3.0.0-beta.1
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 +5 -3
- package/lib/module/GestureViewer.js +96 -147
- package/lib/module/GestureViewer.js.map +1 -1
- package/lib/module/GestureViewerManager.js +49 -105
- package/lib/module/GestureViewerManager.js.map +1 -1
- package/lib/module/gestureViewerAnimation.js +18 -0
- package/lib/module/gestureViewerAnimation.js.map +1 -0
- package/lib/module/gestureViewerGestures.js +12 -0
- package/lib/module/gestureViewerGestures.js.map +1 -0
- package/lib/module/gestureViewerPaging.js +66 -0
- package/lib/module/gestureViewerPaging.js.map +1 -0
- package/lib/module/gestureViewerRenderWindow.js +29 -0
- package/lib/module/gestureViewerRenderWindow.js.map +1 -0
- package/lib/module/getWebContentProps.js +6 -0
- package/lib/module/getWebContentProps.js.map +1 -0
- package/lib/module/getWebContentProps.web.js +8 -0
- package/lib/module/getWebContentProps.web.js.map +1 -0
- package/lib/module/platformTapGestures.js +4 -0
- package/lib/module/platformTapGestures.js.map +1 -0
- package/lib/module/platformTapGestures.web.js +4 -0
- package/lib/module/platformTapGestures.web.js.map +1 -0
- package/lib/module/renderWindow.js +160 -0
- package/lib/module/renderWindow.js.map +1 -0
- package/lib/module/useGestureViewer.js +459 -211
- package/lib/module/useGestureViewer.js.map +1 -1
- package/lib/module/useGestureViewerController.js +3 -3
- package/lib/module/useGestureViewerController.js.map +1 -1
- package/lib/module/useGestureViewerManagerBridge.js +85 -0
- package/lib/module/useGestureViewerManagerBridge.js.map +1 -0
- package/lib/module/useGestureViewerPaging.js +168 -79
- package/lib/module/useGestureViewerPaging.js.map +1 -1
- package/lib/module/useWebClickHandler.js +7 -0
- package/lib/module/useWebClickHandler.js.map +1 -0
- package/lib/module/useWebClickHandler.web.js +85 -0
- package/lib/module/useWebClickHandler.web.js.map +1 -0
- package/lib/module/useWebSingleTapTimer.js +12 -0
- package/lib/module/useWebSingleTapTimer.js.map +1 -0
- package/lib/module/useWebSingleTapTimer.web.js +25 -0
- package/lib/module/useWebSingleTapTimer.web.js.map +1 -0
- package/lib/module/utils/index.js +0 -77
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/tapZoom.js +4 -3
- package/lib/module/utils/tapZoom.js.map +1 -1
- package/lib/typescript/src/GestureViewer.d.ts +1 -1
- package/lib/typescript/src/GestureViewer.d.ts.map +1 -1
- package/lib/typescript/src/GestureViewerManager.d.ts +20 -20
- package/lib/typescript/src/GestureViewerManager.d.ts.map +1 -1
- package/lib/typescript/src/gestureViewerAnimation.d.ts +15 -0
- package/lib/typescript/src/gestureViewerAnimation.d.ts.map +1 -0
- package/lib/typescript/src/gestureViewerGestures.d.ts +10 -0
- package/lib/typescript/src/gestureViewerGestures.d.ts.map +1 -0
- package/lib/typescript/src/gestureViewerPaging.d.ts +13 -0
- package/lib/typescript/src/gestureViewerPaging.d.ts.map +1 -0
- package/lib/typescript/src/gestureViewerRenderWindow.d.ts +15 -0
- package/lib/typescript/src/gestureViewerRenderWindow.d.ts.map +1 -0
- package/lib/typescript/src/getWebContentProps.d.ts +3 -0
- package/lib/typescript/src/getWebContentProps.d.ts.map +1 -0
- package/lib/typescript/src/getWebContentProps.web.d.ts +5 -0
- package/lib/typescript/src/getWebContentProps.web.d.ts.map +1 -0
- package/lib/typescript/src/platformTapGestures.d.ts +2 -0
- package/lib/typescript/src/platformTapGestures.d.ts.map +1 -0
- package/lib/typescript/src/platformTapGestures.web.d.ts +2 -0
- package/lib/typescript/src/platformTapGestures.web.d.ts.map +1 -0
- package/lib/typescript/src/renderWindow.d.ts +44 -0
- package/lib/typescript/src/renderWindow.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +36 -53
- 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 +1 -1
- package/lib/typescript/src/useGestureViewerManagerBridge.d.ts +28 -0
- package/lib/typescript/src/useGestureViewerManagerBridge.d.ts.map +1 -0
- package/lib/typescript/src/useGestureViewerPaging.d.ts +33 -2
- package/lib/typescript/src/useGestureViewerPaging.d.ts.map +1 -1
- package/lib/typescript/src/useWebClickHandler.d.ts +35 -0
- package/lib/typescript/src/useWebClickHandler.d.ts.map +1 -0
- package/lib/typescript/src/useWebClickHandler.web.d.ts +36 -0
- package/lib/typescript/src/useWebClickHandler.web.d.ts.map +1 -0
- package/lib/typescript/src/useWebSingleTapTimer.d.ts +6 -0
- package/lib/typescript/src/useWebSingleTapTimer.d.ts.map +1 -0
- package/lib/typescript/src/useWebSingleTapTimer.web.d.ts +6 -0
- package/lib/typescript/src/useWebSingleTapTimer.web.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +0 -20
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/tapZoom.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/GestureViewer.tsx +113 -208
- package/src/GestureViewerManager.ts +77 -122
- package/src/gestureViewerAnimation.ts +18 -0
- package/src/gestureViewerGestures.ts +20 -0
- package/src/gestureViewerPaging.ts +116 -0
- package/src/gestureViewerRenderWindow.ts +56 -0
- package/src/getWebContentProps.ts +5 -0
- package/src/getWebContentProps.web.ts +5 -0
- package/src/platformTapGestures.ts +1 -0
- package/src/platformTapGestures.web.ts +1 -0
- package/src/renderWindow.ts +253 -0
- package/src/types.ts +34 -100
- package/src/useGestureViewer.ts +665 -275
- package/src/useGestureViewerController.ts +3 -3
- package/src/useGestureViewerManagerBridge.ts +118 -0
- package/src/useGestureViewerPaging.ts +306 -112
- package/src/useWebClickHandler.ts +44 -0
- package/src/useWebClickHandler.web.ts +146 -0
- package/src/useWebSingleTapTimer.ts +10 -0
- package/src/useWebSingleTapTimer.web.ts +30 -0
- package/src/utils/index.ts +0 -102
- package/src/utils/tapZoom.ts +4 -3
- package/lib/module/WebPagingFixStyle.js +0 -25
- package/lib/module/WebPagingFixStyle.js.map +0 -1
- package/lib/module/scheduleInitialScroll.js +0 -21
- package/lib/module/scheduleInitialScroll.js.map +0 -1
- package/lib/module/useGestureViewerPaging.types.js +0 -4
- package/lib/module/useGestureViewerPaging.types.js.map +0 -1
- package/lib/module/useGestureViewerPaging.web.js +0 -291
- package/lib/module/useGestureViewerPaging.web.js.map +0 -1
- package/lib/module/utils/FlashList.js +0 -9
- package/lib/module/utils/FlashList.js.map +0 -1
- package/lib/module/utils/webScroll.js +0 -70
- package/lib/module/utils/webScroll.js.map +0 -1
- package/lib/typescript/src/WebPagingFixStyle.d.ts +0 -6
- package/lib/typescript/src/WebPagingFixStyle.d.ts.map +0 -1
- package/lib/typescript/src/scheduleInitialScroll.d.ts +0 -3
- package/lib/typescript/src/scheduleInitialScroll.d.ts.map +0 -1
- package/lib/typescript/src/useGestureViewerPaging.types.d.ts +0 -42
- package/lib/typescript/src/useGestureViewerPaging.types.d.ts.map +0 -1
- package/lib/typescript/src/useGestureViewerPaging.web.d.ts +0 -3
- package/lib/typescript/src/useGestureViewerPaging.web.d.ts.map +0 -1
- package/lib/typescript/src/utils/FlashList.d.ts +0 -2
- package/lib/typescript/src/utils/FlashList.d.ts.map +0 -1
- package/lib/typescript/src/utils/webScroll.d.ts +0 -18
- package/lib/typescript/src/utils/webScroll.d.ts.map +0 -1
- package/src/WebPagingFixStyle.tsx +0 -25
- package/src/scheduleInitialScroll.ts +0 -36
- package/src/useGestureViewerPaging.types.ts +0 -42
- package/src/useGestureViewerPaging.web.ts +0 -453
- package/src/utils/FlashList.ts +0 -7
- package/src/utils/webScroll.ts +0 -96
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Existing libraries often have limited customization options or performance issue
|
|
|
23
23
|
- 🎨 **Full Customization** - Total control over components, styles, and gesture behavior
|
|
24
24
|
- 🎛️ **External Control API** - Trigger actions programmatically from buttons or other UI components
|
|
25
25
|
- 🧩 **Multi-Instance Management** - Manage multiple viewers independently using unique IDs
|
|
26
|
-
- 🧬 **Flexible Integration** - Use with Modal, [React Native Modal](https://www.npmjs.com/package/react-native-modal),
|
|
26
|
+
- 🧬 **Flexible Integration** - Use with Modal, [React Native Modal](https://www.npmjs.com/package/react-native-modal), [Expo Image](https://www.npmjs.com/package/expo-image), [FastImage](https://github.com/DylanVann/react-native-fast-image), videos, and custom content
|
|
27
27
|
- 🧠 **Full TypeScript Support** - Great developer experience with type inference and safety
|
|
28
28
|
- 🌐 **Cross-Platform** - Runs on iOS, Android, and Web with Expo Go and New Architecture compatibility
|
|
29
29
|
- 🪄 **Easy-to-Use API** - Simple and intuitive API that requires minimal setup
|
|
@@ -34,6 +34,8 @@ Existing libraries often have limited customization options or performance issue
|
|
|
34
34
|
|
|
35
35
|
Full documentation is available at: <https://react-native-gesture-image-viewer.pages.dev>
|
|
36
36
|
|
|
37
|
+
> v3 is currently in beta. Install it with `react-native-gesture-image-viewer@beta` and use the [v3 beta docs](https://react-native-gesture-image-viewer.pages.dev/3.x-beta/). The docs root still points to the stable v2 documentation.
|
|
38
|
+
|
|
37
39
|
### Examples & Demo
|
|
38
40
|
|
|
39
41
|
- [📁 Example Project](/example/) - Real implementation code with various use cases
|
|
@@ -50,7 +52,7 @@ Full documentation is available at: <https://react-native-gesture-image-viewer.p
|
|
|
50
52
|
|
|
51
53
|
```tsx
|
|
52
54
|
import { useCallback, useState } from 'react';
|
|
53
|
-
import {
|
|
55
|
+
import { Image, Modal, View, Text, Button, Pressable } from 'react-native';
|
|
54
56
|
import {
|
|
55
57
|
GestureViewer,
|
|
56
58
|
GestureTrigger,
|
|
@@ -95,7 +97,7 @@ function App() {
|
|
|
95
97
|
data={images}
|
|
96
98
|
initialIndex={selectedIndex}
|
|
97
99
|
renderItem={renderImage}
|
|
98
|
-
|
|
100
|
+
pageSpacing={16}
|
|
99
101
|
onDismiss={() => setVisible(false)}
|
|
100
102
|
/>
|
|
101
103
|
<View>
|
|
@@ -1,212 +1,161 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import Animated from 'react-native-reanimated';
|
|
3
|
+
import { useEffect, useMemo } from 'react';
|
|
4
|
+
import { StyleSheet, useWindowDimensions, View } from 'react-native';
|
|
5
|
+
import { GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
6
|
+
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
|
|
7
|
+
import { composeGestureViewerGestures } from "./gestureViewerGestures.js";
|
|
7
8
|
import { registry } from "./GestureViewerRegistry.js";
|
|
9
|
+
import { getWebContentProps } from './getWebContentProps';
|
|
8
10
|
import { useGestureViewer } from "./useGestureViewer.js";
|
|
9
|
-
import { createLoopData, isFlashListLike, isFlatListLike, isScrollViewLike, shouldUseNativeScrollGesture } from "./utils/index.js";
|
|
10
|
-
import WebPagingFixStyle from "./WebPagingFixStyle.js";
|
|
11
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
function RenderWindowSlotView({
|
|
13
|
+
animatedStyle,
|
|
14
|
+
height,
|
|
15
|
+
isActive,
|
|
16
|
+
pageStride,
|
|
17
|
+
renderItem,
|
|
18
|
+
slot,
|
|
19
|
+
visualPage,
|
|
20
|
+
width
|
|
21
|
+
}) {
|
|
22
|
+
const slotAnimatedStyle = useAnimatedStyle(() => ({
|
|
23
|
+
transform: [{
|
|
24
|
+
translateX: (slot.virtualIndex - visualPage.get()) * pageStride
|
|
25
|
+
}]
|
|
26
|
+
}));
|
|
27
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
28
|
+
style: [styles.slot, {
|
|
29
|
+
height,
|
|
30
|
+
width
|
|
31
|
+
}, slotAnimatedStyle],
|
|
32
|
+
children: /*#__PURE__*/_jsx(Animated.View, {
|
|
33
|
+
style: [styles.page, isActive && animatedStyle],
|
|
34
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
35
|
+
style: [styles.item, {
|
|
36
|
+
height,
|
|
37
|
+
width
|
|
38
|
+
}],
|
|
39
|
+
children: renderItem(slot.item, slot.logicalIndex, {
|
|
40
|
+
isActive
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
12
46
|
export function GestureViewer({
|
|
13
47
|
id = 'default',
|
|
14
48
|
data,
|
|
15
|
-
renderItem
|
|
49
|
+
renderItem,
|
|
16
50
|
renderContainer,
|
|
17
|
-
ListComponent,
|
|
18
51
|
width: customWidth,
|
|
19
52
|
height: customHeight,
|
|
20
|
-
listProps,
|
|
21
53
|
backdropStyle: backdropStyleProps,
|
|
22
54
|
containerStyle,
|
|
23
55
|
initialIndex = 0,
|
|
24
|
-
|
|
25
|
-
|
|
56
|
+
pageSpacing = 0,
|
|
57
|
+
windowSize = 3,
|
|
26
58
|
enableLoop = false,
|
|
27
59
|
...props
|
|
28
60
|
}) {
|
|
29
|
-
const Component = ListComponent;
|
|
30
|
-
const dataRef = useRef(data);
|
|
31
61
|
const {
|
|
32
62
|
width: screenWidth,
|
|
33
63
|
height: screenHeight
|
|
34
64
|
} = useWindowDimensions();
|
|
35
65
|
const width = customWidth || screenWidth;
|
|
36
66
|
const height = customHeight || screenHeight;
|
|
37
|
-
const loopData = useMemo(() => createLoopData(dataRef, enableLoop), [enableLoop]);
|
|
38
|
-
const isScrollView = isScrollViewLike(Component);
|
|
39
|
-
const isFlashList = isFlashListLike(Component);
|
|
40
67
|
const {
|
|
41
|
-
activeListIndex,
|
|
42
|
-
listRef,
|
|
43
|
-
isZoomed,
|
|
44
|
-
isRotated,
|
|
45
|
-
isPinching,
|
|
46
|
-
dismissGesture,
|
|
47
|
-
zoomGesture,
|
|
48
|
-
nativeScrollGesture,
|
|
49
|
-
onWebClick,
|
|
50
|
-
onMomentumScrollEnd,
|
|
51
|
-
onScroll,
|
|
52
|
-
onScrollBeginDrag,
|
|
53
68
|
animatedStyle,
|
|
54
69
|
backdropStyle,
|
|
55
|
-
|
|
70
|
+
centerVirtualIndex,
|
|
71
|
+
dismissGesture,
|
|
72
|
+
handleDismiss,
|
|
73
|
+
horizontalPagingGesture,
|
|
74
|
+
onWebClick,
|
|
75
|
+
pageStride,
|
|
76
|
+
renderWindowSlots,
|
|
77
|
+
visualPage,
|
|
78
|
+
zoomGesture,
|
|
79
|
+
zoomPinchGesture
|
|
56
80
|
} = useGestureViewer({
|
|
57
81
|
id,
|
|
58
82
|
data,
|
|
59
83
|
width,
|
|
60
84
|
height,
|
|
61
85
|
initialIndex,
|
|
62
|
-
|
|
86
|
+
pageSpacing,
|
|
87
|
+
windowSize,
|
|
63
88
|
enableLoop,
|
|
64
89
|
...props
|
|
65
90
|
});
|
|
66
|
-
const keyExtractor = useCallback((item, index) => {
|
|
67
|
-
if (enableLoop) {
|
|
68
|
-
return typeof item === 'string' ? `${item}-${index}` : `item-${index}`;
|
|
69
|
-
}
|
|
70
|
-
return typeof item === 'string' ? item : `image-${index}`;
|
|
71
|
-
}, [enableLoop]);
|
|
72
|
-
const renderItem = useCallback(({
|
|
73
|
-
item,
|
|
74
|
-
index,
|
|
75
|
-
target
|
|
76
|
-
}) => {
|
|
77
|
-
const isFlashListCell = !isFlashList || target === undefined || target === 'Cell';
|
|
78
|
-
return /*#__PURE__*/_jsx(View, {
|
|
79
|
-
style: [{
|
|
80
|
-
width,
|
|
81
|
-
height,
|
|
82
|
-
marginHorizontal: itemSpacing / 2
|
|
83
|
-
}, styles.item],
|
|
84
|
-
children: renderItemProp(item, index, {
|
|
85
|
-
isActive: index === activeListIndex && isFlashListCell
|
|
86
|
-
})
|
|
87
|
-
}, isScrollView ? keyExtractor(item, index) : undefined);
|
|
88
|
-
}, [activeListIndex, width, itemSpacing, renderItemProp, keyExtractor, isScrollView, isFlashList, height]);
|
|
89
|
-
const getItemLayout = useCallback((_, index) => ({
|
|
90
|
-
length: width + itemSpacing,
|
|
91
|
-
offset: (width + itemSpacing) * index,
|
|
92
|
-
index
|
|
93
|
-
}), [width, itemSpacing]);
|
|
94
91
|
const gesture = useMemo(() => {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
return composeGestureViewerGestures({
|
|
93
|
+
dismissGesture,
|
|
94
|
+
horizontalPagingGesture,
|
|
95
|
+
zoomGesture,
|
|
96
|
+
zoomPinchGesture
|
|
97
|
+
});
|
|
98
|
+
}, [dismissGesture, horizontalPagingGesture, zoomGesture, zoomPinchGesture]);
|
|
100
99
|
useEffect(() => {
|
|
101
100
|
registry.createManager(id);
|
|
102
101
|
return () => registry.deleteManager(id);
|
|
103
102
|
}, [id]);
|
|
104
|
-
const commonProps = useMemo(() => ({
|
|
105
|
-
horizontal: true,
|
|
106
|
-
scrollEnabled: !isZoomed && !isRotated && !isPinching,
|
|
107
|
-
showsHorizontalScrollIndicator: false,
|
|
108
|
-
onMomentumScrollEnd,
|
|
109
|
-
onScroll,
|
|
110
|
-
onScrollBeginDrag,
|
|
111
|
-
...(enableSnapMode ? {
|
|
112
|
-
snapToInterval: width + itemSpacing,
|
|
113
|
-
snapToAlignment: 'center',
|
|
114
|
-
decelerationRate: 'fast'
|
|
115
|
-
} : {
|
|
116
|
-
pagingEnabled: true
|
|
117
|
-
}),
|
|
118
|
-
scrollEventThrottle: 16,
|
|
119
|
-
removeClippedSubviews: true
|
|
120
|
-
}), [width, itemSpacing, isZoomed, isRotated, isPinching, onMomentumScrollEnd, onScroll, onScrollBeginDrag, enableSnapMode]);
|
|
121
103
|
const control = useMemo(() => ({
|
|
122
104
|
dismiss: handleDismiss
|
|
123
105
|
}), [handleDismiss]);
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
if (!shouldWrapScrollableWithNativeGesture) {
|
|
127
|
-
return children;
|
|
128
|
-
}
|
|
129
|
-
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
130
|
-
gesture: nativeScrollGesture,
|
|
131
|
-
children: children
|
|
132
|
-
});
|
|
133
|
-
}, [nativeScrollGesture, shouldWrapScrollableWithNativeGesture]);
|
|
134
|
-
const listComponent = /*#__PURE__*/_jsx(GestureHandlerRootView, {
|
|
106
|
+
const webContentProps = getWebContentProps(onWebClick);
|
|
107
|
+
const viewer = /*#__PURE__*/_jsx(GestureHandlerRootView, {
|
|
135
108
|
children: /*#__PURE__*/_jsx(GestureDetector, {
|
|
136
109
|
gesture: gesture,
|
|
137
110
|
children: /*#__PURE__*/_jsxs(View, {
|
|
138
|
-
style: [{
|
|
139
|
-
|
|
140
|
-
|
|
111
|
+
style: [styles.container, {
|
|
112
|
+
height,
|
|
113
|
+
width
|
|
141
114
|
}, containerStyle],
|
|
142
115
|
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
143
116
|
style: [styles.background, backdropStyleProps, backdropStyle]
|
|
144
117
|
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
145
|
-
style:
|
|
146
|
-
...
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
}),
|
|
154
|
-
children: isScrollView ? maybeWrapWithNativeScrollGesture(/*#__PURE__*/_jsx(Component, {
|
|
155
|
-
ref: listRef,
|
|
156
|
-
...commonProps,
|
|
157
|
-
...listProps,
|
|
158
|
-
children: loopData.map((item, index) => renderItem({
|
|
159
|
-
item,
|
|
160
|
-
index
|
|
161
|
-
}))
|
|
162
|
-
})) : isFlatListLike(Component) && maybeWrapWithNativeScrollGesture(/*#__PURE__*/_jsx(Component, {
|
|
163
|
-
ref: listRef,
|
|
164
|
-
...commonProps,
|
|
165
|
-
data: loopData,
|
|
118
|
+
style: styles.content,
|
|
119
|
+
...webContentProps,
|
|
120
|
+
children: renderWindowSlots.map(slot => /*#__PURE__*/_jsx(RenderWindowSlotView, {
|
|
121
|
+
animatedStyle: animatedStyle,
|
|
122
|
+
height: height,
|
|
123
|
+
isActive: slot.virtualIndex === centerVirtualIndex,
|
|
124
|
+
pageStride: pageStride,
|
|
166
125
|
renderItem: renderItem,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
{
|
|
172
|
-
estimatedItemSize: width + itemSpacing
|
|
173
|
-
} : {
|
|
174
|
-
windowSize: 3,
|
|
175
|
-
maxToRenderPerBatch: 3,
|
|
176
|
-
getItemLayout
|
|
177
|
-
}),
|
|
178
|
-
...(Platform.OS === 'web' && isFlatListLike(Component) && {
|
|
179
|
-
dataSet: {
|
|
180
|
-
'flat-list-paging-enabled-fix': true
|
|
181
|
-
}
|
|
182
|
-
}),
|
|
183
|
-
...listProps
|
|
184
|
-
}))
|
|
185
|
-
}), /*#__PURE__*/_jsx(WebPagingFixStyle, {
|
|
186
|
-
Component: Component
|
|
126
|
+
slot: slot,
|
|
127
|
+
visualPage: visualPage,
|
|
128
|
+
width: width
|
|
129
|
+
}, slot.slotKey))
|
|
187
130
|
})]
|
|
188
131
|
})
|
|
189
132
|
})
|
|
190
133
|
});
|
|
191
|
-
return renderContainer ? renderContainer(
|
|
134
|
+
return renderContainer ? renderContainer(viewer, control) : viewer;
|
|
192
135
|
}
|
|
193
136
|
const styles = StyleSheet.create({
|
|
137
|
+
background: {
|
|
138
|
+
...StyleSheet.absoluteFill,
|
|
139
|
+
backgroundColor: '#000'
|
|
140
|
+
},
|
|
141
|
+
container: {
|
|
142
|
+
overflow: 'hidden'
|
|
143
|
+
},
|
|
194
144
|
content: {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
height: '100%'
|
|
145
|
+
...StyleSheet.absoluteFill,
|
|
146
|
+
overflow: 'hidden'
|
|
198
147
|
},
|
|
199
148
|
item: {
|
|
200
|
-
|
|
201
|
-
|
|
149
|
+
alignItems: 'center',
|
|
150
|
+
justifyContent: 'center'
|
|
202
151
|
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
152
|
+
page: {
|
|
153
|
+
flex: 1
|
|
154
|
+
},
|
|
155
|
+
slot: {
|
|
206
156
|
left: 0,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
backgroundColor: 'black'
|
|
157
|
+
position: 'absolute',
|
|
158
|
+
top: 0
|
|
210
159
|
}
|
|
211
160
|
});
|
|
212
161
|
//# sourceMappingURL=GestureViewer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","StyleSheet","useWindowDimensions","View","GestureDetector","GestureHandlerRootView","Animated","useAnimatedStyle","composeGestureViewerGestures","registry","getWebContentProps","useGestureViewer","jsx","_jsx","jsxs","_jsxs","RenderWindowSlotView","animatedStyle","height","isActive","pageStride","renderItem","slot","visualPage","width","slotAnimatedStyle","transform","translateX","virtualIndex","get","style","styles","children","page","item","logicalIndex","GestureViewer","id","data","renderContainer","customWidth","customHeight","backdropStyle","backdropStyleProps","containerStyle","initialIndex","pageSpacing","windowSize","enableLoop","props","screenWidth","screenHeight","centerVirtualIndex","dismissGesture","handleDismiss","horizontalPagingGesture","onWebClick","renderWindowSlots","zoomGesture","zoomPinchGesture","gesture","createManager","deleteManager","control","dismiss","webContentProps","viewer","container","background","content","map","slotKey","create","absoluteFill","backgroundColor","overflow","alignItems","justifyContent","flex","left","position","top"],"sourceRoot":"../../src","sources":["GestureViewer.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAC1C,SAASC,UAAU,EAAEC,mBAAmB,EAAEC,IAAI,QAAwB,cAAc;AACpF,SAASC,eAAe,EAAEC,sBAAsB,QAAQ,8BAA8B;AACtF,OAAOC,QAAQ,IAGbC,gBAAgB,QACX,yBAAyB;AAEhC,SAASC,4BAA4B,QAAQ,4BAAyB;AACtE,SAASC,QAAQ,QAAQ,4BAAyB;AAClD,SAASC,kBAAkB,QAAQ,sBAAsB;AAGzD,SAASC,gBAAgB,QAAQ,uBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAatD,SAASC,oBAAoBA,CAAQ;EACnCC,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6C,IAAI,EAAE;EACR,CAAC;EACDxD,IAAI,EAAE;IACJyD,IAAI,EAAE,CAAC;IACPC,QAAQ,EAAE,UAAU;IACpBC,GAAG,EAAE;EACP;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { withTiming } from 'react-native-reanimated';
|
|
4
|
-
import { createBoundsConstraint
|
|
4
|
+
import { createBoundsConstraint } from "./utils/index.js";
|
|
5
|
+
const DEFAULT_STATE_READER = () => ({
|
|
6
|
+
currentIndex: 0,
|
|
7
|
+
totalCount: 0
|
|
8
|
+
});
|
|
5
9
|
class GestureViewerManager {
|
|
6
|
-
currentIndex = 0;
|
|
7
|
-
dataLength = 0;
|
|
8
10
|
width = 0;
|
|
9
11
|
height = 0;
|
|
10
12
|
maxZoomScale = 2;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
listRef = null;
|
|
13
|
+
navigationAdapter = null;
|
|
14
|
+
stateReader = DEFAULT_STATE_READER;
|
|
14
15
|
scale = null;
|
|
15
16
|
rotation = null;
|
|
16
17
|
translateX = null;
|
|
17
18
|
translateY = null;
|
|
18
|
-
resetTransformCallback = null;
|
|
19
|
-
loopCallback = null;
|
|
20
|
-
programmaticScrollVersion = 0;
|
|
21
19
|
listeners = new Set();
|
|
22
20
|
eventListeners = new Map();
|
|
21
|
+
eventListenerPresenceSubscribers = new Set();
|
|
23
22
|
notifyListeners() {
|
|
24
23
|
const state = this.getState();
|
|
25
24
|
this.listeners.forEach(listener => listener(state));
|
|
@@ -35,6 +34,7 @@ class GestureViewerManager {
|
|
|
35
34
|
this.eventListeners.set(eventType, new Set());
|
|
36
35
|
}
|
|
37
36
|
this.eventListeners.get(eventType)?.add(callback);
|
|
37
|
+
this.notifyEventListenerPresence(eventType);
|
|
38
38
|
return () => {
|
|
39
39
|
const listeners = this.eventListeners.get(eventType);
|
|
40
40
|
if (listeners) {
|
|
@@ -43,8 +43,29 @@ class GestureViewerManager {
|
|
|
43
43
|
this.eventListeners.delete(eventType);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
this.notifyEventListenerPresence(eventType);
|
|
46
47
|
};
|
|
47
48
|
}
|
|
49
|
+
subscribeToEventListenerPresence(callback) {
|
|
50
|
+
this.eventListenerPresenceSubscribers.add(callback);
|
|
51
|
+
this.notifyEventListenerPresenceSubscriber(callback, 'zoomChange');
|
|
52
|
+
this.notifyEventListenerPresenceSubscriber(callback, 'rotationChange');
|
|
53
|
+
this.notifyEventListenerPresenceSubscriber(callback, 'tap');
|
|
54
|
+
return () => {
|
|
55
|
+
this.eventListenerPresenceSubscribers.delete(callback);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
hasEventListeners(eventType) {
|
|
59
|
+
return (this.eventListeners.get(eventType)?.size ?? 0) > 0;
|
|
60
|
+
}
|
|
61
|
+
notifyEventListenerPresence(eventType) {
|
|
62
|
+
this.eventListenerPresenceSubscribers.forEach(callback => {
|
|
63
|
+
this.notifyEventListenerPresenceSubscriber(callback, eventType);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
notifyEventListenerPresenceSubscriber(callback, eventType) {
|
|
67
|
+
callback(eventType, this.hasEventListeners(eventType));
|
|
68
|
+
}
|
|
48
69
|
emitEvent(eventType, data) {
|
|
49
70
|
const listeners = this.eventListeners.get(eventType);
|
|
50
71
|
if (listeners) {
|
|
@@ -67,16 +88,7 @@ class GestureViewerManager {
|
|
|
67
88
|
this.emitEvent('tap', data);
|
|
68
89
|
};
|
|
69
90
|
getState() {
|
|
70
|
-
return
|
|
71
|
-
currentIndex: this.currentIndex,
|
|
72
|
-
totalCount: this.dataLength
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
getProgrammaticScrollVersion() {
|
|
76
|
-
return this.programmaticScrollVersion;
|
|
77
|
-
}
|
|
78
|
-
setEnableLoop(enabled) {
|
|
79
|
-
this.enableLoop = enabled;
|
|
91
|
+
return this.stateReader();
|
|
80
92
|
}
|
|
81
93
|
setWidth(width) {
|
|
82
94
|
this.width = width;
|
|
@@ -84,19 +96,11 @@ class GestureViewerManager {
|
|
|
84
96
|
setHeight(height) {
|
|
85
97
|
this.height = height;
|
|
86
98
|
}
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
}
|
|
90
|
-
setDataLength(length) {
|
|
91
|
-
this.dataLength = length;
|
|
92
|
-
}
|
|
93
|
-
setEnableHorizontalSwipe(enabled) {
|
|
94
|
-
this.enableHorizontalSwipe = enabled;
|
|
99
|
+
setNavigationAdapter(adapter) {
|
|
100
|
+
this.navigationAdapter = adapter;
|
|
95
101
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.currentIndex = index;
|
|
99
|
-
}
|
|
102
|
+
setStateReader(reader) {
|
|
103
|
+
this.stateReader = reader ?? DEFAULT_STATE_READER;
|
|
100
104
|
}
|
|
101
105
|
setZoomSharedValues(scale, translateX, translateY, maxZoomScale) {
|
|
102
106
|
this.scale = scale;
|
|
@@ -104,9 +108,6 @@ class GestureViewerManager {
|
|
|
104
108
|
this.translateY = translateY;
|
|
105
109
|
this.maxZoomScale = maxZoomScale;
|
|
106
110
|
}
|
|
107
|
-
setResetTransformCallback(callback) {
|
|
108
|
-
this.resetTransformCallback = callback;
|
|
109
|
-
}
|
|
110
111
|
notifyStateChange() {
|
|
111
112
|
this.notifyListeners();
|
|
112
113
|
}
|
|
@@ -184,93 +185,36 @@ class GestureViewerManager {
|
|
|
184
185
|
this.translateX.set(withTiming(0));
|
|
185
186
|
this.translateY.set(withTiming(0));
|
|
186
187
|
};
|
|
187
|
-
goToIndex = index => {
|
|
188
|
-
if (!this.
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this.cancelPendingLoopTransition();
|
|
192
|
-
const {
|
|
193
|
-
scrollTo
|
|
194
|
-
} = createScrollAction(this.listRef, this.width);
|
|
195
|
-
if (this.enableLoop && this.dataLength > 1) {
|
|
196
|
-
if (index < 0) {
|
|
197
|
-
this.loopCallback = () => {
|
|
198
|
-
scrollTo(this.dataLength, false);
|
|
199
|
-
this.updateCurrentIndex(this.dataLength - 1);
|
|
200
|
-
this.cancelPendingLoopTransition();
|
|
201
|
-
};
|
|
202
|
-
this.resetTransformCallback?.();
|
|
203
|
-
this.programmaticScrollVersion += 1;
|
|
204
|
-
scrollTo(0, true);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (index >= this.dataLength) {
|
|
208
|
-
this.loopCallback = () => {
|
|
209
|
-
scrollTo(1, false);
|
|
210
|
-
this.updateCurrentIndex(0);
|
|
211
|
-
this.cancelPendingLoopTransition();
|
|
212
|
-
};
|
|
213
|
-
this.resetTransformCallback?.();
|
|
214
|
-
this.programmaticScrollVersion += 1;
|
|
215
|
-
scrollTo(this.dataLength + 1, true);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
this.resetTransformCallback?.();
|
|
219
|
-
this.programmaticScrollVersion += 1;
|
|
220
|
-
scrollTo(index + 1, true);
|
|
221
|
-
this.updateCurrentIndex(index);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (index < 0 || index >= this.dataLength) {
|
|
188
|
+
goToIndex = (index, options) => {
|
|
189
|
+
if (!this.navigationAdapter) {
|
|
225
190
|
return;
|
|
226
191
|
}
|
|
227
|
-
this.
|
|
228
|
-
this.programmaticScrollVersion += 1;
|
|
229
|
-
scrollTo(index, true);
|
|
230
|
-
this.updateCurrentIndex(index);
|
|
231
|
-
};
|
|
232
|
-
handleMomentumScrollEnd = scrollIndex => {
|
|
233
|
-
if (!this.loopCallback) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
if (scrollIndex === 0 || scrollIndex === this.dataLength + 1) {
|
|
237
|
-
this.loopCallback();
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
this.cancelPendingLoopTransition();
|
|
241
|
-
return true;
|
|
242
|
-
};
|
|
243
|
-
cancelPendingLoopTransition = () => {
|
|
244
|
-
this.loopCallback = null;
|
|
245
|
-
};
|
|
246
|
-
handleScrollBeginDrag = () => {
|
|
247
|
-
this.cancelPendingLoopTransition();
|
|
192
|
+
this.navigationAdapter.goToIndex(index, options);
|
|
248
193
|
};
|
|
249
194
|
goToPrevious = () => {
|
|
250
|
-
|
|
195
|
+
if (!this.navigationAdapter) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.navigationAdapter.goToPrevious();
|
|
251
199
|
};
|
|
252
200
|
goToNext = () => {
|
|
253
|
-
|
|
201
|
+
if (!this.navigationAdapter) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.navigationAdapter.goToNext();
|
|
254
205
|
};
|
|
255
206
|
cleanUp() {
|
|
256
|
-
this.cancelPendingLoopTransition();
|
|
257
207
|
this.listeners.clear();
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.currentIndex = 0;
|
|
261
|
-
this.dataLength = 0;
|
|
208
|
+
this.navigationAdapter = null;
|
|
209
|
+
this.stateReader = DEFAULT_STATE_READER;
|
|
262
210
|
this.maxZoomScale = 2;
|
|
263
211
|
this.scale = null;
|
|
264
212
|
this.translateX = null;
|
|
265
213
|
this.translateY = null;
|
|
266
214
|
this.rotation = null;
|
|
267
|
-
this.resetTransformCallback = null;
|
|
268
215
|
this.eventListeners.clear();
|
|
216
|
+
this.eventListenerPresenceSubscribers.clear();
|
|
269
217
|
}
|
|
270
|
-
updateCurrentIndex = targetIndex => {
|
|
271
|
-
this.currentIndex = targetIndex;
|
|
272
|
-
this.notifyListeners();
|
|
273
|
-
};
|
|
274
218
|
}
|
|
275
219
|
export default GestureViewerManager;
|
|
276
220
|
//# sourceMappingURL=GestureViewerManager.js.map
|