@tamagui/sheet 2.7.7 → 3.0.0-beta.1091.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.
Files changed (477) hide show
  1. package/dist/cjs/GestureSheetContext.cjs +28 -37
  2. package/dist/cjs/GestureSheetContext.native.cjs +48 -0
  3. package/dist/cjs/GestureSheetContext.native.js +29 -37
  4. package/dist/cjs/GestureSheetContext.native.js.map +1 -1
  5. package/dist/cjs/Sheet.cjs +220 -99
  6. package/dist/cjs/Sheet.native.cjs +245 -0
  7. package/dist/cjs/Sheet.native.js +223 -98
  8. package/dist/cjs/Sheet.native.js.map +1 -1
  9. package/dist/cjs/SheetContext.cjs +43 -22
  10. package/dist/cjs/SheetContext.native.cjs +57 -0
  11. package/dist/cjs/SheetContext.native.js +44 -22
  12. package/dist/cjs/SheetContext.native.js.map +1 -1
  13. package/dist/cjs/SheetController.cjs +49 -56
  14. package/dist/cjs/SheetController.native.cjs +71 -0
  15. package/dist/cjs/SheetController.native.js +52 -58
  16. package/dist/cjs/SheetController.native.js.map +1 -1
  17. package/dist/cjs/SheetDragSurface.cjs +50 -0
  18. package/dist/cjs/SheetDragSurface.native.cjs +61 -0
  19. package/dist/cjs/SheetDragSurface.native.js +63 -0
  20. package/dist/cjs/SheetDragSurface.native.js.map +1 -0
  21. package/dist/cjs/SheetImplementationCustom.cjs +664 -610
  22. package/dist/cjs/SheetImplementationCustom.native.cjs +748 -0
  23. package/dist/cjs/SheetImplementationCustom.native.js +704 -649
  24. package/dist/cjs/SheetImplementationCustom.native.js.map +1 -1
  25. package/dist/cjs/SheetScrollView.cjs +291 -312
  26. package/dist/cjs/SheetScrollView.native.cjs +326 -0
  27. package/dist/cjs/SheetScrollView.native.js +299 -319
  28. package/dist/cjs/SheetScrollView.native.js.map +1 -1
  29. package/dist/cjs/constants.cjs +21 -21
  30. package/dist/cjs/constants.native.cjs +36 -0
  31. package/dist/cjs/constants.native.js +21 -20
  32. package/dist/cjs/constants.native.js.map +1 -1
  33. package/dist/cjs/contexts.cjs +19 -28
  34. package/dist/cjs/contexts.native.cjs +37 -0
  35. package/dist/cjs/contexts.native.js +19 -27
  36. package/dist/cjs/contexts.native.js.map +1 -1
  37. package/dist/cjs/controller.cjs +16 -18
  38. package/dist/cjs/controller.native.cjs +31 -0
  39. package/dist/cjs/controller.native.js +16 -17
  40. package/dist/cjs/controller.native.js.map +1 -1
  41. package/dist/cjs/gestureState.cjs +28 -30
  42. package/dist/cjs/gestureState.native.cjs +53 -0
  43. package/dist/cjs/gestureState.native.js +29 -30
  44. package/dist/cjs/gestureState.native.js.map +1 -1
  45. package/dist/cjs/helpers.cjs +20 -24
  46. package/dist/cjs/helpers.native.cjs +34 -0
  47. package/dist/cjs/helpers.native.js +21 -24
  48. package/dist/cjs/helpers.native.js.map +1 -1
  49. package/dist/cjs/index.cjs +14 -21
  50. package/dist/cjs/index.native.cjs +36 -0
  51. package/dist/cjs/index.native.js +15 -21
  52. package/dist/cjs/index.native.js.map +1 -1
  53. package/dist/cjs/keyboardAvoidance.cjs +55 -79
  54. package/dist/cjs/keyboardAvoidance.native.cjs +74 -0
  55. package/dist/cjs/keyboardAvoidance.native.js +55 -78
  56. package/dist/cjs/keyboardAvoidance.native.js.map +1 -1
  57. package/dist/cjs/nativeSheet.cjs +17 -86
  58. package/dist/cjs/nativeSheet.native.cjs +94 -0
  59. package/dist/cjs/nativeSheet.native.js +73 -86
  60. package/dist/cjs/nativeSheet.native.js.map +1 -1
  61. package/dist/cjs/stableViewportHeight.cjs +27 -0
  62. package/dist/cjs/stableViewportHeight.native.cjs +29 -0
  63. package/dist/cjs/stableViewportHeight.native.js +31 -0
  64. package/dist/cjs/stableViewportHeight.native.js.map +1 -0
  65. package/dist/cjs/types.cjs +9 -11
  66. package/dist/cjs/types.native.cjs +18 -0
  67. package/dist/cjs/types.native.js +9 -10
  68. package/dist/cjs/types.native.js.map +1 -1
  69. package/dist/cjs/useGestureHandlerPan.cjs +244 -257
  70. package/dist/cjs/useGestureHandlerPan.native.cjs +272 -0
  71. package/dist/cjs/useGestureHandlerPan.native.js +253 -265
  72. package/dist/cjs/useGestureHandlerPan.native.js.map +1 -1
  73. package/dist/cjs/useKeyboardControllerSheet.cjs +82 -88
  74. package/dist/cjs/useKeyboardControllerSheet.native.cjs +92 -0
  75. package/dist/cjs/useKeyboardControllerSheet.native.js +73 -111
  76. package/dist/cjs/useKeyboardControllerSheet.native.js.map +1 -1
  77. package/dist/cjs/useSafeAreaInsets.cjs +19 -26
  78. package/dist/cjs/useSafeAreaInsets.native.cjs +50 -0
  79. package/dist/cjs/useSafeAreaInsets.native.js +29 -25
  80. package/dist/cjs/useSafeAreaInsets.native.js.map +1 -1
  81. package/dist/cjs/useSheetController.cjs +26 -39
  82. package/dist/cjs/useSheetController.native.cjs +41 -0
  83. package/dist/cjs/useSheetController.native.js +27 -39
  84. package/dist/cjs/useSheetController.native.js.map +1 -1
  85. package/dist/cjs/useSheetOffscreenSize.cjs +43 -53
  86. package/dist/cjs/useSheetOffscreenSize.native.cjs +59 -0
  87. package/dist/cjs/useSheetOffscreenSize.native.js +47 -56
  88. package/dist/cjs/useSheetOffscreenSize.native.js.map +1 -1
  89. package/dist/cjs/useSheetOpenState.cjs +68 -40
  90. package/dist/cjs/useSheetOpenState.native.cjs +87 -0
  91. package/dist/cjs/useSheetOpenState.native.js +73 -42
  92. package/dist/cjs/useSheetOpenState.native.js.map +1 -1
  93. package/dist/cjs/useSheetProviderProps.cjs +145 -164
  94. package/dist/cjs/useSheetProviderProps.native.cjs +175 -0
  95. package/dist/cjs/useSheetProviderProps.native.js +155 -174
  96. package/dist/cjs/useSheetProviderProps.native.js.map +1 -1
  97. package/dist/cjs/useSheetScrollViewGestures.cjs +171 -180
  98. package/dist/cjs/useSheetScrollViewGestures.native.cjs +149 -0
  99. package/dist/cjs/useSheetScrollViewGestures.native.js +135 -147
  100. package/dist/cjs/useSheetScrollViewGestures.native.js.map +1 -1
  101. package/dist/cjs/webViewport.cjs +46 -48
  102. package/dist/cjs/webViewport.native.cjs +78 -0
  103. package/dist/cjs/webViewport.native.js +49 -50
  104. package/dist/cjs/webViewport.native.js.map +1 -1
  105. package/dist/esm/GestureSheetContext.mjs +15 -20
  106. package/dist/esm/GestureSheetContext.mjs.map +1 -1
  107. package/dist/esm/GestureSheetContext.native.js +17 -22
  108. package/dist/esm/GestureSheetContext.native.js.map +1 -1
  109. package/dist/esm/Sheet.mjs +207 -83
  110. package/dist/esm/Sheet.mjs.map +1 -1
  111. package/dist/esm/Sheet.native.js +210 -83
  112. package/dist/esm/Sheet.native.js.map +1 -1
  113. package/dist/esm/SheetContext.mjs +21 -5
  114. package/dist/esm/SheetContext.mjs.map +1 -1
  115. package/dist/esm/SheetContext.native.js +21 -5
  116. package/dist/esm/SheetContext.native.js.map +1 -1
  117. package/dist/esm/SheetController.mjs +34 -30
  118. package/dist/esm/SheetController.mjs.map +1 -1
  119. package/dist/esm/SheetController.native.js +38 -34
  120. package/dist/esm/SheetController.native.js.map +1 -1
  121. package/dist/esm/SheetDragSurface.mjs +25 -0
  122. package/dist/esm/SheetDragSurface.mjs.map +1 -0
  123. package/dist/esm/SheetDragSurface.native.js +34 -0
  124. package/dist/esm/SheetDragSurface.native.js.map +1 -0
  125. package/dist/esm/SheetImplementationCustom.mjs +647 -586
  126. package/dist/esm/SheetImplementationCustom.mjs.map +1 -1
  127. package/dist/esm/SheetImplementationCustom.native.js +684 -618
  128. package/dist/esm/SheetImplementationCustom.native.js.map +1 -1
  129. package/dist/esm/SheetScrollView.mjs +278 -288
  130. package/dist/esm/SheetScrollView.mjs.map +1 -1
  131. package/dist/esm/SheetScrollView.native.js +287 -297
  132. package/dist/esm/SheetScrollView.native.js.map +1 -1
  133. package/dist/esm/constants.mjs +5 -3
  134. package/dist/esm/constants.mjs.map +1 -1
  135. package/dist/esm/constants.native.js +5 -3
  136. package/dist/esm/constants.native.js.map +1 -1
  137. package/dist/esm/contexts.mjs +3 -3
  138. package/dist/esm/contexts.mjs.map +1 -1
  139. package/dist/esm/contexts.native.js +3 -3
  140. package/dist/esm/contexts.native.js.map +1 -1
  141. package/dist/esm/controller.mjs +2 -2
  142. package/dist/esm/controller.native.js +2 -2
  143. package/dist/esm/gestureState.mjs +13 -11
  144. package/dist/esm/gestureState.mjs.map +1 -1
  145. package/dist/esm/gestureState.native.js +14 -12
  146. package/dist/esm/gestureState.native.js.map +1 -1
  147. package/dist/esm/helpers.mjs +7 -6
  148. package/dist/esm/helpers.mjs.map +1 -1
  149. package/dist/esm/helpers.native.js +8 -7
  150. package/dist/esm/helpers.native.js.map +1 -1
  151. package/dist/esm/index.js +21 -14
  152. package/dist/esm/index.mjs +21 -14
  153. package/dist/esm/index.native.js +21 -14
  154. package/dist/esm/keyboardAvoidance.mjs +40 -61
  155. package/dist/esm/keyboardAvoidance.mjs.map +1 -1
  156. package/dist/esm/keyboardAvoidance.native.js +40 -61
  157. package/dist/esm/keyboardAvoidance.native.js.map +1 -1
  158. package/dist/esm/nativeSheet.mjs +4 -70
  159. package/dist/esm/nativeSheet.mjs.map +1 -1
  160. package/dist/esm/nativeSheet.native.js +60 -70
  161. package/dist/esm/nativeSheet.native.js.map +1 -1
  162. package/dist/esm/stableViewportHeight.mjs +8 -0
  163. package/dist/esm/stableViewportHeight.mjs.map +1 -0
  164. package/dist/esm/stableViewportHeight.native.js +8 -0
  165. package/dist/esm/stableViewportHeight.native.js.map +1 -0
  166. package/dist/esm/types.mjs +0 -2
  167. package/dist/esm/types.native.js +0 -2
  168. package/dist/esm/useGestureHandlerPan.mjs +232 -239
  169. package/dist/esm/useGestureHandlerPan.mjs.map +1 -1
  170. package/dist/esm/useGestureHandlerPan.native.js +241 -248
  171. package/dist/esm/useGestureHandlerPan.native.js.map +1 -1
  172. package/dist/esm/useKeyboardControllerSheet.mjs +71 -71
  173. package/dist/esm/useKeyboardControllerSheet.mjs.map +1 -1
  174. package/dist/esm/useKeyboardControllerSheet.native.js +66 -94
  175. package/dist/esm/useKeyboardControllerSheet.native.js.map +1 -1
  176. package/dist/esm/useSafeAreaInsets.mjs +3 -1
  177. package/dist/esm/useSafeAreaInsets.mjs.map +1 -1
  178. package/dist/esm/useSafeAreaInsets.native.js +15 -3
  179. package/dist/esm/useSafeAreaInsets.native.js.map +1 -1
  180. package/dist/esm/useSheetController.mjs +14 -12
  181. package/dist/esm/useSheetController.mjs.map +1 -1
  182. package/dist/esm/useSheetController.native.js +14 -12
  183. package/dist/esm/useSheetController.native.js.map +1 -1
  184. package/dist/esm/useSheetOffscreenSize.mjs +30 -35
  185. package/dist/esm/useSheetOffscreenSize.mjs.map +1 -1
  186. package/dist/esm/useSheetOffscreenSize.native.js +34 -39
  187. package/dist/esm/useSheetOffscreenSize.native.js.map +1 -1
  188. package/dist/esm/useSheetOpenState.mjs +50 -22
  189. package/dist/esm/useSheetOpenState.mjs.map +1 -1
  190. package/dist/esm/useSheetOpenState.native.js +55 -25
  191. package/dist/esm/useSheetOpenState.native.js.map +1 -1
  192. package/dist/esm/useSheetProviderProps.mjs +130 -138
  193. package/dist/esm/useSheetProviderProps.mjs.map +1 -1
  194. package/dist/esm/useSheetProviderProps.native.js +140 -149
  195. package/dist/esm/useSheetProviderProps.native.js.map +1 -1
  196. package/dist/esm/useSheetScrollViewGestures.mjs +159 -162
  197. package/dist/esm/useSheetScrollViewGestures.mjs.map +1 -1
  198. package/dist/esm/useSheetScrollViewGestures.native.js +123 -130
  199. package/dist/esm/useSheetScrollViewGestures.native.js.map +1 -1
  200. package/dist/esm/webViewport.mjs +26 -25
  201. package/dist/esm/webViewport.mjs.map +1 -1
  202. package/dist/esm/webViewport.native.js +29 -28
  203. package/dist/esm/webViewport.native.js.map +1 -1
  204. package/dist/jsx/GestureSheetContext.mjs +15 -20
  205. package/dist/jsx/GestureSheetContext.mjs.map +1 -1
  206. package/dist/jsx/GestureSheetContext.native.cjs +48 -0
  207. package/dist/jsx/GestureSheetContext.native.js +29 -37
  208. package/dist/jsx/GestureSheetContext.native.js.map +1 -1
  209. package/dist/jsx/Sheet.mjs +207 -83
  210. package/dist/jsx/Sheet.mjs.map +1 -1
  211. package/dist/jsx/Sheet.native.cjs +245 -0
  212. package/dist/jsx/Sheet.native.js +223 -98
  213. package/dist/jsx/Sheet.native.js.map +1 -1
  214. package/dist/jsx/SheetContext.mjs +21 -5
  215. package/dist/jsx/SheetContext.mjs.map +1 -1
  216. package/dist/jsx/SheetContext.native.cjs +57 -0
  217. package/dist/jsx/SheetContext.native.js +44 -22
  218. package/dist/jsx/SheetContext.native.js.map +1 -1
  219. package/dist/jsx/SheetController.mjs +34 -30
  220. package/dist/jsx/SheetController.mjs.map +1 -1
  221. package/dist/jsx/SheetController.native.cjs +71 -0
  222. package/dist/jsx/SheetController.native.js +52 -58
  223. package/dist/jsx/SheetController.native.js.map +1 -1
  224. package/dist/jsx/SheetDragSurface.mjs +25 -0
  225. package/dist/jsx/SheetDragSurface.mjs.map +1 -0
  226. package/dist/jsx/SheetDragSurface.native.cjs +61 -0
  227. package/dist/jsx/SheetDragSurface.native.js +63 -0
  228. package/dist/jsx/SheetDragSurface.native.js.map +1 -0
  229. package/dist/jsx/SheetImplementationCustom.mjs +647 -586
  230. package/dist/jsx/SheetImplementationCustom.mjs.map +1 -1
  231. package/dist/jsx/SheetImplementationCustom.native.cjs +748 -0
  232. package/dist/jsx/SheetImplementationCustom.native.js +704 -649
  233. package/dist/jsx/SheetImplementationCustom.native.js.map +1 -1
  234. package/dist/jsx/SheetScrollView.mjs +278 -288
  235. package/dist/jsx/SheetScrollView.mjs.map +1 -1
  236. package/dist/jsx/SheetScrollView.native.cjs +326 -0
  237. package/dist/jsx/SheetScrollView.native.js +299 -319
  238. package/dist/jsx/SheetScrollView.native.js.map +1 -1
  239. package/dist/jsx/constants.mjs +5 -3
  240. package/dist/jsx/constants.mjs.map +1 -1
  241. package/dist/jsx/constants.native.cjs +36 -0
  242. package/dist/jsx/constants.native.js +21 -20
  243. package/dist/jsx/constants.native.js.map +1 -1
  244. package/dist/jsx/contexts.mjs +3 -3
  245. package/dist/jsx/contexts.mjs.map +1 -1
  246. package/dist/jsx/contexts.native.cjs +37 -0
  247. package/dist/jsx/contexts.native.js +19 -27
  248. package/dist/jsx/contexts.native.js.map +1 -1
  249. package/dist/jsx/controller.mjs +2 -2
  250. package/dist/jsx/controller.native.cjs +31 -0
  251. package/dist/jsx/controller.native.js +16 -17
  252. package/dist/jsx/controller.native.js.map +1 -1
  253. package/dist/jsx/gestureState.mjs +13 -11
  254. package/dist/jsx/gestureState.mjs.map +1 -1
  255. package/dist/jsx/gestureState.native.cjs +53 -0
  256. package/dist/jsx/gestureState.native.js +29 -30
  257. package/dist/jsx/gestureState.native.js.map +1 -1
  258. package/dist/jsx/helpers.mjs +7 -6
  259. package/dist/jsx/helpers.mjs.map +1 -1
  260. package/dist/jsx/helpers.native.cjs +34 -0
  261. package/dist/jsx/helpers.native.js +21 -24
  262. package/dist/jsx/helpers.native.js.map +1 -1
  263. package/dist/jsx/index.js +21 -14
  264. package/dist/jsx/index.mjs +21 -14
  265. package/dist/jsx/index.native.cjs +36 -0
  266. package/dist/jsx/index.native.js +15 -21
  267. package/dist/jsx/index.native.js.map +1 -1
  268. package/dist/jsx/keyboardAvoidance.mjs +40 -61
  269. package/dist/jsx/keyboardAvoidance.mjs.map +1 -1
  270. package/dist/jsx/keyboardAvoidance.native.cjs +74 -0
  271. package/dist/jsx/keyboardAvoidance.native.js +55 -78
  272. package/dist/jsx/keyboardAvoidance.native.js.map +1 -1
  273. package/dist/jsx/nativeSheet.mjs +4 -70
  274. package/dist/jsx/nativeSheet.mjs.map +1 -1
  275. package/dist/jsx/nativeSheet.native.cjs +94 -0
  276. package/dist/jsx/nativeSheet.native.js +73 -86
  277. package/dist/jsx/nativeSheet.native.js.map +1 -1
  278. package/dist/jsx/stableViewportHeight.mjs +8 -0
  279. package/dist/jsx/stableViewportHeight.mjs.map +1 -0
  280. package/dist/jsx/stableViewportHeight.native.cjs +29 -0
  281. package/dist/jsx/stableViewportHeight.native.js +31 -0
  282. package/dist/jsx/stableViewportHeight.native.js.map +1 -0
  283. package/dist/jsx/types.mjs +0 -2
  284. package/dist/jsx/types.native.cjs +18 -0
  285. package/dist/jsx/types.native.js +9 -10
  286. package/dist/jsx/types.native.js.map +1 -1
  287. package/dist/jsx/useGestureHandlerPan.mjs +232 -239
  288. package/dist/jsx/useGestureHandlerPan.mjs.map +1 -1
  289. package/dist/jsx/useGestureHandlerPan.native.cjs +272 -0
  290. package/dist/jsx/useGestureHandlerPan.native.js +253 -265
  291. package/dist/jsx/useGestureHandlerPan.native.js.map +1 -1
  292. package/dist/jsx/useKeyboardControllerSheet.mjs +71 -71
  293. package/dist/jsx/useKeyboardControllerSheet.mjs.map +1 -1
  294. package/dist/jsx/useKeyboardControllerSheet.native.cjs +92 -0
  295. package/dist/jsx/useKeyboardControllerSheet.native.js +73 -111
  296. package/dist/jsx/useKeyboardControllerSheet.native.js.map +1 -1
  297. package/dist/jsx/useSafeAreaInsets.mjs +3 -1
  298. package/dist/jsx/useSafeAreaInsets.mjs.map +1 -1
  299. package/dist/jsx/useSafeAreaInsets.native.cjs +50 -0
  300. package/dist/jsx/useSafeAreaInsets.native.js +29 -25
  301. package/dist/jsx/useSafeAreaInsets.native.js.map +1 -1
  302. package/dist/jsx/useSheetController.mjs +14 -12
  303. package/dist/jsx/useSheetController.mjs.map +1 -1
  304. package/dist/jsx/useSheetController.native.cjs +41 -0
  305. package/dist/jsx/useSheetController.native.js +27 -39
  306. package/dist/jsx/useSheetController.native.js.map +1 -1
  307. package/dist/jsx/useSheetOffscreenSize.mjs +30 -35
  308. package/dist/jsx/useSheetOffscreenSize.mjs.map +1 -1
  309. package/dist/jsx/useSheetOffscreenSize.native.cjs +59 -0
  310. package/dist/jsx/useSheetOffscreenSize.native.js +47 -56
  311. package/dist/jsx/useSheetOffscreenSize.native.js.map +1 -1
  312. package/dist/jsx/useSheetOpenState.mjs +50 -22
  313. package/dist/jsx/useSheetOpenState.mjs.map +1 -1
  314. package/dist/jsx/useSheetOpenState.native.cjs +87 -0
  315. package/dist/jsx/useSheetOpenState.native.js +73 -42
  316. package/dist/jsx/useSheetOpenState.native.js.map +1 -1
  317. package/dist/jsx/useSheetProviderProps.mjs +130 -138
  318. package/dist/jsx/useSheetProviderProps.mjs.map +1 -1
  319. package/dist/jsx/useSheetProviderProps.native.cjs +175 -0
  320. package/dist/jsx/useSheetProviderProps.native.js +155 -174
  321. package/dist/jsx/useSheetProviderProps.native.js.map +1 -1
  322. package/dist/jsx/useSheetScrollViewGestures.mjs +159 -162
  323. package/dist/jsx/useSheetScrollViewGestures.mjs.map +1 -1
  324. package/dist/jsx/useSheetScrollViewGestures.native.cjs +149 -0
  325. package/dist/jsx/useSheetScrollViewGestures.native.js +135 -147
  326. package/dist/jsx/useSheetScrollViewGestures.native.js.map +1 -1
  327. package/dist/jsx/webViewport.mjs +26 -25
  328. package/dist/jsx/webViewport.mjs.map +1 -1
  329. package/dist/jsx/webViewport.native.cjs +78 -0
  330. package/dist/jsx/webViewport.native.js +49 -50
  331. package/dist/jsx/webViewport.native.js.map +1 -1
  332. package/package.json +38 -40
  333. package/src/Sheet.tsx +314 -77
  334. package/src/SheetContext.tsx +57 -7
  335. package/src/SheetController.tsx +7 -6
  336. package/src/SheetDragSurface.native.tsx +42 -0
  337. package/src/SheetDragSurface.tsx +40 -0
  338. package/src/SheetImplementationCustom.tsx +364 -181
  339. package/src/SheetScrollView.tsx +36 -20
  340. package/src/constants.tsx +3 -3
  341. package/src/helpers.tsx +0 -14
  342. package/src/index.ts +3 -6
  343. package/src/{nativeSheet.tsx → nativeSheet.native.tsx} +9 -20
  344. package/src/nativeSheet.ts +19 -0
  345. package/src/stableViewportHeight.native.ts +9 -0
  346. package/src/stableViewportHeight.ts +15 -0
  347. package/src/types.tsx +122 -92
  348. package/src/useKeyboardControllerSheet.native.ts +10 -39
  349. package/src/useSafeAreaInsets.native.ts +20 -13
  350. package/src/useSheetController.tsx +15 -7
  351. package/src/useSheetOpenState.tsx +50 -4
  352. package/src/useSheetProviderProps.tsx +4 -27
  353. package/src/useSheetScrollViewGestures.ts +2 -2
  354. package/types/GestureSheetContext.d.ts +1 -1
  355. package/types/GestureSheetContext.d.ts.map +1 -1
  356. package/types/Sheet.d.ts +247 -151
  357. package/types/Sheet.d.ts.map +1 -1
  358. package/types/SheetContext.d.ts +28 -42
  359. package/types/SheetContext.d.ts.map +1 -1
  360. package/types/SheetController.d.ts +4 -2
  361. package/types/SheetController.d.ts.map +1 -1
  362. package/types/SheetDragSurface.d.ts +11 -0
  363. package/types/SheetDragSurface.d.ts.map +1 -0
  364. package/types/SheetDragSurface.native.d.ts +11 -0
  365. package/types/SheetDragSurface.native.d.ts.map +1 -0
  366. package/types/SheetImplementationCustom.d.ts +4 -36
  367. package/types/SheetImplementationCustom.d.ts.map +1 -1
  368. package/types/SheetScrollView.d.ts +21 -38
  369. package/types/SheetScrollView.d.ts.map +1 -1
  370. package/types/constants.d.ts +3 -2
  371. package/types/constants.d.ts.map +1 -1
  372. package/types/index.d.ts +1 -3
  373. package/types/index.d.ts.map +1 -1
  374. package/types/nativeSheet.d.ts +8 -8
  375. package/types/nativeSheet.d.ts.map +1 -1
  376. package/types/nativeSheet.native.d.ts +5 -0
  377. package/types/nativeSheet.native.d.ts.map +1 -0
  378. package/types/stableViewportHeight.d.ts +12 -0
  379. package/types/stableViewportHeight.d.ts.map +1 -0
  380. package/types/stableViewportHeight.native.d.ts +6 -0
  381. package/types/stableViewportHeight.native.d.ts.map +1 -0
  382. package/types/types.d.ts +43 -17
  383. package/types/types.d.ts.map +1 -1
  384. package/types/useKeyboardControllerSheet.native.d.ts +6 -6
  385. package/types/useKeyboardControllerSheet.native.d.ts.map +1 -1
  386. package/types/useSafeAreaInsets.native.d.ts +4 -12
  387. package/types/useSafeAreaInsets.native.d.ts.map +1 -1
  388. package/types/useSheetController.d.ts +6 -6
  389. package/types/useSheetController.d.ts.map +1 -1
  390. package/types/useSheetOffscreenSize.d.ts.map +1 -1
  391. package/types/useSheetOpenState.d.ts +3 -2
  392. package/types/useSheetOpenState.d.ts.map +1 -1
  393. package/types/useSheetProviderProps.d.ts +5 -8
  394. package/types/useSheetProviderProps.d.ts.map +1 -1
  395. package/types/useSheetScrollViewGestures.d.ts +2 -2
  396. package/types/useSheetScrollViewGestures.d.ts.map +1 -1
  397. package/.turbo/turbo-build.log +0 -2
  398. package/controller/index.cjs +0 -2
  399. package/controller/index.d.ts +0 -5
  400. package/controller/index.js +0 -2
  401. package/controller/index.native.cjs +0 -2
  402. package/controller/index.native.js +0 -2
  403. package/dist/cjs/GestureDetectorWrapper.cjs +0 -54
  404. package/dist/cjs/GestureDetectorWrapper.native.js +0 -58
  405. package/dist/cjs/GestureDetectorWrapper.native.js.map +0 -1
  406. package/dist/cjs/createSheet.cjs +0 -194
  407. package/dist/cjs/createSheet.native.js +0 -204
  408. package/dist/cjs/createSheet.native.js.map +0 -1
  409. package/dist/cjs/setupGestureHandler.cjs +0 -55
  410. package/dist/cjs/setupGestureHandler.native.js +0 -60
  411. package/dist/cjs/setupGestureHandler.native.js.map +0 -1
  412. package/dist/cjs/useSheet.cjs +0 -29
  413. package/dist/cjs/useSheet.native.js +0 -34
  414. package/dist/cjs/useSheet.native.js.map +0 -1
  415. package/dist/esm/GestureDetectorWrapper.mjs +0 -29
  416. package/dist/esm/GestureDetectorWrapper.mjs.map +0 -1
  417. package/dist/esm/GestureDetectorWrapper.native.js +0 -30
  418. package/dist/esm/GestureDetectorWrapper.native.js.map +0 -1
  419. package/dist/esm/controller.mjs.map +0 -1
  420. package/dist/esm/controller.native.js.map +0 -1
  421. package/dist/esm/createSheet.mjs +0 -168
  422. package/dist/esm/createSheet.mjs.map +0 -1
  423. package/dist/esm/createSheet.native.js +0 -176
  424. package/dist/esm/createSheet.native.js.map +0 -1
  425. package/dist/esm/index.js.map +0 -1
  426. package/dist/esm/index.mjs.map +0 -1
  427. package/dist/esm/index.native.js.map +0 -1
  428. package/dist/esm/setupGestureHandler.mjs +0 -29
  429. package/dist/esm/setupGestureHandler.mjs.map +0 -1
  430. package/dist/esm/setupGestureHandler.native.js +0 -31
  431. package/dist/esm/setupGestureHandler.native.js.map +0 -1
  432. package/dist/esm/types.mjs.map +0 -1
  433. package/dist/esm/types.native.js.map +0 -1
  434. package/dist/esm/useSheet.mjs +0 -4
  435. package/dist/esm/useSheet.mjs.map +0 -1
  436. package/dist/esm/useSheet.native.js +0 -6
  437. package/dist/esm/useSheet.native.js.map +0 -1
  438. package/dist/jsx/GestureDetectorWrapper.mjs +0 -29
  439. package/dist/jsx/GestureDetectorWrapper.mjs.map +0 -1
  440. package/dist/jsx/GestureDetectorWrapper.native.js +0 -58
  441. package/dist/jsx/GestureDetectorWrapper.native.js.map +0 -1
  442. package/dist/jsx/controller.mjs.map +0 -1
  443. package/dist/jsx/createSheet.mjs +0 -168
  444. package/dist/jsx/createSheet.mjs.map +0 -1
  445. package/dist/jsx/createSheet.native.js +0 -204
  446. package/dist/jsx/createSheet.native.js.map +0 -1
  447. package/dist/jsx/index.js.map +0 -1
  448. package/dist/jsx/index.mjs.map +0 -1
  449. package/dist/jsx/setupGestureHandler.mjs +0 -29
  450. package/dist/jsx/setupGestureHandler.mjs.map +0 -1
  451. package/dist/jsx/setupGestureHandler.native.js +0 -60
  452. package/dist/jsx/setupGestureHandler.native.js.map +0 -1
  453. package/dist/jsx/types.mjs.map +0 -1
  454. package/dist/jsx/useSheet.mjs +0 -4
  455. package/dist/jsx/useSheet.mjs.map +0 -1
  456. package/dist/jsx/useSheet.native.js +0 -34
  457. package/dist/jsx/useSheet.native.js.map +0 -1
  458. package/next.md +0 -78
  459. package/setup-gesture-handler/index.cjs +0 -2
  460. package/setup-gesture-handler/index.js +0 -2
  461. package/setup-gesture-handler/index.native.cjs +0 -2
  462. package/setup-gesture-handler/index.native.js +0 -2
  463. package/setup-gesture-handler.cjs +0 -1
  464. package/src/GestureDetectorWrapper.tsx +0 -38
  465. package/src/createSheet.tsx +0 -309
  466. package/src/setupGestureHandler.ts +0 -43
  467. package/src/useSheet.tsx +0 -3
  468. package/test/keyboardAvoidance.test.ts +0 -269
  469. package/tsconfig.json +0 -57
  470. package/types/GestureDetectorWrapper.d.ts +0 -14
  471. package/types/GestureDetectorWrapper.d.ts.map +0 -1
  472. package/types/createSheet.d.ts +0 -195
  473. package/types/createSheet.d.ts.map +0 -1
  474. package/types/setupGestureHandler.d.ts +0 -11
  475. package/types/setupGestureHandler.d.ts.map +0 -1
  476. package/types/useSheet.d.ts +0 -2
  477. package/types/useSheet.d.ts.map +0 -1
