@flipova/foundation 1.14.0 → 2.0.4

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 (268) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/README.md +53 -178
  3. package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +162 -0
  4. package/components/ui/accordion/AccordionAnimatedHeight.tsx +56 -0
  5. package/components/ui/accordion/AccordionAnimatedIcon.tsx +41 -0
  6. package/components/ui/accordion/AnimatedHeight.tsx +56 -0
  7. package/components/ui/accordion/AnimatedIcon.tsx +41 -0
  8. package/components/ui/accordion/MIGRATION_SUMMARY.md +250 -0
  9. package/components/ui/accordion/USAGE_EXAMPLE.tsx +179 -0
  10. package/components/ui/accordion/animation-config.ts +32 -0
  11. package/components/ui/accordion/index.tsx +253 -0
  12. package/components/ui/actionsheet/index.tsx +511 -0
  13. package/components/ui/alert/index.tsx +158 -0
  14. package/components/ui/alert-dialog/index.tsx +254 -0
  15. package/components/ui/avatar/index.tsx +139 -0
  16. package/components/ui/badge/index.tsx +163 -0
  17. package/components/ui/bottomsheet/index.tsx +477 -0
  18. package/components/ui/box/index.tsx +19 -0
  19. package/components/ui/box/index.web.tsx +19 -0
  20. package/components/ui/box/styles.tsx +10 -0
  21. package/components/ui/button/index.tsx +264 -0
  22. package/components/ui/calendar/creator.tsx +366 -0
  23. package/components/ui/calendar/index.tsx +462 -0
  24. package/components/ui/calendar/styles.tsx +140 -0
  25. package/components/ui/card/index.tsx +23 -0
  26. package/components/ui/card/index.web.tsx +26 -0
  27. package/components/ui/card/styles.tsx +16 -0
  28. package/components/ui/center/index.tsx +22 -0
  29. package/components/ui/center/index.web.tsx +20 -0
  30. package/components/ui/center/styles.tsx +8 -0
  31. package/components/ui/checkbox/index.tsx +184 -0
  32. package/components/ui/date-time-picker/creator.tsx +109 -0
  33. package/components/ui/date-time-picker/index.tsx +585 -0
  34. package/components/ui/date-time-picker/index.web.tsx +217 -0
  35. package/components/ui/date-time-picker/styles.tsx +56 -0
  36. package/components/ui/divider/index.tsx +40 -0
  37. package/components/ui/drawer/index.tsx +362 -0
  38. package/components/ui/fab/index.tsx +215 -0
  39. package/components/ui/flat-list/index.tsx +21 -0
  40. package/components/ui/form-control/index.tsx +352 -0
  41. package/components/ui/gluestack-ui-provider/config.ts +72 -0
  42. package/components/ui/gluestack-ui-provider/index.tsx +47 -0
  43. package/components/ui/gluestack-ui-provider/index.web.tsx +96 -0
  44. package/components/ui/gluestack-ui-provider/script.ts +19 -0
  45. package/components/ui/gluestack-ui-provider/tokens.d.ts +17 -0
  46. package/components/ui/gluestack-ui-provider/tokens.js +188 -0
  47. package/components/ui/gluestack-ui-provider/useGluestackColors.ts +82 -0
  48. package/components/ui/grid/index.tsx +283 -0
  49. package/components/ui/grid/index.web.tsx +66 -0
  50. package/components/ui/grid/styles.tsx +15 -0
  51. package/components/ui/heading/index.tsx +220 -0
  52. package/components/ui/heading/index.web.tsx +202 -0
  53. package/components/ui/heading/styles.tsx +43 -0
  54. package/components/ui/hstack/index.tsx +27 -0
  55. package/components/ui/hstack/index.web.tsx +26 -0
  56. package/components/ui/hstack/styles.tsx +25 -0
  57. package/components/ui/icon/index.tsx +1588 -0
  58. package/components/ui/icon/index.web.tsx +1573 -0
  59. package/components/ui/image/index.tsx +48 -0
  60. package/components/ui/image-background/index.tsx +25 -0
  61. package/components/ui/image-viewer/index.tsx +743 -0
  62. package/components/ui/image-viewer/index.web.tsx +302 -0
  63. package/components/ui/index.ts +58 -0
  64. package/components/ui/input/index.tsx +125 -0
  65. package/components/ui/input-accessory-view/index.tsx +2 -0
  66. package/components/ui/keyboard-avoiding-view/index.tsx +2 -0
  67. package/components/ui/link/index.tsx +102 -0
  68. package/components/ui/liquid-glass/index.tsx +74 -0
  69. package/components/ui/menu/index.tsx +186 -0
  70. package/components/ui/modal/index.tsx +237 -0
  71. package/components/ui/popover/index.tsx +272 -0
  72. package/components/ui/portal/index.tsx +17 -0
  73. package/components/ui/pressable/index.tsx +39 -0
  74. package/components/ui/progress/index.tsx +83 -0
  75. package/components/ui/radio/index.tsx +217 -0
  76. package/components/ui/refresh-control/index.tsx +2 -0
  77. package/components/ui/safe-area-view/index.tsx +2 -0
  78. package/components/ui/scroll-view/index.tsx +2 -0
  79. package/components/ui/section-list/index.tsx +2 -0
  80. package/components/ui/select/index.tsx +277 -0
  81. package/components/ui/select/select-actionsheet.tsx +562 -0
  82. package/components/ui/skeleton/index.tsx +105 -0
  83. package/components/ui/skeleton/index.web.tsx +103 -0
  84. package/components/ui/skeleton/styles.tsx +35 -0
  85. package/components/ui/slider/index.tsx +181 -0
  86. package/components/ui/spinner/index.tsx +40 -0
  87. package/components/ui/status-bar/index.tsx +2 -0
  88. package/components/ui/switch/index.tsx +41 -0
  89. package/components/ui/table/index.tsx +210 -0
  90. package/components/ui/table/index.web.tsx +157 -0
  91. package/components/ui/table/styles.tsx +44 -0
  92. package/components/ui/tabs/TabsAnimatedIndicator.tsx +160 -0
  93. package/components/ui/tabs/animation-config.ts +3 -0
  94. package/components/ui/tabs/creator.tsx +206 -0
  95. package/components/ui/tabs/index.tsx +484 -0
  96. package/components/ui/text/index.tsx +48 -0
  97. package/components/ui/text/index.web.tsx +45 -0
  98. package/components/ui/text/styles.tsx +47 -0
  99. package/components/ui/textarea/index.tsx +94 -0
  100. package/components/ui/toast/index.tsx +252 -0
  101. package/components/ui/tooltip/index.tsx +131 -0
  102. package/components/ui/view/index.tsx +2 -0
  103. package/components/ui/virtualized-list/index.tsx +2 -0
  104. package/components/ui/vstack/index.tsx +28 -0
  105. package/components/ui/vstack/index.web.tsx +27 -0
  106. package/components/ui/vstack/styles.tsx +25 -0
  107. package/design/canonical.index.txt +53 -0
  108. package/design/documentation.xml +519 -0
  109. package/design/manifest.xml +90 -0
  110. package/design/schema.xsd +639 -0
  111. package/design/themes.xml +204 -0
  112. package/design/tokens.xml +510 -0
  113. package/design/tools/design.js +165 -0
  114. package/design/tools/npm.js +65 -0
  115. package/design/tools/requirements.txt +35 -0
  116. package/design/tools/sources/.checker/__init__.py +81 -0
  117. package/design/tools/sources/.checker/checks.py +198 -0
  118. package/design/tools/sources/.checker/cli.py +154 -0
  119. package/design/tools/sources/.checker/io.py +242 -0
  120. package/design/tools/sources/.checker/model.py +144 -0
  121. package/design/tools/sources/.checker/registry.py +115 -0
  122. package/design/tools/sources/.checker/report.py +21 -0
  123. package/design/tools/sources/.docgen/__init__.py +45 -0
  124. package/design/tools/sources/.docgen/cli.py +101 -0
  125. package/design/tools/sources/.docgen/model.py +147 -0
  126. package/design/tools/sources/.docgen/reference.py +97 -0
  127. package/design/tools/sources/.docgen/site.py +145 -0
  128. package/design/tools/sources/.docgen/xsddoc.py +329 -0
  129. package/design/tools/sources/.generate/__init__.py +35 -0
  130. package/design/tools/sources/.generate/cli.py +76 -0
  131. package/design/tools/sources/.generate/common.py +33 -0
  132. package/design/tools/sources/.generate/config.py +119 -0
  133. package/design/tools/sources/.generate/model.py +51 -0
  134. package/design/tools/sources/.generate/tokens.py +141 -0
  135. package/design/tools/sources/.linter/__init__.py +9 -0
  136. package/design/tools/sources/.linter/cli.py +44 -0
  137. package/design/tools/sources/.linter/discovery.py +30 -0
  138. package/design/tools/sources/.linter/errors.py +45 -0
  139. package/design/tools/sources/.linter/linter.py +68 -0
  140. package/design/tools/sources/.xmleditor/__init__.py +74 -0
  141. package/design/tools/sources/.xmleditor/blocks.py +185 -0
  142. package/design/tools/sources/.xmleditor/cli.py +141 -0
  143. package/design/tools/sources/.xmleditor/editor.py +906 -0
  144. package/design/tools/sources/.xmleditor/model.py +708 -0
  145. package/design/tools/sources/.xmleditor/widgets.py +1832 -0
  146. package/design/tools/sources/.xmleditor/xsdmodel.py +753 -0
  147. package/design/tools/sources/checker.py +55 -0
  148. package/design/tools/sources/docgen.py +66 -0
  149. package/design/tools/sources/generate.py +48 -0
  150. package/design/tools/sources/linter.py +54 -0
  151. package/design/tools/sources/ruff.toml +12 -0
  152. package/design/tools/sources/xmleditor.py +62 -0
  153. package/design/tools/unix/_venv_python.sh +16 -0
  154. package/design/tools/unix/check.sh +13 -0
  155. package/design/tools/unix/doc.sh +14 -0
  156. package/design/tools/unix/gen.sh +14 -0
  157. package/design/tools/unix/lint.sh +10 -0
  158. package/design/tools/unix/run.sh +20 -0
  159. package/design/tools/unix/verify.sh +12 -0
  160. package/design/tools/unix/xmledit.sh +12 -0
  161. package/design/tools/windows/check.cmd +12 -0
  162. package/design/tools/windows/doc.cmd +12 -0
  163. package/design/tools/windows/gen.cmd +11 -0
  164. package/design/tools/windows/lint.cmd +9 -0
  165. package/design/tools/windows/run.cmd +26 -0
  166. package/design/tools/windows/verify.cmd +10 -0
  167. package/design/tools/windows/xmledit.cmd +10 -0
  168. package/dist/chunk-LV4UIEQN.js +9730 -0
  169. package/dist/chunk-LV4UIEQN.js.map +1 -0
  170. package/dist/chunk-WNVU3BM2.mjs +9401 -0
  171. package/dist/chunk-WNVU3BM2.mjs.map +1 -0
  172. package/dist/index.d.mts +40 -10
  173. package/dist/index.d.ts +40 -10
  174. package/dist/index.js +726 -414
  175. package/dist/index.mjs +1 -5
  176. package/dist/ui/index.d.mts +6931 -3070
  177. package/dist/ui/index.d.ts +6931 -3070
  178. package/dist/ui/index.js +779 -352
  179. package/dist/ui/index.mjs +1 -2
  180. package/package.json +66 -149
  181. package/dist/chunk-2XORADW6.js +0 -24552
  182. package/dist/chunk-2XORADW6.js.map +0 -1
  183. package/dist/chunk-52BHHF5M.js +0 -46
  184. package/dist/chunk-52BHHF5M.js.map +0 -1
  185. package/dist/chunk-5647JY7Z.mjs +0 -100
  186. package/dist/chunk-5647JY7Z.mjs.map +0 -1
  187. package/dist/chunk-5N5HC4ZA.mjs +0 -3
  188. package/dist/chunk-5N5HC4ZA.mjs.map +0 -1
  189. package/dist/chunk-7QFZMGL6.js +0 -8583
  190. package/dist/chunk-7QFZMGL6.js.map +0 -1
  191. package/dist/chunk-ASZEP37D.js +0 -423
  192. package/dist/chunk-ASZEP37D.js.map +0 -1
  193. package/dist/chunk-BH5SU2JQ.mjs +0 -8282
  194. package/dist/chunk-BH5SU2JQ.mjs.map +0 -1
  195. package/dist/chunk-BO65GO53.mjs +0 -422
  196. package/dist/chunk-BO65GO53.mjs.map +0 -1
  197. package/dist/chunk-BSVXX52E.mjs +0 -413
  198. package/dist/chunk-BSVXX52E.mjs.map +0 -1
  199. package/dist/chunk-DNV5UBNF.mjs +0 -3
  200. package/dist/chunk-DNV5UBNF.mjs.map +0 -1
  201. package/dist/chunk-EDTAMUO2.js +0 -8310
  202. package/dist/chunk-EDTAMUO2.js.map +0 -1
  203. package/dist/chunk-IJTI6EX4.js +0 -4
  204. package/dist/chunk-IJTI6EX4.js.map +0 -1
  205. package/dist/chunk-M3YLASM2.js +0 -428
  206. package/dist/chunk-M3YLASM2.js.map +0 -1
  207. package/dist/chunk-OXKOGLXE.js +0 -4
  208. package/dist/chunk-OXKOGLXE.js.map +0 -1
  209. package/dist/chunk-RQXQK3ZO.mjs +0 -8486
  210. package/dist/chunk-RQXQK3ZO.mjs.map +0 -1
  211. package/dist/chunk-SR25V4EA.mjs +0 -40
  212. package/dist/chunk-SR25V4EA.mjs.map +0 -1
  213. package/dist/chunk-UB34WFEQ.js +0 -106
  214. package/dist/chunk-UB34WFEQ.js.map +0 -1
  215. package/dist/chunk-ZBRWXKDF.mjs +0 -24431
  216. package/dist/chunk-ZBRWXKDF.mjs.map +0 -1
  217. package/dist/cli/ds.d.mts +0 -1
  218. package/dist/cli/ds.d.ts +0 -1
  219. package/dist/cli/ds.js +0 -602
  220. package/dist/cli/ds.js.map +0 -1
  221. package/dist/cli/ds.mjs +0 -579
  222. package/dist/cli/ds.mjs.map +0 -1
  223. package/dist/cli/flipova.d.mts +0 -1
  224. package/dist/cli/flipova.d.ts +0 -1
  225. package/dist/cli/flipova.js +0 -161
  226. package/dist/cli/flipova.js.map +0 -1
  227. package/dist/cli/flipova.mjs +0 -154
  228. package/dist/cli/flipova.mjs.map +0 -1
  229. package/dist/config/index.d.mts +0 -123
  230. package/dist/config/index.d.ts +0 -123
  231. package/dist/config/index.js +0 -28
  232. package/dist/config/index.js.map +0 -1
  233. package/dist/config/index.mjs +0 -3
  234. package/dist/config/index.mjs.map +0 -1
  235. package/dist/createTheme-DQeX3s0I.d.mts +0 -78
  236. package/dist/createTheme-Y4jfz4-u.d.ts +0 -78
  237. package/dist/index-CuaJA3gM.d.mts +0 -78
  238. package/dist/index-CuaJA3gM.d.ts +0 -78
  239. package/dist/registry/index.d.mts +0 -10160
  240. package/dist/registry/index.d.ts +0 -10160
  241. package/dist/registry/index.js +0 -392
  242. package/dist/registry/index.js.map +0 -1
  243. package/dist/registry/index.mjs +0 -3
  244. package/dist/registry/index.mjs.map +0 -1
  245. package/dist/theme/index.d.mts +0 -35
  246. package/dist/theme/index.d.ts +0 -35
  247. package/dist/theme/index.js +0 -28
  248. package/dist/theme/index.js.map +0 -1
  249. package/dist/theme/index.mjs +0 -3
  250. package/dist/theme/index.mjs.map +0 -1
  251. package/dist/tokens/index.d.mts +0 -423
  252. package/dist/tokens/index.d.ts +0 -423
  253. package/dist/tokens/index.js +0 -44
  254. package/dist/tokens/index.js.map +0 -1
  255. package/dist/tokens/index.mjs +0 -3
  256. package/dist/tokens/index.mjs.map +0 -1
  257. package/dist/types/index.d.mts +0 -202
  258. package/dist/types/index.d.ts +0 -202
  259. package/dist/types/index.js +0 -4
  260. package/dist/types/index.js.map +0 -1
  261. package/dist/types/index.mjs +0 -3
  262. package/dist/types/index.mjs.map +0 -1
  263. package/dist/web/index.d.mts +0 -316
  264. package/dist/web/index.d.ts +0 -316
  265. package/dist/web/index.js +0 -1500
  266. package/dist/web/index.js.map +0 -1
  267. package/dist/web/index.mjs +0 -1396
  268. package/dist/web/index.mjs.map +0 -1
