@gyjshow/react-native-image-viewing 1.0.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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +101 -0
  3. package/dist/@types/index.d.ts +17 -0
  4. package/dist/@types/index.js +8 -0
  5. package/dist/ImageViewing.d.ts +33 -0
  6. package/dist/ImageViewing.js +86 -0
  7. package/dist/components/ImageDefaultHeader.d.ts +13 -0
  8. package/dist/components/ImageDefaultHeader.js +38 -0
  9. package/dist/components/ImageItem/ImageItem.android.d.ts +20 -0
  10. package/dist/components/ImageItem/ImageItem.android.js +83 -0
  11. package/dist/components/ImageItem/ImageItem.ios.d.ts +20 -0
  12. package/dist/components/ImageItem/ImageItem.ios.js +79 -0
  13. package/dist/components/ImageItem/ImageLoading.d.ts +9 -0
  14. package/dist/components/ImageItem/ImageLoading.js +30 -0
  15. package/dist/components/StatusBarManager.d.ts +5 -0
  16. package/dist/components/StatusBarManager.js +14 -0
  17. package/dist/hooks/useAnimatedComponents.d.ts +18 -0
  18. package/dist/hooks/useAnimatedComponents.js +41 -0
  19. package/dist/hooks/useDoubleTapToZoom.d.ts +16 -0
  20. package/dist/hooks/useDoubleTapToZoom.js +49 -0
  21. package/dist/hooks/useImageDimensions.d.ts +10 -0
  22. package/dist/hooks/useImageDimensions.js +69 -0
  23. package/dist/hooks/useImageIndexChange.d.ts +11 -0
  24. package/dist/hooks/useImageIndexChange.js +20 -0
  25. package/dist/hooks/useImagePrefetch.d.ts +10 -0
  26. package/dist/hooks/useImagePrefetch.js +21 -0
  27. package/dist/hooks/usePanResponder.d.ts +19 -0
  28. package/dist/hooks/usePanResponder.js +273 -0
  29. package/dist/hooks/useRequestClose.d.ts +9 -0
  30. package/dist/hooks/useRequestClose.js +20 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.js +8 -0
  33. package/dist/utils.d.ts +46 -0
  34. package/dist/utils.js +99 -0
  35. package/package.json +45 -0
package/dist/utils.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Copyright (c) JOB TODAY S.A. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { Animated, PanResponder, } from "react-native";
9
+ export const createCache = (cacheSize) => ({
10
+ _storage: [],
11
+ get(key) {
12
+ const { value } = this._storage.find(({ key: storageKey }) => storageKey === key) || {};
13
+ return value;
14
+ },
15
+ set(key, value) {
16
+ if (this._storage.length >= cacheSize) {
17
+ this._storage.shift();
18
+ }
19
+ this._storage.push({ key, value });
20
+ },
21
+ });
22
+ export const splitArrayIntoBatches = (arr, batchSize) => arr.reduce((result, item) => {
23
+ const batch = result.pop() || [];
24
+ if (batch.length < batchSize) {
25
+ batch.push(item);
26
+ result.push(batch);
27
+ }
28
+ else {
29
+ result.push(batch, [item]);
30
+ }
31
+ return result;
32
+ }, []);
33
+ export const getImageTransform = (image, screen) => {
34
+ if (!(image === null || image === void 0 ? void 0 : image.width) || !(image === null || image === void 0 ? void 0 : image.height)) {
35
+ return [];
36
+ }
37
+ const wScale = screen.width / image.width;
38
+ const hScale = screen.height / image.height;
39
+ const scale = Math.min(wScale, hScale);
40
+ const { x, y } = getImageTranslate(image, screen);
41
+ return [{ x, y }, scale];
42
+ };
43
+ export const getImageStyles = (image, translate, scale) => {
44
+ if (!(image === null || image === void 0 ? void 0 : image.width) || !(image === null || image === void 0 ? void 0 : image.height)) {
45
+ return { width: 0, height: 0 };
46
+ }
47
+ const transform = [];
48
+ if (scale) {
49
+ transform.push({ scale }, { perspective: new Animated.Value(1000) });
50
+ }
51
+ return {
52
+ width: image.width,
53
+ height: image.height,
54
+ transform,
55
+ };
56
+ };
57
+ export const getImageTranslate = (image, screen) => {
58
+ const getTranslateForAxis = (axis) => {
59
+ const imageSize = axis === "x" ? image.width : image.height;
60
+ const screenSize = axis === "x" ? screen.width : screen.height;
61
+ return (screenSize - imageSize) / 2;
62
+ };
63
+ return {
64
+ x: getTranslateForAxis("x"),
65
+ y: getTranslateForAxis("y"),
66
+ };
67
+ };
68
+ export const getImageDimensionsByTranslate = (translate, screen) => ({
69
+ width: screen.width - translate.x * 2,
70
+ height: screen.height - translate.y * 2,
71
+ });
72
+ export const getImageTranslateForScale = (currentTranslate, targetScale, screen) => {
73
+ const { width, height } = getImageDimensionsByTranslate(currentTranslate, screen);
74
+ const targetImageDimensions = {
75
+ width: width * targetScale,
76
+ height: height * targetScale,
77
+ };
78
+ return getImageTranslate(targetImageDimensions, screen);
79
+ };
80
+ export const createPanResponder = ({ onGrant, onStart, onMove, onRelease, onTerminate, }) => PanResponder.create({
81
+ onStartShouldSetPanResponder: () => true,
82
+ onStartShouldSetPanResponderCapture: () => true,
83
+ onMoveShouldSetPanResponder: () => true,
84
+ onMoveShouldSetPanResponderCapture: () => true,
85
+ onPanResponderGrant: onGrant,
86
+ onPanResponderStart: onStart,
87
+ onPanResponderMove: onMove,
88
+ onPanResponderRelease: onRelease,
89
+ onPanResponderTerminate: onTerminate,
90
+ onPanResponderTerminationRequest: () => false,
91
+ onShouldBlockNativeResponder: () => false,
92
+ });
93
+ export const getDistanceBetweenTouches = (touches) => {
94
+ const [a, b] = touches;
95
+ if (a == null || b == null) {
96
+ return 0;
97
+ }
98
+ return Math.sqrt(Math.pow(a.pageX - b.pageX, 2) + Math.pow(a.pageY - b.pageY, 2));
99
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@gyjshow/react-native-image-viewing",
3
+ "version": "1.0.0",
4
+ "description": "\"Enhanced image viewing component for React Native (Fork of react-native-image-viewing)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/AllenGe/react-native-image-viewing.git"
10
+ },
11
+ "keywords": [
12
+ "react",
13
+ "react-native",
14
+ "image",
15
+ "gallery",
16
+ "image-gallery",
17
+ "image-viewer"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "postversion": "npm build"
22
+ },
23
+ "peerDependencies": {
24
+ "react": ">=18.0.0",
25
+ "react-native": ">=0.72.0"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "readme.md",
30
+ "package.json"
31
+ ],
32
+ "author": "Anton Kalinin",
33
+ "license": "MIT",
34
+ "bugs": {
35
+ "url": "https://github.com/AllenGe/react-native-image-viewing/issues"
36
+ },
37
+ "homepage": "https://github.com/AllenGe/react-native-image-viewing#readme",
38
+ "devDependencies": {
39
+ "@babel/runtime": "^7.25.0",
40
+ "@types/react": "19.2.0",
41
+ "react": "19.2.0",
42
+ "react-native": "0.83.1",
43
+ "typescript": "^5.8.3"
44
+ }
45
+ }