@@ -1,612 +1,673 @@
1
1
  import { AnimatePresence } from "@tamagui/animate-presence";
2
+ import { getTransitionResolver } from "@tamagui/animation-helpers/transitionResolver";
2
3
  import { useComposedRefs } from "@tamagui/compose-refs";
3
4
  import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
- import { LayoutMeasurementController, View, useConfiguration, useDidFinishSSR, useEvent, useThemeName } from "@tamagui/core";
5
+ import { LayoutMeasurementController, View, createRefComponent, formatDiagnostic, useAnimatedNumber, useAnimatedNumberStyle, useAnimationDriver, useDidFinishSSR, useEvent, useThemeName } from "@tamagui/core";
5
6
  import { Portal, needsPortalRepropagation } from "@tamagui/portal";
6
7
  import React, { useState } from "react";
7
- import { Dimensions, PanResponder, View as View$1 } from "react-native-web";
8
8
  import { ParentSheetContext, SheetInsideSheetContext } from "./contexts.mjs";
9
- import { GestureDetectorWrapper } from "./GestureDetectorWrapper.mjs";
9
+ import { SHEET_OVERLAY_MARKER } from "./constants.mjs";
10
10
  import { getGestureHandlerState } from "./gestureState.mjs";
11
+ import { SheetDragSurface } from "./SheetDragSurface.mjs";
12
+ import { getStableViewportHeight } from "./stableViewportHeight.mjs";
11
13
  import { GestureSheetProvider } from "./GestureSheetContext.mjs";