@@ -0,0 +1,743 @@
1
+ 'use client';
2
+ import React, { useCallback, useState, useEffect, useRef } from 'react';
3
+ import {
4
+ View,
5
+ Pressable,
6
+ Text,
7
+ Image as RNImage,
8
+ Dimensions,
9
+ TouchableOpacity,
10
+ FlatList,
11
+ } from 'react-native';
12
+ import Animated, {
13
+ useSharedValue,
14
+ useAnimatedStyle,
15
+ withSpring,
16
+ withTiming,
17
+ interpolate,
18
+ Extrapolate,
19
+ FadeIn,
20
+ FadeOut,
21
+ Easing,
22
+ runOnJS,
23
+ } from 'react-native-reanimated';
24
+ import { tva } from '@gluestack-ui/utils/nativewind-utils';
25
+ import {
26
+ Gesture,
27
+ GestureDetector,
28
+ GestureHandlerRootView,
29
+ } from 'react-native-gesture-handler';
30
+ import { Overlay } from '@gluestack-ui/core/overlay/creator';
31
+
32
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
33
+
34
+ const AnimatedView = Animated.createAnimatedComponent(View);
35
+ const AnimatedImage = Animated.createAnimatedComponent(RNImage);
36
+
37
+ const imageViewerStyle = tva({
38
+ base: 'w-full',
39
+ });
40
+
41
+ const imageViewerModalStyle = tva({
42
+ base: 'flex-1 bg-black/95',
43
+ });
44
+
45
+ const imageViewerContentStyle = tva({
46
+ base: 'flex-1 justify-center items-center overflow-hidden web:flex web:justify-center web:items-center',
47
+ });
48
+
49
+ const imageViewerCloseButtonStyle = tva({
50
+ base: 'absolute top-12 right-4 z-50 w-10 h-10 rounded-full bg-black/60 justify-center items-center',
51
+ });
52
+
53
+ const imageViewerNavigationStyle = tva({
54
+ base: 'absolute inset-0 flex-row justify-between items-center px-2',
55
+ });
56
+
57
+ const imageViewerNavButtonStyle = tva({
58
+ base: 'w-12 h-12 rounded-full bg-black/50 justify-center items-center',
59
+ });
60
+
61
+ const imageViewerCounterStyle = tva({
62
+ base: 'absolute bottom-12 left-0 right-0 items-center',
63
+ });
64
+
65
+ const imageViewerCounterTextStyle = tva({
66
+ base: 'text-white text-sm font-medium bg-black/60 px-4 py-2 rounded-full',
67
+ });
68
+
69
+ interface ImageItem {
70
+ url: string;
71
+ alt?: string;
72
+ }
73
+
74
+ interface ImageViewerProps {
75
+ images: ImageItem[];
76
+ defaultOpen?: boolean;
77
+ isOpen?: boolean;
78
+ onOpenChange?: (isOpen: boolean) => void;
79
+ onIndexChange?: (index: number) => void;
80
+ initialIndex?: number;
81
+ children?: React.ReactNode;
82
+ }
83
+
84
+ interface ImageViewerTriggerProps {
85
+ children: React.ReactNode;
86
+ onPress?: () => void;
87
+ }
88
+
89
+ // Context for ImageViewer - with default values to prevent errors
90
+ interface ImageViewerContextType {
91
+ images: ImageItem[];
92
+ currentIndex: number;
93
+ isOpen: boolean;
94
+ open: () => void;
95
+ close: () => void;
96
+ goNext: () => void;
97
+ goPrevious: () => void;
98
+ }
99
+
100
+ const ImageViewerContext = React.createContext<ImageViewerContextType>({
101
+ images: [],
102
+ currentIndex: 0,
103
+ isOpen: false,
104
+ open: () => {},
105
+ close: () => {},
106
+ goNext: () => {},
107
+ goPrevious: () => {},
108
+ });
109
+
110
+ const useImageViewerContext = () => {
111
+ const context = React.useContext(ImageViewerContext);
112
+ return context;
113
+ };
114
+
115
+ // Single Zoomable Image Component
116
+ const ZoomableImage = React.memo(
117
+ React.forwardRef(function ZoomableImage(
118
+ {
119
+ image,
120
+ index,
121
+ currentIndex,
122
+ onSwipeLeft,
123
+ onSwipeRight,
124
+ onDismiss,
125
+ onZoomChange,
126
+ }: {
127
+ image: ImageItem;
128
+ index: number;
129
+ currentIndex: number;
130
+ onSwipeLeft: () => void;
131
+ onSwipeRight: () => void;
132
+ onDismiss: () => void;
133
+ onZoomChange?: (isZoomed: boolean) => void;
134
+ },
135
+ ref
136
+ ) {
137
+ const scale = useSharedValue(1);
138
+ const savedScale = useSharedValue(1);
139
+ const translateX = useSharedValue(0);
140
+ const translateY = useSharedValue(0);
141
+ const savedTranslateX = useSharedValue(0);
142
+ const savedTranslateY = useSharedValue(0);
143
+ const dismissProgress = useSharedValue(0);
144
+ const opacity = useSharedValue(1);
145
+
146
+ // Notify parent when zoom changes
147
+ useEffect(() => {
148
+ const isZoomed = scale.value > 1;
149
+ if (index === currentIndex && onZoomChange) {
150
+ onZoomChange(isZoomed);
151
+ }
152
+ }, [scale.value, index, currentIndex, onZoomChange]);
153
+
154
+ // Expose reset method to parent
155
+ React.useImperativeHandle(ref, () => ({
156
+ resetZoom: () => {
157
+ scale.value = 1;
158
+ savedScale.value = 1;
159
+ translateX.value = 0;
160
+ translateY.value = 0;
161
+ savedTranslateX.value = 0;
162
+ savedTranslateY.value = 0;
163
+ if (onZoomChange) {
164
+ onZoomChange(false);
165
+ }
166
+ },
167
+ isZoomed: () => scale.value > 1,
168
+ }));
169
+
170
+ const pinchGesture = Gesture.Pinch()
171
+ .onUpdate((event) => {
172
+ scale.value = savedScale.value * event.scale;
173
+ })
174
+ .onEnd(() => {
175
+ if (scale.value < 1) {
176
+ scale.value = withSpring(1);
177
+ savedScale.value = 1;
178
+ translateX.value = withSpring(0);
179
+ translateY.value = withSpring(0);
180
+ savedTranslateX.value = 0;
181
+ savedTranslateY.value = 0;
182
+ if (onZoomChange) runOnJS(onZoomChange)(false);
183
+ } else if (scale.value > 4) {
184
+ scale.value = withSpring(4);
185
+ savedScale.value = 4;
186
+ if (onZoomChange) runOnJS(onZoomChange)(true);
187
+ } else {
188
+ savedScale.value = scale.value;
189
+ if (onZoomChange) runOnJS(onZoomChange)(scale.value > 1);
190
+ }
191
+ });
192
+
193
+ // Pan gesture for when zoomed - allows free movement with edge detection
194
+ const panGesture = Gesture.Pan()
195
+ .enabled(scale.value > 1)
196
+ .onUpdate((event) => {
197
+ // Calculate max translation bounds for zoomed image
198
+ const maxTranslateX = ((scale.value - 1) * SCREEN_WIDTH) / 2;
199
+ const maxTranslateY = ((scale.value - 1) * SCREEN_HEIGHT * 0.8) / 2;
200
+
201
+ // Allow panning within bounds
202
+ const newTranslateX = savedTranslateX.value + event.translationX;
203
+ const newTranslateY = savedTranslateY.value + event.translationY;
204
+
205
+ // Clamp to bounds
206
+ translateX.value = Math.max(
207
+ -maxTranslateX,
208
+ Math.min(maxTranslateX, newTranslateX)
209
+ );
210
+ translateY.value = Math.max(
211
+ -maxTranslateY,
212
+ Math.min(maxTranslateY, newTranslateY)
213
+ );
214
+ })
215
+ .onEnd((event) => {
216
+ const maxTranslateX = ((scale.value - 1) * SCREEN_WIDTH) / 2;
217
+
218
+ // Check if at horizontal edge and swiped further (outer range offset)
219
+ const isAtRightEdge = translateX.value >= maxTranslateX - 5;
220
+ const isAtLeftEdge = translateX.value <= -maxTranslateX + 5;
221
+ const swipeThreshold = 50;
222
+
223
+ // If at edge and swiped with enough velocity/distance, navigate
224
+ if (
225
+ isAtLeftEdge &&
226
+ event.translationX > swipeThreshold &&
227
+ event.velocityX > 0
228
+ ) {
229
+ // At left edge, swiped right -> go to previous
230
+ runOnJS(onSwipeRight)();
231
+ // Reset zoom after navigation
232
+ scale.value = withSpring(1);
233
+ savedScale.value = 1;
234
+ translateX.value = withSpring(0);
235
+ translateY.value = withSpring(0);
236
+ savedTranslateX.value = 0;
237
+ savedTranslateY.value = 0;
238
+ if (onZoomChange) runOnJS(onZoomChange)(false);
239
+ } else if (
240
+ isAtRightEdge &&
241
+ event.translationX < -swipeThreshold &&
242
+ event.velocityX < 0
243
+ ) {
244
+ // At right edge, swiped left -> go to next
245
+ runOnJS(onSwipeLeft)();
246
+ // Reset zoom after navigation
247
+ scale.value = withSpring(1);
248
+ savedScale.value = 1;
249
+ translateX.value = withSpring(0);
250
+ translateY.value = withSpring(0);
251
+ savedTranslateX.value = 0;
252
+ savedTranslateY.value = 0;
253
+ if (onZoomChange) runOnJS(onZoomChange)(false);
254
+ } else {
255
+ // Save position within bounds
256
+ savedTranslateX.value = translateX.value;
257
+ savedTranslateY.value = translateY.value;
258
+ }
259
+ });
260
+
261
+ // Vertical pan gesture for dismiss - only when NOT zoomed
262
+ const dismissGesture = Gesture.Pan()
263
+ .enabled(scale.value <= 1)
264
+ .activeOffsetY([-10, 10]) // Activate only for vertical movement
265
+ .failOffsetX([-20, 20]) // Fail if horizontal movement is too much
266
+ .onUpdate((event) => {
267
+ dismissProgress.value =
268
+ Math.abs(event.translationY) / (SCREEN_HEIGHT * 0.3);
269
+ translateY.value = event.translationY;
270
+ opacity.value = interpolate(
271
+ dismissProgress.value,
272
+ [0, 1],
273
+ [1, 0.3],
274
+ Extrapolate.CLAMP
275
+ );
276
+ })
277
+ .onEnd((event) => {
278
+ if (Math.abs(event.translationY) > 120) {
279
+ runOnJS(onDismiss)();
280
+ } else {
281
+ translateY.value = withSpring(0);
282
+ opacity.value = withTiming(1, { duration: 200 });
283
+ dismissProgress.value = withTiming(0, { duration: 200 });
284
+ }
285
+ });
286
+
287
+ const lastTapX = useSharedValue(0);
288
+ const lastTapY = useSharedValue(0);
289
+
290
+ const doubleTapGesture = Gesture.Tap()
291
+ .numberOfTaps(2)
292
+ .onBegin((event) => {
293
+ lastTapX.value = event.x;
294
+ lastTapY.value = event.y;
295
+ })
296
+ .onEnd(() => {
297
+ if (scale.value > 1) {
298
+ scale.value = withSpring(1);
299
+ savedScale.value = 1;
300
+ translateX.value = withSpring(0);
301
+ translateY.value = withSpring(0);
302
+ savedTranslateX.value = 0;
303
+ savedTranslateY.value = 0;
304
+ if (onZoomChange) runOnJS(onZoomChange)(false);
305
+ } else {
306
+ const zoomScale = 2.5;
307
+ scale.value = withSpring(zoomScale);
308
+ savedScale.value = zoomScale;
309
+
310
+ const centerX = SCREEN_WIDTH / 2;
311
+ const centerY = SCREEN_HEIGHT * 0.4;
312
+ const deltaX = centerX - lastTapX.value;
313
+ const deltaY = centerY - lastTapY.value;
314
+ const targetX = (deltaX * zoomScale) / zoomScale;
315
+ const targetY = (deltaY * zoomScale) / zoomScale;
316
+
317
+ translateX.value = withSpring(targetX);
318
+ translateY.value = withSpring(targetY);
319
+ savedTranslateX.value = targetX;
320
+ savedTranslateY.value = targetY;
321
+ if (onZoomChange) runOnJS(onZoomChange)(true);
322
+ }
323
+ });
324
+
325
+ const composedGesture = Gesture.Race(
326
+ doubleTapGesture,
327
+ Gesture.Simultaneous(
328
+ pinchGesture,
329
+ Gesture.Exclusive(panGesture, dismissGesture)
330
+ )
331
+ );
332
+
333
+ const animatedStyle = useAnimatedStyle(() => ({
334
+ transform: [
335
+ { translateX: translateX.value },
336
+ { translateY: translateY.value },
337
+ { scale: scale.value },
338
+ ],
339
+ opacity: opacity.value,
340
+ }));
341
+
342
+ return (
343
+ <GestureDetector gesture={composedGesture}>
344
+ <AnimatedImage
345
+ source={{ uri: image.url }}
346
+ alt={image.alt}
347
+ resizeMode="contain"
348
+ style={[
349
+ { width: SCREEN_WIDTH, height: SCREEN_HEIGHT * 0.8 },
350
+ animatedStyle,
351
+ ]}
352
+ />
353
+ </GestureDetector>
354
+ );
355
+ })
356
+ );
357
+
358
+ // FlatList-based Image Gallery Component
359
+ const SlidableImageGallery = React.memo(function SlidableImageGallery({
360
+ images,
361
+ currentIndex,
362
+ onIndexChange,
363
+ onDismiss,
364
+ }: {
365
+ images: ImageItem[];
366
+ currentIndex: number;
367
+ onIndexChange: (index: number) => void;
368
+ onDismiss: () => void;
369
+ }) {
370
+ const flatListRef = useRef<FlatList>(null);
371
+ const [localIndex, setLocalIndex] = useState(currentIndex);
372
+ const scrollOffsetRef = useRef(0);
373
+ const imageRefsRef = useRef<Map<number, any>>(new Map());
374
+ const [isCurrentImageZoomed, setIsCurrentImageZoomed] = useState(false);
375
+
376
+ // Handle zoom change from current image
377
+ const handleZoomChange = useCallback((isZoomed: boolean) => {
378
+ setIsCurrentImageZoomed(isZoomed);
379
+ }, []);
380
+
381
+ // Track previous currentIndex to detect external changes
382
+ const prevCurrentIndexRef = useRef(currentIndex);
383
+
384
+ // Scroll to index when currentIndex changes from outside (button press)
385
+ useEffect(() => {
386
+ // Only scroll if currentIndex changed externally (not from manual scroll)
387
+ if (currentIndex !== prevCurrentIndexRef.current && flatListRef.current) {
388
+ // Reset zoom on current image before scrolling to new one
389
+ const currentImageRef = imageRefsRef.current.get(localIndex);
390
+ if (currentImageRef?.resetZoom) {
391
+ currentImageRef.resetZoom();
392
+ }
393
+
394
+ flatListRef.current.scrollToIndex({
395
+ index: currentIndex,
396
+ animated: true,
397
+ });
398
+ setLocalIndex(currentIndex);
399
+ prevCurrentIndexRef.current = currentIndex;
400
+ }
401
+ }, [currentIndex]);
402
+
403
+ // Handle scroll - track position without updating state
404
+ const handleScroll = useCallback((event: any) => {
405
+ scrollOffsetRef.current = event.nativeEvent.contentOffset.x;
406
+ }, []);
407
+
408
+ // Handle scroll end - update index when scroll completes
409
+ const handleMomentumScrollEnd = useCallback(
410
+ (event: any) => {
411
+ const contentOffsetX = event.nativeEvent.contentOffset.x;
412
+ const newIndex = Math.round(contentOffsetX / SCREEN_WIDTH);
413
+
414
+ if (
415
+ newIndex !== localIndex &&
416
+ newIndex >= 0 &&
417
+ newIndex < images.length
418
+ ) {
419
+ setLocalIndex(newIndex);
420
+ prevCurrentIndexRef.current = newIndex; // Update ref to prevent effect from scrolling back
421
+ onIndexChange(newIndex);
422
+ }
423
+ },
424
+ [localIndex, images.length, onIndexChange]
425
+ );
426
+
427
+ const goNext = useCallback(() => {
428
+ if (currentIndex < images.length - 1) {
429
+ onIndexChange(currentIndex + 1);
430
+ }
431
+ }, [currentIndex, images.length, onIndexChange]);
432
+
433
+ const goPrevious = useCallback(() => {
434
+ if (currentIndex > 0) {
435
+ onIndexChange(currentIndex - 1);
436
+ }
437
+ }, [currentIndex, onIndexChange]);
438
+
439
+ // Render each image item
440
+ const renderItem = useCallback(
441
+ ({ item, index }: { item: ImageItem; index: number }) => (
442
+ <View style={{ width: SCREEN_WIDTH, height: SCREEN_HEIGHT * 0.8 }}>
443
+ <ZoomableImage
444
+ ref={(ref) => {
445
+ if (ref) {
446
+ imageRefsRef.current.set(index, ref);
447
+ } else {
448
+ imageRefsRef.current.delete(index);
449
+ }
450
+ }}
451
+ image={item}
452
+ index={index}
453
+ currentIndex={localIndex}
454
+ onSwipeLeft={goNext}
455
+ onSwipeRight={goPrevious}
456
+ onDismiss={onDismiss}
457
+ onZoomChange={index === localIndex ? handleZoomChange : undefined}
458
+ />
459
+ </View>
460
+ ),
461
+ [localIndex, goNext, goPrevious, onDismiss, handleZoomChange]
462
+ );
463
+
464
+ // Get item layout for better performance
465
+ const getItemLayout = useCallback(
466
+ (_: any, index: number) => ({
467
+ length: SCREEN_WIDTH,
468
+ offset: SCREEN_WIDTH * index,
469
+ index,
470
+ }),
471
+ []
472
+ );
473
+
474
+ const keyExtractor = useCallback(
475
+ (item: ImageItem, index: number) => `image-${index}-${item.url}`,
476
+ []
477
+ );
478
+
479
+ return (
480
+ <View
481
+ style={{ width: SCREEN_WIDTH, height: SCREEN_HEIGHT * 0.8 }}
482
+ className="web:my-auto"
483
+ >
484
+ <FlatList
485
+ ref={flatListRef}
486
+ data={images}
487
+ renderItem={renderItem}
488
+ keyExtractor={keyExtractor}
489
+ horizontal
490
+ pagingEnabled={false}
491
+ scrollEnabled={!isCurrentImageZoomed}
492
+ showsHorizontalScrollIndicator={false}
493
+ onScroll={handleScroll}
494
+ onMomentumScrollEnd={handleMomentumScrollEnd}
495
+ getItemLayout={getItemLayout}
496
+ initialScrollIndex={currentIndex}
497
+ bounces={true}
498
+ scrollEventThrottle={16}
499
+ decelerationRate="normal"
500
+ snapToInterval={SCREEN_WIDTH}
501
+ snapToAlignment="center"
502
+ disableIntervalMomentum={true}
503
+ />
504
+ </View>
505
+ );
506
+ });
507
+
508
+ // Main ImageViewer Component
509
+ const ImageViewer = React.forwardRef<View, ImageViewerProps>(
510
+ function ImageViewer(
511
+ {
512
+ images,
513
+ defaultOpen = false,
514
+ isOpen: controlledIsOpen,
515
+ onOpenChange,
516
+ onIndexChange,
517
+ initialIndex = 0,
518
+ children,
519
+ },
520
+ ref
521
+ ) {
522
+ const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(defaultOpen);
523
+ const [currentIndex, setCurrentIndex] = useState(initialIndex);
524
+
525
+ const isControlled = controlledIsOpen !== undefined;
526
+ const isOpen = isControlled ? controlledIsOpen : uncontrolledIsOpen;
527
+
528
+ useEffect(() => {
529
+ onIndexChange?.(currentIndex);
530
+ }, [currentIndex, onIndexChange]);
531
+
532
+ const open = useCallback(() => {
533
+ if (!isControlled) {
534
+ setUncontrolledIsOpen(true);
535
+ }
536
+ onOpenChange?.(true);
537
+ }, [isControlled, onOpenChange]);
538
+
539
+ const close = useCallback(() => {
540
+ if (!isControlled) {
541
+ setUncontrolledIsOpen(false);
542
+ }
543
+ onOpenChange?.(false);
544
+ }, [isControlled, onOpenChange]);
545
+
546
+ const goNext = useCallback(() => {
547
+ setCurrentIndex((prev) => Math.min(prev + 1, images.length - 1));
548
+ }, [images.length]);
549
+
550
+ const goPrevious = useCallback(() => {
551
+ setCurrentIndex((prev) => Math.max(prev - 1, 0));
552
+ }, []);
553
+
554
+ const contextValue = React.useMemo(
555
+ () => ({
556
+ images,
557
+ currentIndex,
558
+ isOpen,
559
+ open,
560
+ close,
561
+ goNext,
562
+ goPrevious,
563
+ }),
564
+ [images, currentIndex, isOpen, open, close, goNext, goPrevious]
565
+ );
566
+
567
+ return (
568
+ <View ref={ref} className={imageViewerStyle({})}>
569
+ <ImageViewerContext.Provider value={contextValue}>
570
+ {children}
571
+ </ImageViewerContext.Provider>
572
+ </View>
573
+ );
574
+ }
575
+ );
576
+
577
+ // Trigger Component
578
+ const ImageViewerTrigger = React.forwardRef<
579
+ React.ElementRef<typeof Pressable>,
580
+ ImageViewerTriggerProps
581
+ >(function ImageViewerTrigger({ children, onPress, ...props }, ref) {
582
+ const { open } = useImageViewerContext();
583
+
584
+ const handlePress = useCallback(() => {
585
+ onPress?.();
586
+ open();
587
+ }, [onPress, open]);
588
+
589
+ return (
590
+ <Pressable ref={ref} onPress={handlePress} {...props}>
591
+ {children}
592
+ </Pressable>
593
+ );
594
+ });
595
+
596
+ // Content Component (Uses gluestack Overlay for proper portal rendering)
597
+ // Context provider is placed INSIDE the Overlay so portaled content has access
598
+ const ImageViewerContent = React.forwardRef<
599
+ View,
600
+ { children?: React.ReactNode }
601
+ >(function ImageViewerContent({ children }, ref) {
602
+ const context = useImageViewerContext();
603
+ const { images, currentIndex, isOpen, close, goNext, goPrevious } = context;
604
+ const currentImage = images[currentIndex];
605
+
606
+ return (
607
+ <Overlay
608
+ isOpen={isOpen}
609
+ onRequestClose={close}
610
+ isKeyboardDismissable={true}
611
+ >
612
+ <ImageViewerContext.Provider value={context}>
613
+ <GestureHandlerRootView style={{ flex: 1 }}>
614
+ <AnimatedView
615
+ entering={FadeIn.duration(300).easing(Easing.out(Easing.ease))}
616
+ exiting={FadeOut.duration(200).easing(Easing.in(Easing.ease))}
617
+ className={imageViewerModalStyle({})}
618
+ style={{
619
+ display: 'flex',
620
+ justifyContent: 'center',
621
+ alignItems: 'center',
622
+ }}
623
+ >
624
+ <View
625
+ ref={ref}
626
+ className={imageViewerContentStyle({})}
627
+ style={{
628
+ width: '100%',
629
+ height: '100%',
630
+ display: 'flex',
631
+ justifyContent: 'center',
632
+ alignItems: 'center',
633
+ }}
634
+ >
635
+ {currentImage && (
636
+ <SlidableImageGallery
637
+ images={images}
638
+ currentIndex={currentIndex}
639
+ onIndexChange={(newIndex) => {
640
+ if (newIndex > currentIndex) {
641
+ goNext();
642
+ } else if (newIndex < currentIndex) {
643
+ goPrevious();
644
+ }
645
+ }}
646
+ onDismiss={close}
647
+ />
648
+ )}
649
+ {children}
650
+ </View>
651
+ </AnimatedView>
652
+ </GestureHandlerRootView>
653
+ </ImageViewerContext.Provider>
654
+ </Overlay>
655
+ );
656
+ });
657
+
658
+ // Close Button Component
659
+ const ImageViewerCloseButton = React.forwardRef<
660
+ React.ElementRef<typeof Pressable>,
661
+ { className?: string }
662
+ >(function ImageViewerCloseButton({ className, ...props }, ref) {
663
+ const { close } = useImageViewerContext();
664
+
665
+ return (
666
+ <TouchableOpacity
667
+ ref={ref as any}
668
+ onPress={close}
669
+ className={imageViewerCloseButtonStyle({ class: className })}
670
+ accessibilityLabel="Close image viewer"
671
+ accessibilityRole="button"
672
+ {...props}
673
+ >
674
+ <Text className="text-white text-xl font-bold">✕</Text>
675
+ </TouchableOpacity>
676
+ );
677
+ });
678
+
679
+ // Navigation Component
680
+ const ImageViewerNavigation = React.forwardRef<View, { className?: string }>(
681
+ function ImageViewerNavigation({ className }, ref) {
682
+ const { goPrevious, goNext, currentIndex, images } =
683
+ useImageViewerContext();
684
+
685
+ const canGoPrevious = currentIndex > 0;
686
+ const canGoNext = currentIndex < images.length - 1;
687
+
688
+ return (
689
+ <View
690
+ ref={ref}
691
+ className={imageViewerNavigationStyle({ class: className })}
692
+ >
693
+ {canGoPrevious && (
694
+ <TouchableOpacity
695
+ onPress={goPrevious}
696
+ className={imageViewerNavButtonStyle({})}
697
+ accessibilityLabel="Previous image"
698
+ accessibilityRole="button"
699
+ >
700
+ <Text className="text-white text-2xl font-bold">‹</Text>
701
+ </TouchableOpacity>
702
+ )}
703
+ <View className="flex-1" />
704
+ {canGoNext && (
705
+ <TouchableOpacity
706
+ onPress={goNext}
707
+ className={imageViewerNavButtonStyle({})}
708
+ accessibilityLabel="Next image"
709
+ accessibilityRole="button"
710
+ >
711
+ <Text className="text-white text-2xl font-bold">›</Text>
712
+ </TouchableOpacity>
713
+ )}
714
+ </View>
715
+ );
716
+ }
717
+ );
718
+
719
+ // Counter Component
720
+ const ImageViewerCounter = React.forwardRef<View, { className?: string }>(
721
+ function ImageViewerCounter({ className }, ref) {
722
+ const { currentIndex, images } = useImageViewerContext();
723
+
724
+ return (
725
+ <View ref={ref} className={imageViewerCounterStyle({ class: className })}>
726
+ <Text className={imageViewerCounterTextStyle({})}>
727
+ {currentIndex + 1} / {images.length}
728
+ </Text>
729
+ </View>
730
+ );
731
+ }
732
+ );
733
+
734
+ export {
735
+ ImageViewer,
736
+ ImageViewerTrigger,
737
+ ImageViewerContent,
738
+ ImageViewerCloseButton,
739
+ ImageViewerNavigation,
740
+ ImageViewerCounter,
741
+ };
742
+
743
+ export type { ImageItem, ImageViewerProps, ImageViewerTriggerProps };