react-native-gesture-image-viewer 0.1.0 → 0.3.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/lib/module/GestureImageViewer.js +25 -10
- package/lib/module/GestureImageViewer.js.map +1 -1
- package/lib/module/ImageViewerManager.js +78 -0
- package/lib/module/ImageViewerManager.js.map +1 -0
- package/lib/module/ImageViewerRegistry.js +26 -0
- package/lib/module/ImageViewerRegistry.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useGestureImageViewer.js +138 -59
- package/lib/module/useGestureImageViewer.js.map +1 -1
- package/lib/module/useImageViewerController.js +28 -0
- package/lib/module/useImageViewerController.js.map +1 -0
- package/lib/typescript/src/GestureImageViewer.d.ts +1 -1
- package/lib/typescript/src/GestureImageViewer.d.ts.map +1 -1
- package/lib/typescript/src/ImageViewerManager.d.ts +28 -0
- package/lib/typescript/src/ImageViewerManager.d.ts.map +1 -0
- package/lib/typescript/src/ImageViewerRegistry.d.ts +10 -0
- package/lib/typescript/src/ImageViewerRegistry.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +5 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useGestureImageViewer.d.ts +16 -7
- package/lib/typescript/src/useGestureImageViewer.d.ts.map +1 -1
- package/lib/typescript/src/useImageViewerController.d.ts +8 -0
- package/lib/typescript/src/useImageViewerController.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/GestureImageViewer.tsx +42 -14
- package/src/ImageViewerManager.ts +92 -0
- package/src/ImageViewerRegistry.ts +30 -0
- package/src/index.tsx +1 -0
- package/src/types.ts +5 -0
- package/src/useGestureImageViewer.ts +210 -62
- package/src/useImageViewerController.ts +34 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
2
|
import type { SharedValue } from 'react-native-reanimated';
|
|
3
3
|
export interface GestureImageViewerProps<T = any> {
|
|
4
|
+
id?: string;
|
|
4
5
|
data: T[];
|
|
5
6
|
initialIndex?: number;
|
|
6
7
|
onIndexChange?: (index: number) => void;
|
|
@@ -19,6 +20,10 @@ export interface GestureImageViewerProps<T = any> {
|
|
|
19
20
|
backdropStyle?: StyleProp<ViewStyle>;
|
|
20
21
|
containerStyle?: StyleProp<ViewStyle>;
|
|
21
22
|
animateBackdrop?: boolean;
|
|
23
|
+
enableZoomPanGesture?: boolean;
|
|
24
|
+
enableZoomGesture?: boolean;
|
|
25
|
+
enableDoubleTapGesture?: boolean;
|
|
26
|
+
maxZoomScale?: number;
|
|
22
27
|
}
|
|
23
28
|
export interface GestureState {
|
|
24
29
|
currentIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,GAAG;IAC9C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,YAAY,CAAC;IAC5D,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY,CAAC;IACvE,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,GAAG;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,YAAY,CAAC;IAC5D,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY,CAAC;IACvE,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,YAAY,GAAG,UAAU,GAAG,IAAI,CAAC;CACjD"}
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { type NativeScrollEvent, type NativeSyntheticEvent } from 'react-native';
|
|
2
2
|
import type { GestureImageViewerProps } from './types';
|
|
3
3
|
type UseGestureImageViewerProps<T = any> = Omit<GestureImageViewerProps<T>, 'renderImage' | 'renderContainer' | 'ListComponent' | 'listProps' | 'containerStyle' | 'backdropStyle'>;
|
|
4
|
-
export declare const useGestureImageViewer: <T = any>({ data, initialIndex, onIndexChange, onDismiss, width: customWidth, dismissThreshold, resistance, animateBackdrop, enableDismissGesture, enableSwipeGesture, }: UseGestureImageViewerProps<T>) => {
|
|
4
|
+
export declare const useGestureImageViewer: <T = any>({ data, initialIndex, onIndexChange, onDismiss, width: customWidth, dismissThreshold, resistance, animateBackdrop, enableDismissGesture, enableSwipeGesture, enableZoomGesture, enableDoubleTapGesture, enableZoomPanGesture, maxZoomScale, id, }: UseGestureImageViewerProps<T>) => {
|
|
5
5
|
currentIndex: number;
|
|
6
6
|
dataLength: number;
|
|
7
7
|
translateY: import("react-native-reanimated").SharedValue<number>;
|
|
8
8
|
flatListRef: import("react").RefObject<any>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
panGesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
|
|
9
|
+
isZoomed: boolean;
|
|
10
|
+
dismissGesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
|
|
11
|
+
zoomGesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/gestureComposition").SimultaneousGesture;
|
|
13
12
|
onMomentumScrollEnd: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
14
13
|
animatedStyle: {
|
|
15
|
-
transform: {
|
|
14
|
+
transform: ({
|
|
16
15
|
translateY: number;
|
|
17
|
-
|
|
16
|
+
translateX?: undefined;
|
|
17
|
+
scale?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
translateX: number;
|
|
20
|
+
translateY?: undefined;
|
|
21
|
+
scale?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
scale: number;
|
|
24
|
+
translateY?: undefined;
|
|
25
|
+
translateX?: undefined;
|
|
26
|
+
})[];
|
|
18
27
|
};
|
|
19
28
|
backdropStyle: {
|
|
20
29
|
opacity: number;
|
|
@@ -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;
|
|
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;;;;;;;;iCA8FpB,oBAAoB,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;CA0LlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useImageViewerController.d.ts","sourceRoot":"","sources":["../../../src/useImageViewerController.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,GAAI,WAAc;;;;;;CA6BtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { FlatList, Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
4
4
|
import Animated from 'react-native-reanimated';
|
|
5
|
+
import { registry } from './ImageViewerRegistry';
|
|
5
6
|
import type { GestureImageViewerProps } from './types';
|
|
6
7
|
import { useGestureImageViewer } from './useGestureImageViewer';
|
|
7
8
|
|
|
@@ -14,6 +15,7 @@ const WebPagingFix = () => {
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
export function GestureImageViewer<T = any>({
|
|
18
|
+
id = 'default',
|
|
17
19
|
data,
|
|
18
20
|
renderImage,
|
|
19
21
|
renderContainer,
|
|
@@ -29,7 +31,17 @@ export function GestureImageViewer<T = any>({
|
|
|
29
31
|
|
|
30
32
|
const width = customWidth || screenWidth;
|
|
31
33
|
|
|
32
|
-
const {
|
|
34
|
+
const {
|
|
35
|
+
currentIndex,
|
|
36
|
+
flatListRef,
|
|
37
|
+
isZoomed,
|
|
38
|
+
dismissGesture,
|
|
39
|
+
zoomGesture,
|
|
40
|
+
onMomentumScrollEnd,
|
|
41
|
+
animatedStyle,
|
|
42
|
+
backdropStyle,
|
|
43
|
+
} = useGestureImageViewer({
|
|
44
|
+
id,
|
|
33
45
|
data,
|
|
34
46
|
width,
|
|
35
47
|
initialIndex,
|
|
@@ -38,20 +50,25 @@ export function GestureImageViewer<T = any>({
|
|
|
38
50
|
|
|
39
51
|
const renderItem = useCallback(
|
|
40
52
|
({ item, index }: { item: T; index: number }) => {
|
|
53
|
+
const isActive = index === currentIndex;
|
|
54
|
+
|
|
41
55
|
return (
|
|
42
56
|
<Animated.View
|
|
43
|
-
style={
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
style={[
|
|
58
|
+
{
|
|
59
|
+
width,
|
|
60
|
+
height: '100%',
|
|
61
|
+
justifyContent: 'center',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
},
|
|
64
|
+
isActive && animatedStyle,
|
|
65
|
+
]}
|
|
49
66
|
>
|
|
50
67
|
{renderImage(item, index)}
|
|
51
68
|
</Animated.View>
|
|
52
69
|
);
|
|
53
70
|
},
|
|
54
|
-
[width, renderImage],
|
|
71
|
+
[width, renderImage, animatedStyle, currentIndex],
|
|
55
72
|
);
|
|
56
73
|
|
|
57
74
|
const getItemLayout = useCallback(
|
|
@@ -65,12 +82,22 @@ export function GestureImageViewer<T = any>({
|
|
|
65
82
|
|
|
66
83
|
const keyExtractor = useCallback((item: T, index: number) => `image-${index}-${item}`, []);
|
|
67
84
|
|
|
85
|
+
const gesture = useMemo(() => {
|
|
86
|
+
return Gesture.Race(dismissGesture, zoomGesture);
|
|
87
|
+
}, [zoomGesture, dismissGesture]);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
registry.createManager(id);
|
|
91
|
+
|
|
92
|
+
return () => registry.deleteManager(id);
|
|
93
|
+
}, [id]);
|
|
94
|
+
|
|
68
95
|
const listComponent = (
|
|
69
96
|
<GestureHandlerRootView>
|
|
70
|
-
<GestureDetector gesture={
|
|
97
|
+
<GestureDetector gesture={gesture}>
|
|
71
98
|
<View style={[styles.container, containerStyle]}>
|
|
72
99
|
<Animated.View style={[styles.background, backdropStyleProps, backdropStyle]} />
|
|
73
|
-
<
|
|
100
|
+
<View style={styles.content}>
|
|
74
101
|
<ListComponent
|
|
75
102
|
ref={flatListRef}
|
|
76
103
|
data={data}
|
|
@@ -78,6 +105,7 @@ export function GestureImageViewer<T = any>({
|
|
|
78
105
|
keyExtractor={keyExtractor}
|
|
79
106
|
horizontal
|
|
80
107
|
pagingEnabled
|
|
108
|
+
scrollEnabled={!isZoomed}
|
|
81
109
|
showsHorizontalScrollIndicator={false}
|
|
82
110
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
83
111
|
getItemLayout={getItemLayout}
|
|
@@ -89,7 +117,7 @@ export function GestureImageViewer<T = any>({
|
|
|
89
117
|
{...(Platform.OS === 'web' && { dataSet: { 'paging-enabled-fix': true } })}
|
|
90
118
|
{...listProps}
|
|
91
119
|
/>
|
|
92
|
-
</
|
|
120
|
+
</View>
|
|
93
121
|
<WebPagingFix />
|
|
94
122
|
</View>
|
|
95
123
|
</GestureDetector>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type ImageViewerManagerState = {
|
|
2
|
+
currentIndex: number;
|
|
3
|
+
dataLength: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
class ImageViewerManager {
|
|
7
|
+
private currentIndex = 0;
|
|
8
|
+
private dataLength = 0;
|
|
9
|
+
private flatListRef: any = null;
|
|
10
|
+
private enableSwipeGesture = true;
|
|
11
|
+
private listeners = new Set<(state: ImageViewerManagerState) => void>();
|
|
12
|
+
|
|
13
|
+
// private updateState(newState: Partial<any>) {
|
|
14
|
+
// Object.assign(this, newState);
|
|
15
|
+
// this.notifyListeners();
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
private notifyListeners() {
|
|
19
|
+
const state = this.getState();
|
|
20
|
+
|
|
21
|
+
this.listeners.forEach((listener) => listener(state));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
subscribe(listener: (state: ImageViewerManagerState) => void) {
|
|
25
|
+
this.listeners.add(listener);
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
this.listeners.delete(listener);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getState() {
|
|
33
|
+
return {
|
|
34
|
+
currentIndex: this.currentIndex,
|
|
35
|
+
dataLength: this.dataLength,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setFlatListRef(ref: any) {
|
|
40
|
+
this.flatListRef = ref;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setDataLength(length: number) {
|
|
44
|
+
this.dataLength = length;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setEnableSwipeGesture(enabled: boolean) {
|
|
48
|
+
this.enableSwipeGesture = enabled;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setCurrentIndex(index: number) {
|
|
52
|
+
if (index !== this.currentIndex) {
|
|
53
|
+
this.currentIndex = index;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
notifyStateChange() {
|
|
58
|
+
this.notifyListeners();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
goToIndex = (index: number) => {
|
|
62
|
+
if (index < 0 || index >= this.dataLength || !this.enableSwipeGesture || !this.flatListRef) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.currentIndex = index;
|
|
67
|
+
this.flatListRef.scrollToIndex({ index, animated: true });
|
|
68
|
+
this.notifyListeners();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
goToPrevious = () => {
|
|
72
|
+
if (this.currentIndex > 0) {
|
|
73
|
+
this.goToIndex(this.currentIndex - 1);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
goToNext = () => {
|
|
78
|
+
if (this.currentIndex < this.dataLength - 1) {
|
|
79
|
+
this.goToIndex(this.currentIndex + 1);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
cleanUp() {
|
|
84
|
+
this.listeners.clear();
|
|
85
|
+
this.flatListRef = null;
|
|
86
|
+
this.enableSwipeGesture = true;
|
|
87
|
+
this.currentIndex = 0;
|
|
88
|
+
this.dataLength = 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default ImageViewerManager;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ImageViewerManager from './ImageViewerManager';
|
|
2
|
+
|
|
3
|
+
class ImageViewerRegistry {
|
|
4
|
+
private managers = new Map<string, ImageViewerManager>();
|
|
5
|
+
|
|
6
|
+
createManager(id: string): ImageViewerManager | null {
|
|
7
|
+
if (this.managers.has(id)) {
|
|
8
|
+
return this.managers.get(id) || null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const manager = new ImageViewerManager();
|
|
12
|
+
this.managers.set(id, manager);
|
|
13
|
+
return manager;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getManager(id: string): ImageViewerManager | null {
|
|
17
|
+
return this.managers.get(id) || null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
deleteManager(id: string) {
|
|
21
|
+
const manager = this.managers.get(id);
|
|
22
|
+
|
|
23
|
+
if (manager) {
|
|
24
|
+
manager.cleanUp();
|
|
25
|
+
this.managers.delete(id);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const registry = new ImageViewerRegistry();
|
package/src/index.tsx
CHANGED
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { StyleProp, ViewStyle } from 'react-native';
|
|
|
2
2
|
import type { SharedValue } from 'react-native-reanimated';
|
|
3
3
|
|
|
4
4
|
export interface GestureImageViewerProps<T = any> {
|
|
5
|
+
id?: string;
|
|
5
6
|
data: T[];
|
|
6
7
|
initialIndex?: number;
|
|
7
8
|
onIndexChange?: (index: number) => void;
|
|
@@ -20,6 +21,10 @@ export interface GestureImageViewerProps<T = any> {
|
|
|
20
21
|
backdropStyle?: StyleProp<ViewStyle>;
|
|
21
22
|
containerStyle?: StyleProp<ViewStyle>;
|
|
22
23
|
animateBackdrop?: boolean;
|
|
24
|
+
enableZoomPanGesture?: boolean;
|
|
25
|
+
enableZoomGesture?: boolean;
|
|
26
|
+
enableDoubleTapGesture?: boolean;
|
|
27
|
+
maxZoomScale?: number;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export interface GestureState {
|