12
14
  import { resisted } from "./helpers.mjs";
13
15
  import { getKeyboardAdjustedSheetY, getKeyboardOccludedHeight, getSheetReleasePosition } from "./keyboardAvoidance.mjs";
14
- import { MIN_KEYBOARD_HEIGHT, getMaxViewportHeight, getStableLayoutViewportHeight, getWebKeyboardResizeHeight, getWebVisualViewportOffsetTop } from "./webViewport.mjs";
15
- import { SheetProvider } from "./SheetContext.mjs";
16
+ import { MIN_KEYBOARD_HEIGHT, getMaxViewportHeight, getWebKeyboardResizeHeight, getWebVisualViewportOffsetTop } from "./webViewport.mjs";
17
+ import { SheetAnimatedPositionContext, SheetOverlayLayerContext, SheetProvider } from "./SheetContext.mjs";
16
18
  import { useGestureHandlerPan } from "./useGestureHandlerPan.mjs";
17
19
  import { useKeyboardControllerSheet } from "./useKeyboardControllerSheet.mjs";
18
20
  import { useSafeAreaInsets } from "./useSafeAreaInsets.mjs";
19
21
  import { useSheetOpenState } from "./useSheetOpenState.mjs";
20
22
  import { useSheetProviderProps } from "./useSheetProviderProps.mjs";
