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