react-native-gesture-image-viewer 1.3.0 → 1.4.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.
@@ -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
- * @default 'default'
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
- * @default 0
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
- * @default screen width
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
- * @default false
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
- * @default 80
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
- * @default true
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
- * @default true
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
- * @default 2
83
+ * @defaultValue 2
84
84
  */
85
85
  resistance?: number;
86
86
  /**
@@ -99,38 +99,167 @@ 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
- * @default true
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
- * @default true
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
- * @default true
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
- * @default true
120
+ * @defaultValue true
121
121
  */
122
122
  enableDoubleTapGesture?: boolean;
123
123
  /**
124
124
  * The maximum zoom scale.
125
- * @default 2
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
- * @default 0
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
+ };
135
264
  export {};
136
265
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":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IAEtC;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvC;;;;;;;;;;;OAWG;IACH,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9D,GAAG,4BAA4B,CAAC;AAEjC;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC"}
@@ -7,6 +7,7 @@ export declare const useGestureViewer: <T = any>({ data, initialIndex, onIndexCh
7
7
  translateY: import("react-native-reanimated").SharedValue<number>;
8
8
  listRef: import("react").RefObject<any>;
9
9
  isZoomed: boolean;
10
+ isRotated: boolean;
10
11
  dismissGesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
11
12
  zoomGesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/gestureComposition").ComposedGesture;
12
13
  onMomentumScrollEnd: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
@@ -15,14 +16,22 @@ export declare const useGestureViewer: <T = any>({ data, initialIndex, onIndexCh
15
16
  translateY: number;
16
17
  translateX?: undefined;
17
18
  scale?: undefined;
19
+ rotate?: undefined;
18
20
  } | {
19
21
  translateX: number;
20
22
  translateY?: undefined;
21
23
  scale?: undefined;
24
+ rotate?: undefined;
22
25
  } | {
23
26
  scale: number;
24
27
  translateY?: undefined;
25
28
  translateX?: undefined;
29
+ rotate?: undefined;
30
+ } | {
31
+ rotate: string;
32
+ translateY?: undefined;
33
+ translateX?: undefined;
34
+ scale?: undefined;
26
35
  })[];
27
36
  };
28
37
  backdropStyle: {
@@ -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;;;;;;;;iCAmIf,oBAAoB,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;CAqQlD,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;;;;;;;;;iCA8If,oBAAoB,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4QlD,CAAC"}
@@ -1,11 +1,55 @@
1
- export declare const useGestureViewerController: (id?: string) => {
2
- goToIndex: (index: number) => void;
3
- goToPrevious: () => void;
4
- goToNext: () => void;
5
- zoomIn: (multiplier?: number) => void;
6
- zoomOut: (multiplier?: number) => void;
7
- resetZoom: (scale?: number) => void;
8
- currentIndex: number;
9
- totalCount: number;
10
- };
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;
11
55
  //# sourceMappingURL=useGestureViewerController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGestureViewerController.d.ts","sourceRoot":"","sources":["../../../src/useGestureViewerController.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,0BAA0B,GAAI,WAAc;;;;;;;;;CA6CxD,CAAC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gesture-image-viewer",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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",
@@ -29,16 +29,24 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
29
29
 
30
30
  const width = useSnap ? customWidth || screenWidth : screenWidth;
31
31
 
32
- const { listRef, isZoomed, dismissGesture, zoomGesture, onMomentumScrollEnd, animatedStyle, backdropStyle } =
33
- useGestureViewer({
34
- id,
35
- data,
36
- width,
37
- initialIndex,
38
- itemSpacing,
39
- useSnap,
40
- ...props,
41
- });
32
+ const {
33
+ listRef,
34
+ isZoomed,
35
+ isRotated,
36
+ dismissGesture,
37
+ zoomGesture,
38
+ onMomentumScrollEnd,
39
+ animatedStyle,
40
+ backdropStyle,
41
+ } = useGestureViewer({
42
+ id,
43
+ data,
44
+ width,
45
+ initialIndex,
46
+ itemSpacing,
47
+ useSnap,
48
+ ...props,
49
+ });
42
50
 
43
51
  const renderItem = useCallback(
44
52
  ({ item, index }: { item: T; index: number }) => {
@@ -89,7 +97,7 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
89
97
  const commonProps: ScrollViewProps = useMemo(
90
98
  () => ({
91
99
  horizontal: true,
92
- scrollEnabled: !isZoomed,
100
+ scrollEnabled: !isZoomed && !isRotated,
93
101
  showsHorizontalScrollIndicator: false,
94
102
  onMomentumScrollEnd: onMomentumScrollEnd,
95
103
  ...(useSnap
@@ -104,7 +112,7 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
104
112
  scrollEventThrottle: 16,
105
113
  removeClippedSubviews: true,
106
114
  }),
107
- [width, itemSpacing, isZoomed, onMomentumScrollEnd, useSnap],
115
+ [width, itemSpacing, isZoomed, isRotated, onMomentumScrollEnd, useSnap],
108
116
  );
109
117
 
110
118
  const listComponent = (
@@ -1,11 +1,7 @@
1
1
  import { type SharedValue, withTiming } from 'react-native-reanimated';
2
+ import type { GestureViewerControllerState } from './types';
2
3
  import { createBoundsConstraint } from './utils';
3
4
 
4
- export type GestureViewerManagerState = {
5
- currentIndex: number;
6
- dataLength: number;
7
- };
8
-
9
5
  class GestureViewerManager {
10
6
  private currentIndex = 0;
11
7
  private dataLength = 0;
@@ -17,7 +13,8 @@ class GestureViewerManager {
17
13
  private maxZoomScale = 2;
18
14
  private listRef: any | null = null;
19
15
  private enableSwipeGesture = true;
20
- private listeners = new Set<(state: GestureViewerManagerState) => void>();
16
+ private listeners = new Set<(state: GestureViewerControllerState) => void>();
17
+ private rotation: SharedValue<number> | null = null;
21
18
 
22
19
  private notifyListeners() {
23
20
  const state = this.getState();
@@ -25,7 +22,7 @@ class GestureViewerManager {
25
22
  this.listeners.forEach((listener) => listener(state));
26
23
  }
27
24
 
28
- subscribe(listener: (state: GestureViewerManagerState) => void) {
25
+ subscribe(listener: (state: GestureViewerControllerState) => void) {
29
26
  this.listeners.add(listener);
30
27
 
31
28
  return () => {
@@ -36,7 +33,7 @@ class GestureViewerManager {
36
33
  getState() {
37
34
  return {
38
35
  currentIndex: this.currentIndex,
39
- dataLength: this.dataLength,
36
+ totalCount: this.dataLength,
40
37
  };
41
38
  }
42
39
 
@@ -82,11 +79,39 @@ class GestureViewerManager {
82
79
  this.notifyListeners();
83
80
  }
84
81
 
85
- /**
86
- * @param multiplier - The multiplier to zoom in.
87
- * @range 0.01 - 1
88
- * @default 0.25
89
- */
82
+ setRotation(rotation: SharedValue<number>) {
83
+ this.rotation = rotation;
84
+ }
85
+
86
+ rotate = (angle: 0 | 90 | 180 | 270 | 360 = 90, clockwise = true) => {
87
+ const MAX_ANGLE = 360;
88
+
89
+ if (
90
+ !this.rotation ||
91
+ angle < 0 ||
92
+ angle > MAX_ANGLE ||
93
+ (angle !== 0 && this.rotation.value % angle !== 0 && angle !== 360)
94
+ ) {
95
+ return;
96
+ }
97
+
98
+ if (angle === 0) {
99
+ const nextAngle = Math.floor(this.rotation.value / MAX_ANGLE) * MAX_ANGLE;
100
+
101
+ this.rotation.value = withTiming(clockwise ? nextAngle : nextAngle - MAX_ANGLE);
102
+ return;
103
+ }
104
+
105
+ if (angle === 360) {
106
+ this.rotation.value = withTiming(clockwise ? this.rotation.value + MAX_ANGLE : this.rotation.value - MAX_ANGLE);
107
+ return;
108
+ }
109
+
110
+ const nextAngle = clockwise ? this.rotation.value + angle : this.rotation.value - angle;
111
+
112
+ this.rotation.value = withTiming(nextAngle);
113
+ };
114
+
90
115
  zoomIn = (multiplier = 0.25) => {
91
116
  if (!this.scale || !this.translateX || !this.translateY || multiplier < 0.01 || multiplier > 1) {
92
117
  return;
@@ -109,11 +134,6 @@ class GestureViewerManager {
109
134
  this.translateY.value = withTiming(translateY);
110
135
  };
111
136
 
112
- /**
113
- * @param multiplier - The multiplier to zoom out.
114
- * @range 0.01 - 1
115
- * @default 0.25
116
- */
117
137
  zoomOut = (multiplier = 0.25) => {
118
138
  if (!this.scale || !this.translateX || !this.translateY || multiplier < 0.01 || multiplier > 1) {
119
139
  return;
@@ -142,10 +162,6 @@ class GestureViewerManager {
142
162
  this.translateY.value = withTiming(translateY);
143
163
  };
144
164
 
145
- /**
146
- * @param scale - The scale to reset to.
147
- * @default 1
148
- */
149
165
  resetZoom = (scale = 1) => {
150
166
  if (!this.scale || !this.translateX || !this.translateY || scale <= 0 || scale > this.maxZoomScale) {
151
167
  return;
@@ -195,6 +211,7 @@ class GestureViewerManager {
195
211
  this.scale = null;
196
212
  this.translateX = null;
197
213
  this.translateY = null;
214
+ this.rotation = null;
198
215
  }
199
216
  }
200
217
 
package/src/index.tsx CHANGED
@@ -1,3 +1,3 @@
1
1
  export { GestureViewer } from './GestureViewer';
2
- export type { GestureViewerProps } from './types';
2
+ export type { GestureViewerController, GestureViewerProps } from './types';
3
3
  export { useGestureViewerController } from './useGestureViewerController';