21
23
  import { jsx, jsxs } from "react/jsx-runtime";
24
+
22
25
  const hiddenSize = 10000.1;
23
26
  const rnghRootStyleOpen = {
24
- width: "100%",
25
- height: "100%"
27
+ width: "100%",
28
+ height: "100%"
26
29
  };
27
30
  const rnghRootStyleClosed = {
28
- width: "100%",
29
- height: 0
31
+ width: "100%",
32
+ height: 0
30
33
  };
31
34
  let sheetHiddenStyleSheet = null;
32
- const relativeDimensionTo = isWeb ? "window" : "screen";
33
- function getStableViewportHeight() {
34
- if (isWeb && typeof window !== "undefined") return getStableLayoutViewportHeight();
35
- return Dimensions.get(relativeDimensionTo).height;
36
- }
37
- const SheetImplementationCustom = React.forwardRef(function SheetImplementationCustom2(props, forwardedRef) {
38
- const parentSheet = React.useContext(ParentSheetContext);
39
- const safeAreaTopInset = useSafeAreaInsets()?.top ?? 0;
40
- const {
41
- transition,
42
- transitionConfig: transitionConfigProp,
43
- modal = false,
44
- zIndex = parentSheet.zIndex + 1,
45
- moveOnKeyboardChange = false,
46
- unmountChildrenWhenHidden = false,
47
- disableTransparencyHide = false,
48
- portalProps,
49
- containerComponent: ContainerComponent = React.Fragment,
50
- onAnimationComplete
51
- } = props;
52
- const state = useSheetOpenState(props);
53
- const [overlayComponent, setOverlayComponent] = React.useState(null);
54
- const providerProps = useSheetProviderProps(props, state, {
55
- onOverlayComponent: setOverlayComponent
56
- });
57
- const {
58
- frameSize,
59
- setFrameSize,
60
- dismissOnSnapToBottom,
61
- snapPoints,
62
- snapPointsMode,
63
- hasFit,
64
- position,
65
- setPosition,
66
- scrollBridge,
67
- screenSize,
68
- setMaxContentSize,
69
- maxSnapPoint
70
- } = providerProps;
71
- const {
72
- open,
73
- controller,
74
- isHidden
75
- } = state;
76
- const openRef = React.useRef(open);
77
- openRef.current = open;
78
- const ref = useComposedRefs(forwardedRef, React.useRef(void 0), providerProps.contentRef);
79
- const {
80
- animationDriver
81
- } = useConfiguration();
82
- if (!animationDriver) throw new Error(`Sheet requires an animation driver to be set`);
83
- const transitionConfig = (() => {
84
- if (transitionConfigProp) return transitionConfigProp;
85
- const [animationProp, animationPropConfig] = !transition ? [] : Array.isArray(transition) ? transition : [transition];
86
- if (animationProp && animationDriver.animations?.[animationProp]) return {
87
- ...animationDriver.animations[animationProp],
88
- ...animationPropConfig
89
- };
90
- return null;
91
- })();
92
- const [isShowingInnerSheet, setIsShowingInnerSheet] = React.useState(false);
93
- const shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet && needsPortalRepropagation();
94
- const sheetInsideSheet = React.useContext(SheetInsideSheetContext);
95
- const onInnerSheet = React.useCallback(hasChild => {
96
- setIsShowingInnerSheet(hasChild);
97
- }, []);
98
- const {
99
- keyboardHeight,
100
- isKeyboardVisible,
101
- dismissKeyboard,
102
- pauseKeyboardHandler,
103
- flushPendingHide
104
- } = useKeyboardControllerSheet({
105
- enabled: Boolean(moveOnKeyboardChange)
106
- });
107
- const stableFrameSize = React.useRef(frameSize);
108
- React.useEffect(() => {
109
- if (open && frameSize) stableFrameSize.current = frameSize;
110
- }, [open, frameSize]);
111
- const isWebKbSheet = isWeb && hasFit && moveOnKeyboardChange;
112
- const isNativeKbFitSheet = !isWeb && hasFit && Boolean(moveOnKeyboardChange);
113
- const preKeyboardFrameSize = React.useRef(0);
114
- React.useEffect(() => {
115
- if (isNativeKbFitSheet && open && !isKeyboardVisible && frameSize > 0) preKeyboardFrameSize.current = frameSize;
116
- }, [isNativeKbFitSheet, open, isKeyboardVisible, frameSize]);
117
- const effScreenSize = isWebKbSheet ? getStableViewportHeight() : screenSize;
118
- const effectiveFrameSize = open ? frameSize : stableFrameSize.current || frameSize;
119
- const positions = React.useMemo(() => snapPoints.map(point => getYPositions(snapPointsMode, point, effScreenSize, effectiveFrameSize)), [effScreenSize, effectiveFrameSize, snapPoints, snapPointsMode]);
120
- const [isDragging, setIsDragging_] = React.useState(false);
121
- const isDraggingRef = React.useRef(false);
122
- const setIsDragging = React.useCallback(val => {
123
- isDraggingRef.current = val;
124
- pauseKeyboardHandler.current = val;
125
- setIsDragging_(val);
126
- if (!val) flushPendingHide();
127
- }, [pauseKeyboardHandler, flushPendingHide]);
128
- const activePositionsRef = React.useRef(positions);
129
- const activePositions = React.useMemo(() => {
130
- if (isDragging || isDraggingRef.current) return activePositionsRef.current;
131
- let result;
132
- if (!isKeyboardVisible || keyboardHeight <= 0) result = positions;else result = positions.map(p => getKeyboardAdjustedSheetY({
133
- sheetY: p,
134
- screenSize: effScreenSize,
135
- isKeyboardVisible,
136
- keyboardHeight,
137
- shouldTranslate: true,
138
- safeAreaTop: isWeb ? getWebVisualViewportOffsetTop() : safeAreaTopInset
139
- }));
140
- activePositionsRef.current = result;
141
- return result;
142
- }, [positions, isKeyboardVisible, keyboardHeight, effScreenSize, isDragging, safeAreaTopInset]);
143
- const keyboardOccludedHeight = getKeyboardOccludedHeight({
144
- frameSize: effectiveFrameSize,
145
- isKeyboardVisible,
146
- keyboardHeight,
147
- screenSize: effScreenSize,
148
- sheetY: position >= 0 ? activePositions[position] : void 0
149
- });
150
- const keyboardStableFrameHeight = isWebKbSheet && isKeyboardVisible && frameSize > 0 ? frameSize : isNativeKbFitSheet && isKeyboardVisible && preKeyboardFrameSize.current > 0 ? preKeyboardFrameSize.current : 0;
151
- const {
152
- useAnimatedNumber,
153
- useAnimatedNumberStyle
154
- } = animationDriver;
155
- const AnimatedView = animationDriver.View ?? View;
156
- useIsomorphicLayoutEffect(() => {
157
- if (!(sheetInsideSheet && open)) return;
158
- sheetInsideSheet(true);
159
- return () => {
160
- sheetInsideSheet(false);
161
- };
162
- }, [sheetInsideSheet, open]);
163
- const nextParentContext = React.useMemo(() => ({
164
- zIndex
165
- }), [zIndex]);
166
- const startPosition = useDidFinishSSR() && screenSize ? screenSize : hiddenSize;
167
- const animatedNumber = useAnimatedNumber(startPosition);
168
- const at = React.useRef(startPosition);
169
- const hasntMeasured = at.current === hiddenSize;
170
- const [disableAnimation, setDisableAnimation] = useState(hasntMeasured);
171
- const skipAdaptAnimation = React.useRef(false);
172
- if (controller?.skipNextAnimation) skipAdaptAnimation.current = true;
173
- const hasScrollView = React.useRef(false);
174
- const opacityFallbackTimer = React.useRef(null);
175
- const syncAnimatedPosition = useEvent(value => {
176
- at.current = value;
177
- scrollBridge.paneY = value;
178
- const minY = activePositions[0];
179
- const wasAtTop = scrollBridge.isAtTop;
180
- const nowAtTop = value <= minY + 5;
181
- if (wasAtTop === nowAtTop) return;
182
- scrollBridge.isAtTop = nowAtTop;
183
- if (nowAtTop) {
184
- if (scrollBridge.lockScrollAtTop) {
185
- if (scrollBridge.y > 0) {
186
- scrollBridge.forceScrollTo?.(0);
187
- scrollBridge.y = 0;
188
- }
189
- scrollBridge.scrollLockY = 0;
190
- scrollBridge.setScrollEnabled?.(false, 0);
191
- return;
192
- }
193
- if (scrollBridge.y > 0) {
194
- scrollBridge.forceScrollTo?.(0);
195
- scrollBridge.y = 0;
196
- }
197
- scrollBridge.scrollLockY = void 0;
198
- scrollBridge.setScrollEnabled?.(true);
199
- } else {
200
- scrollBridge.scrollLockY = 0;
201
- scrollBridge.setScrollEnabled?.(false);
202
- }
203
- });
204
- const setAnimatedPositionDirect = useEvent(value => {
205
- syncAnimatedPosition(value);
206
- animatedNumber.setValue(value, {
207
- type: "direct"
208
- });
209
- });
210
- const getAnimatedPosition = useEvent(() => {
211
- const value = animatedNumber.getValue();
212
- syncAnimatedPosition(value);
213
- return value;
214
- });
215
- function stopSpring() {
216
- animatedNumber.stop();
217
- if (scrollBridge.onFinishAnimate) {
218
- scrollBridge.onFinishAnimate();
219
- scrollBridge.onFinishAnimate = void 0;
220
- }
221
- }
222
- const animateTo = useEvent((position2, animationOverride) => {
223
- if (frameSize === 0) return;
224
- const closeTarget = isWeb ? Math.max(effScreenSize, getMaxViewportHeight()) : effScreenSize;
225
- let toValue = isHidden || position2 === -1 ? closeTarget : activePositions[position2];
226
- if (at.current === toValue) return;
227
- at.current = toValue;
228
- stopSpring();
229
- const isOpenAnimation = position2 !== -1 && !isHidden;
230
- if (opacityFallbackTimer.current) {
231
- clearTimeout(opacityFallbackTimer.current);
232
- opacityFallbackTimer.current = null;
233
- }
234
- const animationCompleteCallback = () => {
235
- if (at.current !== toValue) return;
236
- syncAnimatedPosition(toValue);
237
- if (opacityFallbackTimer.current) {
238
- clearTimeout(opacityFallbackTimer.current);
239
- opacityFallbackTimer.current = null;
240
- }
241
- if (!isOpenAnimation && !openRef.current) setOpacity(0);
242
- onAnimationComplete?.({
243
- open: isOpenAnimation
244
- });
245
- controller?.onAnimationComplete?.({
246
- open: isOpenAnimation
247
- });
248
- };
249
- if (!isOpenAnimation) opacityFallbackTimer.current = setTimeout(() => {
250
- opacityFallbackTimer.current = null;
251
- if (!openRef.current) setOpacity(0);
252
- }, 1e3);
253
- if (skipAdaptAnimation.current) {
254
- skipAdaptAnimation.current = false;
255
- animatedNumber.setValue(toValue, {
256
- type: "timing",
257
- duration: 0
258
- }, animationCompleteCallback);
259
- return;
260
- }
261
- animatedNumber.setValue(toValue, animationOverride || {
262
- type: "spring",
263
- ...transitionConfig
264
- }, animationCompleteCallback);
265
- });
266
- useIsomorphicLayoutEffect(() => {
267
- if (hasntMeasured && screenSize && frameSize) {
268
- at.current = screenSize;
269
- animatedNumber.setValue(screenSize, {
270
- type: "timing",
271
- duration: 0
272
- }, () => {
273
- syncAnimatedPosition(screenSize);
274
- setTimeout(() => {
275
- setDisableAnimation(false);
276
- }, 10);
277
- });
278
- return;
279
- }
280
- if (disableAnimation) return;
281
- if (isDraggingRef.current) return;
282
- if (!frameSize || !screenSize || isHidden || hasntMeasured && !open) return;
283
- animateTo(position);
284
- if (position === -1) {
285
- scrollBridge.scrollLock = false;
286
- scrollBridge.scrollStartY = -1;
287
- }
288
- if (open && position >= 0) {
289
- const isTopPosition = position === 0;
290
- scrollBridge.isAtTop = isTopPosition;
291
- if (isTopPosition) {
292
- scrollBridge.scrollLockY = void 0;
293
- scrollBridge.setScrollEnabled?.(true);
294
- } else {
295
- scrollBridge.scrollLockY = 0;
296
- scrollBridge.setScrollEnabled?.(false);
297
- }
298
- }
299
- }, [hasntMeasured, disableAnimation, isHidden, frameSize, screenSize, open, position]);
300
- const disableDrag = props.disableDrag ?? controller?.disableDrag;
301
- useThemeName();
302
- const [blockPan, setBlockPan] = React.useState(false);
303
- const panResponder = React.useMemo(() => {
304
- if (disableDrag) return;
305
- if (!frameSize) return;
306
- if (isShowingInnerSheet) return;
307
- const minY = activePositions[0];
308
- scrollBridge.paneMinY = minY;
309
- let startY = at.current;
310
- function setPanning(val) {
311
- setIsDragging(val);
312
- if (!sheetHiddenStyleSheet) {
313
- sheetHiddenStyleSheet = document.createElement("style");
314
- if (typeof document.head !== "undefined") document.head.appendChild(sheetHiddenStyleSheet);
315
- }
316
- if (!val) sheetHiddenStyleSheet.innerText = "";else sheetHiddenStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }";
317
- }
318
- const release = ({
319
- vy
320
- }) => {
321
- scrollBridge.setParentDragging(false);
322
- if (scrollBridge.scrollLock) return;
323
- isExternalDrag = false;
324
- previouslyScrolling = false;
325
- setPanning(false);
326
- const currentPos = at.current;
327
- const closestPoint = getSheetReleasePosition({
328
- positions: activePositions,
329
- projectedEnd: currentPos + frameSize * vy * .2,
330
- currentPosition: currentPos,
331
- frameSize,
332
- dismissOnSnapToBottom,
333
- snapPointsMode,
334
- isKeyboardVisible,
335
- isWeb
336
- });
337
- setPosition(closestPoint);
338
- animateTo(closestPoint);
339
- };
340
- const finish = (_e, state2) => {
341
- release({
342
- vy: state2.vy,
343
- dragAt: state2.dy
344
- });
345
- };
346
- let previouslyScrolling = false;
347
- const onMoveShouldSet = (e, {
348
- dy
349
- }) => {
350
- function getShouldSet() {
351
- if (e.target === providerProps.handleRef.current) return true;
352
- if (scrollBridge.scrollNodeTouched) return false;
353
- if (scrollBridge.hasScrollableContent === true) {
354
- if (scrollBridge.scrollLock) return false;
355
- const isScrolled = scrollBridge.y !== 0;
356
- const isDraggingUp = dy < 0;
357
- const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
358
- if (isScrolled) return false;
359
- if (isNearTop) {
360
- if (hasScrollView.current && isDraggingUp) return false;
361
- }
362
- }
363
- return Math.abs(dy) > 10;
364
- }
365
- const granted = getShouldSet();
366
- if (granted) scrollBridge.setParentDragging(true);
367
- return granted;
368
- };
369
- const grant = () => {
370
- setPanning(true);
371
- stopSpring();
372
- startY = getAnimatedPosition();
373
- };
374
- let isExternalDrag = false;
375
- scrollBridge.startPanDrag = () => {
376
- isExternalDrag = true;
377
- grant();
378
- };
379
- scrollBridge.drag = dy => {
380
- if (!isExternalDrag) {
381
- isExternalDrag = true;
382
- grant();
383
- }
384
- setAnimatedPositionDirect(resisted(dy + startY, minY));
385
- };
386
- scrollBridge.release = release;
387
- scrollBridge.snapToPosition = positionIndex => {
388
- isExternalDrag = false;
389
- setPanning(false);
390
- setPosition(positionIndex);
391
- animateTo(positionIndex);
392
- };
393
- return PanResponder.create({
394
- onMoveShouldSetPanResponder: onMoveShouldSet,
395
- onPanResponderTerminationRequest: () => false,
396
- onPanResponderGrant: grant,
397
- onPanResponderMove: (_e, {
398
- dy
399
- }) => {
400
- const to = resisted(dy + startY, minY);
401
- if (to <= minY) scrollBridge.setParentDragging(false);else scrollBridge.setParentDragging(true);
402
- setAnimatedPositionDirect(to);
403
- },
404
- onPanResponderEnd: finish,
405
- onPanResponderTerminate: finish,
406
- onPanResponderRelease: finish
407
- });
408
- }, [disableDrag, isShowingInnerSheet, animateTo, frameSize, activePositions, setPosition, dismissOnSnapToBottom, snapPointsMode]);
409
- React.useEffect(() => {
410
- if (isDragging || isHidden || !open || disableAnimation) return;
411
- if (!frameSize || !screenSize) return;
412
- animateTo(position, {
413
- type: "timing",
414
- duration: 250
415
- });
416
- }, [isKeyboardVisible, keyboardHeight]);
417
- const wasDragging = React.useRef(false);
418
- React.useEffect(() => {
419
- if (isDragging) {
420
- wasDragging.current = true;
421
- return;
422
- }
423
- if (!wasDragging.current) return;
424
- wasDragging.current = false;
425
- if (!frameSize || !screenSize || isHidden || !open) return;
426
- animateTo(position);
427
- }, [isDragging]);
428
- React.useEffect(() => {
429
- if (!open && isKeyboardVisible) {
430
- dismissKeyboard();
431
- pauseKeyboardHandler.current = false;
432
- flushPendingHide();
433
- }
434
- }, [open]);
435
- const {
436
- panGesture,
437
- panGestureRef,
438
- gestureHandlerEnabled
439
- } = useGestureHandlerPan({
440
- positions: activePositions,
441
- frameSize,
442
- setPosition,
443
- animateTo,
444
- stopSpring,
445
- scrollBridge,
446
- setIsDragging,
447
- getCurrentPosition: getAnimatedPosition,
448
- resisted,
449
- disableDrag,
450
- isShowingInnerSheet,
451
- setAnimatedPosition: setAnimatedPositionDirect,
452
- dismissOnSnapToBottom,
453
- snapPointsMode,
454
- isKeyboardVisible,
455
- pauseKeyboardHandler
456
- });
457
- const ignoreLayoutForKeyboard = useEvent(() => isWeb && moveOnKeyboardChange && getWebKeyboardResizeHeight() >= MIN_KEYBOARD_HEIGHT);
458
- const handleAnimationViewLayout = useEvent(e => {
459
- if (!open && stableFrameSize.current !== 0) return;
460
- const layoutHeight = e.nativeEvent?.layout.height;
461
- if (ignoreLayoutForKeyboard() && frameSize > 0) return;
462
- const next = modal ? Math.min(layoutHeight, getStableViewportHeight()) : layoutHeight;
463
- if (!next) return;
464
- setFrameSize(Math.round(next));
465
- });
466
- const handleMaxContentViewLayout = React.useCallback(e => {
467
- if (ignoreLayoutForKeyboard() && screenSize > 0) return;
468
- const next = Math.min(e.nativeEvent?.layout.height, getStableViewportHeight());
469
- if (!next) return;
470
- setMaxContentSize(Math.round(next));
471
- }, [ignoreLayoutForKeyboard, screenSize]);
472
- const animatedStyle = useAnimatedNumberStyle(animatedNumber, React.useCallback(val => {
473
- "worklet";
474
-
475
- return {
476
- transform: [{
477
- translateY: frameSize === 0 ? hiddenSize : val
478
- }]
479
- };
480
- }, [frameSize]));
481
- const [opacity, setOpacity] = React.useState(open ? 1 : 0);
482
- if (open && opacity === 0) {
483
- setOpacity(1);
484
- if (opacityFallbackTimer.current) {
485
- clearTimeout(opacityFallbackTimer.current);
486
- opacityFallbackTimer.current = null;
487
- }
488
- }
489
- const forcedContentHeight = hasFit ? void 0 : snapPointsMode === "percent" ? `${maxSnapPoint}${isWeb ? modal ? "dvh" : "%" : "%"}` : maxSnapPoint;
490
- const setHasScrollView = React.useCallback(val => {
491
- hasScrollView.current = val;
492
- }, []);
493
- let contents = /* @__PURE__ */jsx(LayoutMeasurementController, {
494
- disable: !open,
495
- children: /* @__PURE__ */jsx(ParentSheetContext.Provider, {
496
- value: nextParentContext,
497
- children: /* @__PURE__ */jsx(SheetProvider, {
498
- ...providerProps,
499
- keyboardOccludedHeight,
500
- isKeyboardVisible,
501
- keyboardStableFrameHeight,
502
- setHasScrollView,
503
- children: /* @__PURE__ */jsxs(GestureSheetProvider, {
504
- isDragging,
505
- blockPan,
506
- setBlockPan,
507
- panGesture,
508
- panGestureRef,
509
- children: [/* @__PURE__ */jsx(AnimatePresence, {
510
- custom: {
511
- open
512
- },
513
- children: shouldHideParentSheet || !open ? null : overlayComponent
514
- }), snapPointsMode !== "percent" && /* @__PURE__ */jsx(View$1, {
515
- style: {
516
- opacity: 0,
517
- position: "absolute",
518
- top: 0,
519
- left: 0,
520
- right: 0,
521
- bottom: 0,
522
- pointerEvents: "none"
523
- },
524
- onLayout: handleMaxContentViewLayout
525
- }), /* @__PURE__ */jsx(AnimatedView, {
526
- ref,
527
- onLayout: handleAnimationViewLayout,
528
- transition: isDragging || disableAnimation ? null : transition,
529
- disableClassName: true,
530
- style: [{
531
- position: "absolute",
532
- zIndex,
533
- width: "100%",
534
- height: forcedContentHeight,
535
- minHeight: forcedContentHeight,
536
- opacity: shouldHideParentSheet ? 0 : disableTransparencyHide ? 1 : opacity,
537
- ...((shouldHideParentSheet || !open) && {
538
- pointerEvents: "none"
539
- })
540
- }, animatedStyle],
541
- children: gestureHandlerEnabled && panGesture ? /* @__PURE__ */jsx(GestureDetectorWrapper, {
542
- gesture: panGesture,
543
- style: {
544
- flex: 1
545
- },
546
- children: props.children
547
- }) : /* @__PURE__ */jsx(View$1, {
548
- ...panResponder?.panHandlers,
549
- style: {
550
- flex: 1,
551
- width: "100%",
552
- height: "100%"
553
- },
554
- children: props.children
555
- })
556
- })]
557
- })
558
- })
559
- })
560
- });
561
- const shouldMountChildren = unmountChildrenWhenHidden ? !!opacity : true;
562
- if (modal) {
563
- const RNGHRoot = getGestureHandlerState().RootView;
564
- const mountedContents = shouldMountChildren ? /* @__PURE__ */jsx(ContainerComponent, {
565
- children: contents
566
- }) : null;
567
- const modalContents = /* @__PURE__ */jsx(Portal, {
568
- stackZIndex: zIndex,
569
- ...portalProps,
570
- children: mountedContents && RNGHRoot ? /* @__PURE__ */jsx(RNGHRoot, {
571
- style: open ? rnghRootStyleOpen : rnghRootStyleClosed,
572
- children: mountedContents
573
- }) : mountedContents
574
- });
575
- if (isWeb) return modalContents;
576
- return /* @__PURE__ */jsx(SheetInsideSheetContext.Provider, {
577
- value: onInnerSheet,
578
- children: modalContents
579
- });
580
- }
581
- return contents;
35
+ const sheetEscapeLayers = [];
36
+ const SheetImplementationCustom = createRefComponent(function SheetImplementationCustom2(props, forwardedRef) {
37
+ const parentSheet = React.useContext(ParentSheetContext);
38
+ const safeAreaTopInset = useSafeAreaInsets()?.top ?? 0;
39
+ const { transition, transitionConfig: transitionConfigProp, modal = false, zIndex = parentSheet.zIndex + 1, moveOnKeyboardChange = false, unmountChildrenWhenHidden = false, disableHideWhenClosed = false, portalProps, containerComponent: ContainerComponent = React.Fragment, onTransition } = props;
40
+ const state = useSheetOpenState(props);
41
+ const providerProps = useSheetProviderProps(props, state);
42
+ const { frameSize, setFrameSize, dismissOnSnapToBottom, snapPoints, snapPointsMode, hasFit, position, setPosition, scrollBridge, screenSize, setMaxContentSize, maxSnapPoint } = providerProps;
43
+ const { open, controller, isHidden } = state;
44
+ const openRef = React.useRef(open);
45
+ openRef.current = open;
46
+ const ref = useComposedRefs(forwardedRef, React.useRef(void 0), providerProps.contentRef);
47
+ const animationDriver = useAnimationDriver();
48
+ const transitionConfig = (() => {
49
+ if (transitionConfigProp) return transitionConfigProp;
50
+ const timing = (transition ? getTransitionResolver()?.resolve(transition, { animations: animationDriver.animations }) : null)?.all?.timing;
51
+ if (!timing) return null;
52
+ if (timing.kind === "timing") return {
53
+ type: "timing",
54
+ duration: timing.durationMs
55
+ };
56
+ return {
57
+ type: "spring",
58
+ stiffness: timing.stiffness,
59
+ damping: timing.damping,
60
+ mass: timing.mass
61
+ };
62
+ })();
63
+ const [isShowingInnerSheet, setIsShowingInnerSheet] = React.useState(false);
64
+ const shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet && needsPortalRepropagation();
65
+ const sheetInsideSheet = React.useContext(SheetInsideSheetContext);
66
+ const onInnerSheet = React.useCallback((hasChild) => {
67
+ setIsShowingInnerSheet(hasChild);
68
+ }, []);
69
+ const { keyboardHeight, isKeyboardVisible, dismissKeyboard, pauseKeyboardHandler, flushPendingHide } = useKeyboardControllerSheet({ enabled: Boolean(moveOnKeyboardChange) });
70
+ const stableFrameSize = React.useRef(frameSize);
71
+ React.useEffect(() => {
72
+ if (open && frameSize) stableFrameSize.current = frameSize;
73
+ }, [open, frameSize]);
74
+ const isWebKbSheet = isWeb && hasFit && moveOnKeyboardChange;
75
+ const isNativeKbFitSheet = !isWeb && hasFit && Boolean(moveOnKeyboardChange);
76
+ const preKeyboardFrameSize = React.useRef(0);
77
+ React.useEffect(() => {
78
+ if (isNativeKbFitSheet && open && !isKeyboardVisible && frameSize > 0) preKeyboardFrameSize.current = frameSize;
79
+ }, [
80
+ isNativeKbFitSheet,
81
+ open,
82
+ isKeyboardVisible,
83
+ frameSize
84
+ ]);
85
+ const effScreenSize = isWebKbSheet ? getStableViewportHeight() : screenSize;
86
+ const effectiveFrameSize = open ? frameSize : stableFrameSize.current || frameSize;
87
+ const positions = React.useMemo(() => snapPoints.map((point) => getYPositions(snapPointsMode, point, effScreenSize, effectiveFrameSize)), [
88
+ effScreenSize,
89
+ effectiveFrameSize,
90
+ snapPoints,
91
+ snapPointsMode
92
+ ]);
93
+ const [isDragging, setIsDragging_] = React.useState(false);
94
+ const isDraggingRef = React.useRef(false);
95
+ const setIsDragging = React.useCallback((val) => {
96
+ isDraggingRef.current = val;
97
+ pauseKeyboardHandler.current = val;
98
+ setIsDragging_(val);
99
+ if (!val) flushPendingHide();
100
+ }, [pauseKeyboardHandler, flushPendingHide]);
101
+ const activePositionsRef = React.useRef(positions);
102
+ const activePositions = React.useMemo(() => {
103
+ if (isDragging || isDraggingRef.current) return activePositionsRef.current;
104
+ let result;
105
+ if (!isKeyboardVisible || keyboardHeight <= 0) result = positions;
106
+ else result = positions.map((p) => getKeyboardAdjustedSheetY({
107
+ sheetY: p,
108
+ screenSize: effScreenSize,
109
+ isKeyboardVisible,
110
+ keyboardHeight,
111
+ shouldTranslate: true,
112
+ safeAreaTop: isWeb ? getWebVisualViewportOffsetTop() : safeAreaTopInset
113
+ }));
114
+ activePositionsRef.current = result;
115
+ return result;
116
+ }, [
117
+ positions,
118
+ isKeyboardVisible,
119
+ keyboardHeight,
120
+ effScreenSize,
121
+ isDragging,
122
+ safeAreaTopInset
123
+ ]);
124
+ const keyboardOccludedHeight = getKeyboardOccludedHeight({
125
+ frameSize: effectiveFrameSize,
126
+ isKeyboardVisible,
127
+ keyboardHeight,
128
+ screenSize: effScreenSize,
129
+ sheetY: position >= 0 ? activePositions[position] : void 0
130
+ });
131
+ const keyboardStableFrameHeight = isWebKbSheet && isKeyboardVisible && frameSize > 0 ? frameSize : isNativeKbFitSheet && isKeyboardVisible && preKeyboardFrameSize.current > 0 ? preKeyboardFrameSize.current : 0;
132
+ const AnimatedView = animationDriver.View ?? View;
133
+ useIsomorphicLayoutEffect(() => {
134
+ if (!(sheetInsideSheet && open)) return;
135
+ sheetInsideSheet(true);
136
+ return () => {
137
+ sheetInsideSheet(false);
138
+ };
139
+ }, [sheetInsideSheet, open]);
140
+ const nextParentContext = React.useMemo(() => ({ zIndex }), [zIndex]);
141
+ const startPosition = useDidFinishSSR() && screenSize ? screenSize : hiddenSize;
142
+ const animatedNumber = useAnimatedNumber(startPosition);
143
+ const at = React.useRef(startPosition);
144
+ const hasntMeasured = at.current === hiddenSize;
145
+ const [disableAnimation, setDisableAnimation] = useState(hasntMeasured);
146
+ const skipAdaptAnimation = React.useRef(false);
147
+ if (controller?.skipNextAnimation) skipAdaptAnimation.current = true;
148
+ const hasScrollView = React.useRef(false);
149
+ const lastPositionIndexRef = React.useRef(-1);
150
+ const pendingTransitionRef = React.useRef(null);
151
+ const emitTransition = useEvent((phase, event, finished) => {
152
+ const e = {
153
+ phase,
154
+ cause: event.cause,
155
+ position: event.position
156
+ };
157
+ if (phase === "end") e.finished = finished;
158
+ onTransition?.(e);
159
+ controller?.onTransition?.(e);
160
+ });
161
+ const syncAnimatedPosition = useEvent((value) => {
162
+ at.current = value;
163
+ scrollBridge.paneY = value;
164
+ const minY = activePositions[0];
165
+ const wasAtTop = scrollBridge.isAtTop;
166
+ const nowAtTop = value <= minY + 5;
167
+ if (wasAtTop === nowAtTop) return;
168
+ scrollBridge.isAtTop = nowAtTop;
169
+ if (nowAtTop) {
170
+ if (scrollBridge.lockScrollAtTop) {
171
+ if (scrollBridge.y > 0) {
172
+ scrollBridge.forceScrollTo?.(0);
173
+ scrollBridge.y = 0;
174
+ }
175
+ scrollBridge.scrollLockY = 0;
176
+ scrollBridge.setScrollEnabled?.(false, 0);
177
+ return;
178
+ }
179
+ if (scrollBridge.y > 0) {
180
+ scrollBridge.forceScrollTo?.(0);
181
+ scrollBridge.y = 0;
182
+ }
183
+ scrollBridge.scrollLockY = void 0;
184
+ scrollBridge.setScrollEnabled?.(true);
185
+ } else {
186
+ scrollBridge.scrollLockY = 0;
187
+ scrollBridge.setScrollEnabled?.(false);
188
+ }
189
+ });
190
+ const setAnimatedPositionDirect = useEvent((value) => {
191
+ syncAnimatedPosition(value);
192
+ animatedNumber.setValue(value, { type: "direct" });
193
+ });
194
+ const getAnimatedPosition = useEvent(() => {
195
+ const value = animatedNumber.getValue();
196
+ syncAnimatedPosition(value);
197
+ return value;
198
+ });
199
+ function stopSpring() {
200
+ animatedNumber.stop();
201
+ if (scrollBridge.onFinishAnimate) {
202
+ scrollBridge.onFinishAnimate();
203
+ scrollBridge.onFinishAnimate = void 0;
204
+ }
205
+ }
206
+ const animateTo = useEvent((position2, animationOverride) => {
207
+ if (frameSize === 0) return;
208
+ const closeTarget = isWeb ? Math.max(effScreenSize, getMaxViewportHeight()) : effScreenSize;
209
+ const isDismissPosition = dismissOnSnapToBottom && position2 === activePositions.length - 1;
210
+ const isOpenAnimation = position2 !== -1 && !isHidden && !isDismissPosition;
211
+ const toValue = isOpenAnimation ? activePositions[position2] : closeTarget;
212
+ if (at.current === toValue) {
213
+ if (isDismissPosition) {
214
+ if (pendingTransitionRef.current) {
215
+ emitTransition("end", pendingTransitionRef.current, false);
216
+ pendingTransitionRef.current = null;
217
+ }
218
+ stopSpring();
219
+ const event2 = {
220
+ cause: "close",
221
+ position: toValue
222
+ };
223
+ lastPositionIndexRef.current = -1;
224
+ emitTransition("start", event2);
225
+ syncAnimatedPosition(toValue);
226
+ setIsFullyClosed(true);
227
+ emitTransition("end", event2, true);
228
+ }
229
+ return;
230
+ }
231
+ at.current = toValue;
232
+ const cause = !isOpenAnimation ? "close" : lastPositionIndexRef.current < 0 ? "open" : "snap";
233
+ lastPositionIndexRef.current = isOpenAnimation ? position2 : -1;
234
+ const event = {
235
+ cause,
236
+ position: toValue
237
+ };
238
+ if (pendingTransitionRef.current) {
239
+ emitTransition("end", pendingTransitionRef.current, false);
240
+ pendingTransitionRef.current = null;
241
+ }
242
+ stopSpring();
243
+ const animationCompleteCallback = () => {
244
+ if (at.current !== toValue) return;
245
+ syncAnimatedPosition(toValue);
246
+ pendingTransitionRef.current = null;
247
+ if (!isOpenAnimation && !openRef.current) setIsFullyClosed(true);
248
+ emitTransition("end", event, true);
249
+ };
250
+ pendingTransitionRef.current = event;
251
+ emitTransition("start", event);
252
+ if (skipAdaptAnimation.current) {
253
+ skipAdaptAnimation.current = false;
254
+ animatedNumber.setValue(toValue, {
255
+ type: "timing",
256
+ duration: 0
257
+ }, animationCompleteCallback);
258
+ return;
259
+ }
260
+ const resolvedConfig = animationOverride || {
261
+ type: "spring",
262
+ ...transitionConfig
263
+ };
264
+ const springConfig = !resolvedConfig.type || resolvedConfig.type === "spring" ? {
265
+ restDisplacementThreshold: 1,
266
+ restSpeedThreshold: 10,
267
+ energyThreshold: 1e-5,
268
+ ...resolvedConfig
269
+ } : resolvedConfig;
270
+ animatedNumber.setValue(toValue, springConfig, animationCompleteCallback);
271
+ });
272
+ useIsomorphicLayoutEffect(() => {
273
+ if (hasntMeasured && screenSize && frameSize) {
274
+ at.current = screenSize;
275
+ animatedNumber.setValue(screenSize, {
276
+ type: "timing",
277
+ duration: 0
278
+ }, () => {
279
+ syncAnimatedPosition(screenSize);
280
+ setTimeout(() => {
281
+ setDisableAnimation(false);
282
+ }, 10);
283
+ });
284
+ return;
285
+ }
286
+ if (disableAnimation) return;
287
+ if (isDraggingRef.current) return;
288
+ if (!frameSize || !screenSize || isHidden || hasntMeasured && !open) return;
289
+ animateTo(position);
290
+ if (position === -1) {
291
+ scrollBridge.scrollLock = false;
292
+ scrollBridge.scrollStartY = -1;
293
+ }
294
+ if (open && position >= 0) {
295
+ const isTopPosition = position === 0;
296
+ scrollBridge.isAtTop = isTopPosition;
297
+ if (isTopPosition) {
298
+ scrollBridge.scrollLockY = void 0;
299
+ scrollBridge.setScrollEnabled?.(true);
300
+ } else {
301
+ scrollBridge.scrollLockY = 0;
302
+ scrollBridge.setScrollEnabled?.(false);
303
+ }
304
+ }
305
+ }, [
306
+ hasntMeasured,
307
+ disableAnimation,
308
+ isHidden,
309
+ frameSize,
310
+ screenSize,
311
+ open,
312
+ position
313
+ ]);
314
+ const disableDrag = props.disableDrag ?? controller?.disableDrag;
315
+ useThemeName();
316
+ const [blockPan, setBlockPan] = React.useState(false);
317
+ const panConfig = React.useMemo(() => {
318
+ if (disableDrag) return null;
319
+ if (!frameSize) return null;
320
+ if (isShowingInnerSheet) return null;
321
+ const minY = activePositions[0];
322
+ scrollBridge.paneMinY = minY;
323
+ let startY = at.current;
324
+ function setPanning(val) {
325
+ setIsDragging(val);
326
+ if (!sheetHiddenStyleSheet) {
327
+ sheetHiddenStyleSheet = document.createElement("style");
328
+ if (typeof document.head !== "undefined") document.head.appendChild(sheetHiddenStyleSheet);
329
+ }
330
+ if (!val) sheetHiddenStyleSheet.innerText = "";
331
+ else sheetHiddenStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }";
332
+ }
333
+ const release = ({ vy }) => {
334
+ scrollBridge.setParentDragging(false);
335
+ if (scrollBridge.scrollLock) return;
336
+ isExternalDrag = false;
337
+ previouslyScrolling = false;
338
+ setPanning(false);
339
+ const currentPos = at.current;
340
+ const closestPoint = getSheetReleasePosition({
341
+ positions: activePositions,
342
+ projectedEnd: currentPos + frameSize * vy * .2,
343
+ currentPosition: currentPos,
344
+ frameSize,
345
+ dismissOnSnapToBottom,
346
+ snapPointsMode,
347
+ isKeyboardVisible,
348
+ isWeb
349
+ });
350
+ setPosition(closestPoint);
351
+ animateTo(closestPoint);
352
+ };
353
+ const finish = (_e, state2) => {
354
+ release({
355
+ vy: state2.vy,
356
+ dragAt: state2.dy
357
+ });
358
+ };
359
+ let previouslyScrolling = false;
360
+ const onMoveShouldSet = (e, { dy }) => {
361
+ function getShouldSet() {
362
+ if (e.target === providerProps.handleRef.current) return true;
363
+ if (scrollBridge.scrollNodeTouched) return false;
364
+ if (scrollBridge.hasScrollableContent === true) {
365
+ if (scrollBridge.scrollLock) return false;
366
+ const isScrolled = scrollBridge.y !== 0;
367
+ const isDraggingUp = dy < 0;
368
+ const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
369
+ if (isScrolled) return false;
370
+ if (isNearTop) {
371
+ if (hasScrollView.current && isDraggingUp) return false;
372
+ }
373
+ }
374
+ return Math.abs(dy) > 10;
375
+ }
376
+ const granted = getShouldSet();
377
+ if (granted) scrollBridge.setParentDragging(true);
378
+ return granted;
379
+ };
380
+ const grant = () => {
381
+ setPanning(true);
382
+ stopSpring();
383
+ startY = getAnimatedPosition();
384
+ };
385
+ let isExternalDrag = false;
386
+ scrollBridge.startPanDrag = () => {
387
+ isExternalDrag = true;
388
+ grant();
389
+ };
390
+ scrollBridge.drag = (dy) => {
391
+ if (!isExternalDrag) {
392
+ isExternalDrag = true;
393
+ grant();
394
+ }
395
+ setAnimatedPositionDirect(resisted(dy + startY, minY));
396
+ };
397
+ scrollBridge.release = release;
398
+ scrollBridge.snapToPosition = (positionIndex) => {
399
+ isExternalDrag = false;
400
+ setPanning(false);
401
+ setPosition(positionIndex);
402
+ animateTo(positionIndex);
403
+ };
404
+ return {
405
+ onMoveShouldSetPanResponder: onMoveShouldSet,
406
+ onPanResponderTerminationRequest: () => false,
407
+ onPanResponderGrant: grant,
408
+ onPanResponderMove: (_e, { dy }) => {
409
+ const to = resisted(dy + startY, minY);
410
+ if (to <= minY) scrollBridge.setParentDragging(false);
411
+ else scrollBridge.setParentDragging(true);
412
+ setAnimatedPositionDirect(to);
413
+ },
414
+ onPanResponderEnd: finish,
415
+ onPanResponderTerminate: finish,
416
+ onPanResponderRelease: finish
417
+ };
418
+ }, [
419
+ disableDrag,
420
+ isShowingInnerSheet,
421
+ animateTo,
422
+ frameSize,
423
+ activePositions,
424
+ setPosition,
425
+ dismissOnSnapToBottom,
426
+ snapPointsMode
427
+ ]);
428
+ React.useEffect(() => {
429
+ if (isDragging || isHidden || !open || disableAnimation) return;
430
+ if (!frameSize || !screenSize) return;
431
+ animateTo(position, {
432
+ type: "timing",
433
+ duration: 250
434
+ });
435
+ }, [isKeyboardVisible, keyboardHeight]);
436
+ const wasDragging = React.useRef(false);
437
+ React.useEffect(() => {
438
+ if (isDragging) {
439
+ wasDragging.current = true;
440
+ return;
441
+ }
442
+ if (!wasDragging.current) return;
443
+ wasDragging.current = false;
444
+ if (!frameSize || !screenSize || isHidden || !open) return;
445
+ animateTo(position);
446
+ }, [isDragging]);
447
+ React.useEffect(() => {
448
+ if (!open && isKeyboardVisible) {
449
+ dismissKeyboard();
450
+ pauseKeyboardHandler.current = false;
451
+ flushPendingHide();
452
+ }
453
+ }, [open]);
454
+ React.useEffect(() => {
455
+ if (!isWeb || !modal || !open || shouldHideParentSheet) return;
456
+ const layer = {};
457
+ sheetEscapeLayers.push(layer);
458
+ const onKeyDown = (event) => {
459
+ if (event.key === "Escape") {
460
+ if (sheetEscapeLayers[sheetEscapeLayers.length - 1] === layer) state.setOpen(false);
461
+ }
462
+ };
463
+ document.addEventListener("keydown", onKeyDown);
464
+ return () => {
465
+ const index = sheetEscapeLayers.indexOf(layer);
466
+ if (index > -1) sheetEscapeLayers.splice(index, 1);
467
+ document.removeEventListener("keydown", onKeyDown);
468
+ };
469
+ }, [
470
+ modal,
471
+ open,
472
+ shouldHideParentSheet,
473
+ state.setOpen
474
+ ]);
475
+ const { panGesture, panGestureRef, gestureHandlerEnabled } = useGestureHandlerPan({
476
+ positions: activePositions,
477
+ frameSize,
478
+ setPosition,
479
+ animateTo,
480
+ stopSpring,
481
+ scrollBridge,
482
+ setIsDragging,
483
+ getCurrentPosition: getAnimatedPosition,
484
+ resisted,
485
+ disableDrag,
486
+ isShowingInnerSheet,
487
+ setAnimatedPosition: setAnimatedPositionDirect,
488
+ dismissOnSnapToBottom,
489
+ snapPointsMode,
490
+ isKeyboardVisible,
491
+ pauseKeyboardHandler
492
+ });
493
+ const ignoreLayoutForKeyboard = useEvent(() => isWeb && moveOnKeyboardChange && getWebKeyboardResizeHeight() >= MIN_KEYBOARD_HEIGHT);
494
+ const handleAnimationViewLayout = useEvent((e) => {
495
+ if (!open && stableFrameSize.current !== 0) return;
496
+ const layoutHeight = e.nativeEvent?.layout.height;
497
+ if (ignoreLayoutForKeyboard() && frameSize > 0) return;
498
+ const next = modal ? Math.min(layoutHeight, getStableViewportHeight()) : layoutHeight;
499
+ if (!next) return;
500
+ setFrameSize(Math.round(next));
501
+ });
502
+ const handleMaxContentViewLayout = React.useCallback((e) => {
503
+ if (ignoreLayoutForKeyboard() && screenSize > 0) return;
504
+ const next = Math.min(e.nativeEvent?.layout.height, getStableViewportHeight());
505
+ if (!next) return;
506
+ setMaxContentSize(Math.round(next));
507
+ }, [ignoreLayoutForKeyboard, screenSize]);
508
+ const animatedStyle = useAnimatedNumberStyle(animatedNumber, React.useCallback((val) => {
509
+ "worklet";
510
+ return { transform: [{ translateY: frameSize === 0 ? hiddenSize : val }] };
511
+ }, [frameSize]));
512
+ const [isFullyClosed, setIsFullyClosed] = React.useState(false);
513
+ if (open && isFullyClosed) setIsFullyClosed(false);
514
+ const hasEverOpened = React.useRef(open);
515
+ if (open) hasEverOpened.current = true;
516
+ const isVisuallyActive = open || hasEverOpened.current && !isFullyClosed;
517
+ const applyHidden = shouldHideParentSheet || isFullyClosed && !disableHideWhenClosed;
518
+ const forcedContentHeight = hasFit ? void 0 : snapPointsMode === "percent" ? `${maxSnapPoint}${isWeb ? modal ? "dvh" : "%" : "%"}` : maxSnapPoint;
519
+ const setHasScrollView = React.useCallback((val) => {
520
+ hasScrollView.current = val;
521
+ }, []);
522
+ const animatedPositionValue = React.useMemo(() => ({
523
+ value: animatedNumber,
524
+ screenSize: effScreenSize,
525
+ frameSize,
526
+ snapOffsets: activePositions,
527
+ minY: activePositions[0] ?? 0
528
+ }), [
529
+ animatedNumber,
530
+ effScreenSize,
531
+ frameSize,
532
+ activePositions
533
+ ]);
534
+ const { overlayChildren, animatedChildren } = React.useMemo(() => partitionSheetChildren(props.children), [props.children]);
535
+ let contents = /* @__PURE__ */ jsx(LayoutMeasurementController, {
536
+ disable: !open,
537
+ children: /* @__PURE__ */ jsx(ParentSheetContext.Provider, {
538
+ value: nextParentContext,
539
+ children: /* @__PURE__ */ jsx(SheetProvider, {
540
+ ...providerProps,
541
+ keyboardOccludedHeight,
542
+ isKeyboardVisible,
543
+ keyboardStableFrameHeight,
544
+ setHasScrollView,
545
+ children: /* @__PURE__ */ jsx(GestureSheetProvider, {
546
+ isDragging,
547
+ blockPan,
548
+ setBlockPan,
549
+ panGesture,
550
+ panGestureRef,
551
+ children: /* @__PURE__ */ jsxs(SheetAnimatedPositionContext.Provider, {
552
+ value: animatedPositionValue,
553
+ children: [
554
+ /* @__PURE__ */ jsx(SheetOverlayLayerContext.Provider, {
555
+ value: true,
556
+ children: /* @__PURE__ */ jsx(AnimatePresence, {
557
+ custom: { open },
558
+ children: shouldHideParentSheet || !open ? null : overlayChildren
559
+ })
560
+ }),
561
+ snapPointsMode !== "percent" && /* @__PURE__ */ jsx(View, {
562
+ opacity: 0,
563
+ position: "absolute",
564
+ inset: 0,
565
+ pointerEvents: "none",
566
+ onLayout: handleMaxContentViewLayout
567
+ }),
568
+ /* @__PURE__ */ jsx(AnimatedView, {
569
+ ref,
570
+ onLayout: handleAnimationViewLayout,
571
+ transition: isDragging || disableAnimation ? null : transition,
572
+ disableClassName: true,
573
+ style: [{
574
+ position: "absolute",
575
+ zIndex,
576
+ width: "100%",
577
+ height: forcedContentHeight,
578
+ minHeight: forcedContentHeight,
579
+ ...applyHidden && { display: "none" },
580
+ ...(shouldHideParentSheet || !open) && { pointerEvents: "none" }
581
+ }, animatedStyle],
582
+ children: /* @__PURE__ */ jsx(SheetDragSurface, {
583
+ gestureHandlerEnabled,
584
+ panGesture,
585
+ panConfig,
586
+ children: animatedChildren
587
+ })
588
+ })
589
+ ]
590
+ })
591
+ })
592
+ })
593
+ })
594
+ });
595
+ const shouldMountChildren = unmountChildrenWhenHidden ? !isFullyClosed : true;
596
+ if (modal) {
597
+ const RNGHRoot = getGestureHandlerState().RootView;
598
+ const mountedContents = shouldMountChildren ? /* @__PURE__ */ jsx(ContainerComponent, { children: contents }) : null;
599
+ const modalContents = /* @__PURE__ */ jsx(Portal, {
600
+ stackZIndex: zIndex,
601
+ hidden: !isVisuallyActive,
602
+ ...portalProps,
603
+ children: mountedContents && RNGHRoot ? /* @__PURE__ */ jsx(RNGHRoot, {
604
+ style: open ? rnghRootStyleOpen : rnghRootStyleClosed,
605
+ children: mountedContents
606
+ }) : mountedContents
607
+ });
608
+ if (isWeb) return modalContents;
609
+ return /* @__PURE__ */ jsx(SheetInsideSheetContext.Provider, {
610
+ value: onInnerSheet,
611
+ children: modalContents
612
+ });
613
+ }
614
+ return contents;
582
615
  });
616
+ function isSheetOverlayComponent(type) {
617
+ let staticConfig = type?.staticConfig;
618
+ while (staticConfig) {
619
+ if (staticConfig[SHEET_OVERLAY_MARKER]) return true;
620
+ staticConfig = staticConfig.parentStaticConfig;
621
+ }
622
+ return false;
623
+ }
624
+ function partitionSheetChildren(children) {
625
+ const overlayChildren = [];
626
+ const animatedChildren = [];
627
+ React.Children.forEach(children, (child) => {
628
+ if (!React.isValidElement(child)) {
629
+ animatedChildren.push(child);
630
+ return;
631
+ }
632
+ if (isSheetOverlayComponent(child.type)) {
633
+ overlayChildren.push(child);
634
+ return;
635
+ }
636
+ animatedChildren.push(child);
637
+ });
638
+ return {
639
+ overlayChildren,
640
+ animatedChildren
641
+ };
642
+ }
583
643
  function getYPositions(mode, point, screenSize, frameSize) {
584
- if (!screenSize || !frameSize) return 0;
585
- if (mode === "mixed") {
586
- if (typeof point === "number") return screenSize - Math.min(screenSize, Math.max(0, point));
587
- if (point === "fit") return screenSize - Math.min(screenSize, frameSize);
588
- if (point.endsWith("%")) {
589
- const pct2 = Math.min(100, Math.max(0, Number(point.slice(0, -1)))) / 100;
590
- if (Number.isNaN(pct2)) {
591
- console.warn("Invalid snapPoint percentage string");
592
- return 0;
593
- }
594
- return Math.round(screenSize - pct2 * screenSize);
595
- }
596
- console.warn("Invalid snapPoint unknown value");
597
- return 0;
598
- }
599
- if (mode === "fit") {
600
- if (point === 0) return screenSize;
601
- return screenSize - Math.min(screenSize, frameSize);
602
- }
603
- if (mode === "constant" && typeof point === "number") return screenSize - Math.min(screenSize, Math.max(0, point));
604
- const pct = Math.min(100, Math.max(0, Number(point))) / 100;
605
- if (Number.isNaN(pct)) {
606
- console.warn("Invalid snapPoint percentage");
607
- return 0;
608
- }
609
- return Math.round(screenSize - pct * screenSize);
644
+ if (!screenSize || !frameSize) return 0;
645
+ if (mode === "mixed") {
646
+ if (typeof point === "number") return screenSize - Math.min(screenSize, Math.max(0, point));
647
+ if (point === "fit") return screenSize - Math.min(screenSize, frameSize);
648
+ if (point.endsWith("%")) {
649
+ const pct2 = Math.min(100, Math.max(0, Number(point.slice(0, -1)))) / 100;
650
+ if (Number.isNaN(pct2)) {
651
+ console.warn(formatDiagnostic("TAMAGUI_SHEET_SNAP_POINT", "Sheet", "snapPoints contains an invalid percentage string", "Use \"fit\", a pixel number, or a percentage such as \"50%\"", "snapPoint", point));
652
+ return 0;
653
+ }
654
+ return Math.round(screenSize - pct2 * screenSize);
655
+ }
656
+ console.warn(formatDiagnostic("TAMAGUI_SHEET_SNAP_POINT", "Sheet", "snapPoints contains an unsupported mixed-mode value", "Use \"fit\", a pixel number, or a percentage such as \"50%\"", "snapPoint", point));
657
+ return 0;
658
+ }
659
+ if (mode === "fit") {
660
+ if (point === 0) return screenSize;
661
+ return screenSize - Math.min(screenSize, frameSize);
662
+ }
663
+ if (mode === "constant" && typeof point === "number") return screenSize - Math.min(screenSize, Math.max(0, point));
664
+ const pct = Math.min(100, Math.max(0, Number(point))) / 100;
665
+ if (Number.isNaN(pct)) {
666
+ console.warn(formatDiagnostic("TAMAGUI_SHEET_SNAP_POINT", "Sheet", "snapPoints contains a value that cannot be converted to a percentage", "Use a numeric percentage such as 50", "snapPoint", point));
667
+ return 0;
668
+ }
669
+ return Math.round(screenSize - pct * screenSize);
610
670
  }
611
- export { SheetImplementationCustom };
671
+
672
+ export { SheetImplementationCustom, isSheetOverlayComponent };
612
673
  //# sourceMappingURL=SheetImplementationCustom.mjs.map