@lodev09/react-native-true-sheet 4.0.0-beta.0 → 4.0.0-beta.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 (367) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +42 -31
  3. package/RNTrueSheet.podspec +10 -2
  4. package/android/build.gradle +2 -1
  5. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +174 -49
  6. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerViewManager.kt +7 -0
  7. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +371 -18
  8. package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +14 -0
  9. package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +150 -21
  10. package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterViewManager.kt +14 -0
  11. package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderView.kt +38 -0
  12. package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderViewManager.kt +28 -0
  13. package/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +84 -24
  14. package/android/src/main/java/com/lodev09/truesheet/TrueSheetPackage.kt +5 -4
  15. package/android/src/main/java/com/lodev09/truesheet/TrueSheetPeekView.kt +72 -0
  16. package/android/src/main/java/com/lodev09/truesheet/TrueSheetPeekViewManager.kt +33 -0
  17. package/android/src/main/java/com/lodev09/truesheet/TrueSheetStateUpdater.kt +45 -0
  18. package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +526 -231
  19. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +1217 -603
  20. package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +136 -29
  21. package/android/src/main/java/com/lodev09/truesheet/core/RNScreensEventObserver.kt +63 -0
  22. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetBehavior.kt +36 -0
  23. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetView.kt +255 -0
  24. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +303 -0
  25. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDetentCalculator.kt +277 -0
  26. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDimView.kt +162 -0
  27. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt +180 -0
  28. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetKeyboardObserver.kt +207 -0
  29. package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt +220 -0
  30. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetDragEvents.kt +71 -0
  31. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetFocusEvents.kt +65 -0
  32. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetLifecycleEvents.kt +112 -0
  33. package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetStateEvents.kt +56 -0
  34. package/android/src/main/java/com/lodev09/truesheet/utils/KeyboardUtils.kt +84 -0
  35. package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +93 -67
  36. package/android/src/main/java/com/lodev09/truesheet/utils/ViewUtils.kt +30 -0
  37. package/android/src/main/jni/CMakeLists.txt +63 -0
  38. package/android/src/main/jni/TrueSheetSpec.h +19 -0
  39. package/android/src/main/jni/TrueSheetStateUpdater.cpp +96 -0
  40. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewComponentDescriptor.h +24 -0
  41. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp +43 -0
  42. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.h +28 -0
  43. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.cpp +11 -0
  44. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.h +37 -0
  45. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewComponentDescriptor.h +24 -0
  46. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.cpp +56 -0
  47. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.h +28 -0
  48. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.cpp +11 -0
  49. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.h +41 -0
  50. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.cpp +18 -0
  51. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.h +16 -0
  52. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewComponentDescriptor.h +28 -0
  53. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp +61 -0
  54. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.h +45 -0
  55. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.cpp +23 -0
  56. package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.h +52 -0
  57. package/ios/TrueSheetContainerView.h +81 -6
  58. package/ios/TrueSheetContainerView.mm +275 -21
  59. package/ios/TrueSheetContentView.h +38 -1
  60. package/ios/TrueSheetContentView.mm +413 -43
  61. package/ios/TrueSheetFooterView.h +27 -2
  62. package/ios/TrueSheetFooterView.mm +141 -35
  63. package/ios/{events/OnDidDismissEvent.h → TrueSheetHeaderView.h} +10 -7
  64. package/ios/TrueSheetHeaderView.mm +64 -0
  65. package/ios/TrueSheetModule.mm +92 -5
  66. package/ios/TrueSheetPeekView.h +32 -0
  67. package/ios/TrueSheetPeekView.mm +99 -0
  68. package/ios/TrueSheetView.h +7 -15
  69. package/ios/TrueSheetView.mm +633 -215
  70. package/ios/TrueSheetViewController.h +84 -16
  71. package/ios/TrueSheetViewController.mm +1136 -333
  72. package/ios/core/RNScreensEventObserver.h +46 -0
  73. package/ios/core/RNScreensEventObserver.mm +280 -0
  74. package/ios/core/TrueSheetBlurView.h +27 -0
  75. package/ios/core/TrueSheetBlurView.mm +82 -0
  76. package/ios/core/TrueSheetDetentCalculator.h +107 -0
  77. package/ios/core/TrueSheetDetentCalculator.mm +197 -0
  78. package/ios/core/TrueSheetGrabberView.h +72 -0
  79. package/ios/core/TrueSheetGrabberView.mm +178 -0
  80. package/ios/core/TrueSheetKeyboardObserver.h +39 -0
  81. package/ios/core/TrueSheetKeyboardObserver.mm +112 -0
  82. package/ios/events/TrueSheetDragEvents.h +39 -0
  83. package/ios/events/TrueSheetDragEvents.mm +62 -0
  84. package/ios/events/{OnPositionChangeEvent.h → TrueSheetFocusEvents.h} +8 -5
  85. package/ios/events/TrueSheetFocusEvents.mm +49 -0
  86. package/ios/events/TrueSheetLifecycleEvents.h +40 -0
  87. package/ios/events/TrueSheetLifecycleEvents.mm +71 -0
  88. package/ios/events/TrueSheetStateEvents.h +35 -0
  89. package/ios/events/TrueSheetStateEvents.mm +49 -0
  90. package/ios/tvos/TrueSheetStubs.mm +154 -0
  91. package/ios/{events/OnMountEvent.h → utils/BlurUtil.h} +5 -7
  92. package/ios/utils/BlurUtil.mm +69 -0
  93. package/ios/utils/GestureUtil.h +7 -0
  94. package/ios/utils/GestureUtil.mm +12 -0
  95. package/ios/utils/PlatformUtil.h +15 -0
  96. package/ios/utils/UIView+FirstResponder.h +15 -0
  97. package/ios/utils/UIView+FirstResponder.mm +26 -0
  98. package/ios/{events/OnWillDismissEvent.h → utils/UIView+ScrollEdgeInteraction.h} +6 -7
  99. package/ios/utils/UIView+ScrollEdgeInteraction.mm +62 -0
  100. package/ios/utils/WindowUtil.mm +17 -1
  101. package/lib/module/TrueSheet.js +224 -64
  102. package/lib/module/TrueSheet.js.map +1 -1
  103. package/lib/module/TrueSheet.web.js +1201 -0
  104. package/lib/module/TrueSheet.web.js.map +1 -0
  105. package/lib/module/TrueSheetPeek.js +15 -0
  106. package/lib/module/TrueSheetPeek.js.map +1 -0
  107. package/lib/module/TrueSheetPeek.web.js +55 -0
  108. package/lib/module/TrueSheetPeek.web.js.map +1 -0
  109. package/lib/module/TrueSheetProvider.js +28 -0
  110. package/lib/module/TrueSheetProvider.js.map +1 -0
  111. package/lib/module/TrueSheetProvider.web.js +157 -0
  112. package/lib/module/TrueSheetProvider.web.js.map +1 -0
  113. package/lib/module/fabric/TrueSheetContainerViewNativeComponent.ts +1 -1
  114. package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +5 -1
  115. package/lib/module/fabric/TrueSheetFooterViewNativeComponent.ts +10 -2
  116. package/lib/module/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
  117. package/lib/module/fabric/TrueSheetPeekViewNativeComponent.ts +8 -0
  118. package/lib/module/fabric/TrueSheetViewNativeComponent.ts +105 -18
  119. package/lib/module/index.js +3 -3
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/module/mocks/index.js +93 -0
  122. package/lib/module/mocks/index.js.map +1 -0
  123. package/lib/module/mocks/navigation.js +85 -0
  124. package/lib/module/mocks/navigation.js.map +1 -0
  125. package/lib/module/mocks/reanimated.js +91 -0
  126. package/lib/module/mocks/reanimated.js.map +1 -0
  127. package/lib/module/navigation/TrueSheetRouter.js +170 -0
  128. package/lib/module/navigation/TrueSheetRouter.js.map +1 -0
  129. package/lib/module/navigation/TrueSheetView.js +71 -0
  130. package/lib/module/navigation/TrueSheetView.js.map +1 -0
  131. package/lib/module/navigation/createTrueSheetNavigator.js +63 -0
  132. package/lib/module/navigation/createTrueSheetNavigator.js.map +1 -0
  133. package/lib/module/navigation/index.js +6 -0
  134. package/lib/module/navigation/index.js.map +1 -0
  135. package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js +56 -0
  136. package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js.map +1 -0
  137. package/lib/module/navigation/screen/TrueSheetScreen.js +49 -0
  138. package/lib/module/navigation/screen/TrueSheetScreen.js.map +1 -0
  139. package/lib/module/navigation/screen/index.js +5 -0
  140. package/lib/module/navigation/screen/index.js.map +1 -0
  141. package/lib/module/navigation/screen/types.js +4 -0
  142. package/lib/module/navigation/screen/types.js.map +1 -0
  143. package/lib/module/navigation/screen/useSheetScreenState.js +68 -0
  144. package/lib/module/navigation/screen/useSheetScreenState.js.map +1 -0
  145. package/lib/module/navigation/types.js +4 -0
  146. package/lib/module/navigation/types.js.map +1 -0
  147. package/lib/module/navigation/useTrueSheetNavigation.js +24 -0
  148. package/lib/module/navigation/useTrueSheetNavigation.js.map +1 -0
  149. package/lib/module/reanimated/ReanimatedTrueSheet.js +15 -9
  150. package/lib/module/reanimated/ReanimatedTrueSheet.js.map +1 -1
  151. package/lib/module/reanimated/ReanimatedTrueSheet.web.js +81 -0
  152. package/lib/module/reanimated/ReanimatedTrueSheet.web.js.map +1 -0
  153. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +4 -2
  154. package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -1
  155. package/lib/module/reanimated/index.js +2 -2
  156. package/lib/module/reanimated/index.js.map +1 -1
  157. package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js +20 -0
  158. package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js.map +1 -0
  159. package/lib/module/specs/NativeTrueSheetModule.js.map +1 -1
  160. package/lib/module/web/constants.js +16 -0
  161. package/lib/module/web/constants.js.map +1 -0
  162. package/lib/module/web/vaul/README.md +9 -0
  163. package/lib/module/web/vaul/browser.js +30 -0
  164. package/lib/module/web/vaul/browser.js.map +1 -0
  165. package/lib/module/web/vaul/constants.js +15 -0
  166. package/lib/module/web/vaul/constants.js.map +1 -0
  167. package/lib/module/web/vaul/context.js +59 -0
  168. package/lib/module/web/vaul/context.js.map +1 -0
  169. package/lib/module/web/vaul/helpers.js +93 -0
  170. package/lib/module/web/vaul/helpers.js.map +1 -0
  171. package/lib/module/web/vaul/index.js +1309 -0
  172. package/lib/module/web/vaul/index.js.map +1 -0
  173. package/lib/module/web/vaul/style.css +287 -0
  174. package/lib/module/web/vaul/style.css.d.js +2 -0
  175. package/lib/module/web/vaul/style.css.d.js.map +1 -0
  176. package/lib/module/web/vaul/types.js +2 -0
  177. package/lib/module/web/vaul/types.js.map +1 -0
  178. package/lib/module/web/vaul/use-composed-refs.js +34 -0
  179. package/lib/module/web/vaul/use-composed-refs.js.map +1 -0
  180. package/lib/module/web/vaul/use-controllable-state.js +54 -0
  181. package/lib/module/web/vaul/use-controllable-state.js.map +1 -0
  182. package/lib/module/web/vaul/use-position-fixed.js +123 -0
  183. package/lib/module/web/vaul/use-position-fixed.js.map +1 -0
  184. package/lib/module/web/vaul/use-prevent-scroll.js +258 -0
  185. package/lib/module/web/vaul/use-prevent-scroll.js.map +1 -0
  186. package/lib/module/web/vaul/use-scale-background.js +57 -0
  187. package/lib/module/web/vaul/use-scale-background.js.map +1 -0
  188. package/lib/module/web/vaul/use-snap-points.js +305 -0
  189. package/lib/module/web/vaul/use-snap-points.js.map +1 -0
  190. package/lib/typescript/src/TrueSheet.d.ts +51 -14
  191. package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
  192. package/lib/typescript/src/TrueSheet.types.d.ts +463 -54
  193. package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
  194. package/lib/typescript/src/TrueSheet.web.d.ts +5 -0
  195. package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -0
  196. package/lib/typescript/src/TrueSheetPeek.d.ts +9 -0
  197. package/lib/typescript/src/TrueSheetPeek.d.ts.map +1 -0
  198. package/lib/typescript/src/TrueSheetPeek.web.d.ts +28 -0
  199. package/lib/typescript/src/TrueSheetPeek.web.d.ts.map +1 -0
  200. package/lib/typescript/src/TrueSheetProvider.d.ts +18 -0
  201. package/lib/typescript/src/TrueSheetProvider.d.ts.map +1 -0
  202. package/lib/typescript/src/TrueSheetProvider.web.d.ts +27 -0
  203. package/lib/typescript/src/TrueSheetProvider.web.d.ts.map +1 -0
  204. package/lib/typescript/src/fabric/TrueSheetContainerViewNativeComponent.d.ts.map +1 -1
  205. package/lib/typescript/src/fabric/TrueSheetContentViewNativeComponent.d.ts.map +1 -1
  206. package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts +2 -0
  207. package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts.map +1 -1
  208. package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts +6 -0
  209. package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts.map +1 -0
  210. package/lib/typescript/src/fabric/TrueSheetPeekViewNativeComponent.d.ts +6 -0
  211. package/lib/typescript/src/fabric/TrueSheetPeekViewNativeComponent.d.ts.map +1 -0
  212. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +67 -16
  213. package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
  214. package/lib/typescript/src/index.d.ts +2 -2
  215. package/lib/typescript/src/index.d.ts.map +1 -1
  216. package/lib/typescript/src/mocks/index.d.ts +43 -0
  217. package/lib/typescript/src/mocks/index.d.ts.map +1 -0
  218. package/lib/typescript/src/mocks/navigation.d.ts +66 -0
  219. package/lib/typescript/src/mocks/navigation.d.ts.map +1 -0
  220. package/lib/typescript/src/mocks/reanimated.d.ts +48 -0
  221. package/lib/typescript/src/mocks/reanimated.d.ts.map +1 -0
  222. package/lib/typescript/src/navigation/TrueSheetRouter.d.ts +57 -0
  223. package/lib/typescript/src/navigation/TrueSheetRouter.d.ts.map +1 -0
  224. package/lib/typescript/src/navigation/TrueSheetView.d.ts +10 -0
  225. package/lib/typescript/src/navigation/TrueSheetView.d.ts.map +1 -0
  226. package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts +35 -0
  227. package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts.map +1 -0
  228. package/lib/typescript/src/navigation/index.d.ts +6 -0
  229. package/lib/typescript/src/navigation/index.d.ts.map +1 -0
  230. package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts +3 -0
  231. package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts.map +1 -0
  232. package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts +3 -0
  233. package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts.map +1 -0
  234. package/lib/typescript/src/navigation/screen/index.d.ts +4 -0
  235. package/lib/typescript/src/navigation/screen/index.d.ts.map +1 -0
  236. package/lib/typescript/src/navigation/screen/types.d.ts +15 -0
  237. package/lib/typescript/src/navigation/screen/types.d.ts.map +1 -0
  238. package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts +35 -0
  239. package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts.map +1 -0
  240. package/lib/typescript/src/navigation/types.d.ts +153 -0
  241. package/lib/typescript/src/navigation/types.d.ts.map +1 -0
  242. package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts +23 -0
  243. package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts.map +1 -0
  244. package/lib/typescript/src/reanimated/ReanimatedTrueSheet.d.ts.map +1 -1
  245. package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts +41 -0
  246. package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts.map +1 -0
  247. package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts +8 -2
  248. package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts.map +1 -1
  249. package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts +15 -0
  250. package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts.map +1 -0
  251. package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts +25 -3
  252. package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts.map +1 -1
  253. package/lib/typescript/src/web/constants.d.ts +14 -0
  254. package/lib/typescript/src/web/constants.d.ts.map +1 -0
  255. package/lib/typescript/src/web/vaul/browser.d.ts +8 -0
  256. package/lib/typescript/src/web/vaul/browser.d.ts.map +1 -0
  257. package/lib/typescript/src/web/vaul/constants.d.ts +13 -0
  258. package/lib/typescript/src/web/vaul/constants.d.ts.map +1 -0
  259. package/lib/typescript/src/web/vaul/context.d.ts +53 -0
  260. package/lib/typescript/src/web/vaul/context.d.ts.map +1 -0
  261. package/lib/typescript/src/web/vaul/helpers.d.ts +17 -0
  262. package/lib/typescript/src/web/vaul/helpers.d.ts.map +1 -0
  263. package/lib/typescript/src/web/vaul/index.d.ts +228 -0
  264. package/lib/typescript/src/web/vaul/index.d.ts.map +1 -0
  265. package/lib/typescript/src/web/vaul/types.d.ts +7 -0
  266. package/lib/typescript/src/web/vaul/types.d.ts.map +1 -0
  267. package/lib/typescript/src/web/vaul/use-composed-refs.d.ts +14 -0
  268. package/lib/typescript/src/web/vaul/use-composed-refs.d.ts.map +1 -0
  269. package/lib/typescript/src/web/vaul/use-controllable-state.d.ts +9 -0
  270. package/lib/typescript/src/web/vaul/use-controllable-state.d.ts.map +1 -0
  271. package/lib/typescript/src/web/vaul/use-position-fixed.d.ts +19 -0
  272. package/lib/typescript/src/web/vaul/use-position-fixed.d.ts.map +1 -0
  273. package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts +18 -0
  274. package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts.map +1 -0
  275. package/lib/typescript/src/web/vaul/use-scale-background.d.ts +2 -0
  276. package/lib/typescript/src/web/vaul/use-scale-background.d.ts.map +1 -0
  277. package/lib/typescript/src/web/vaul/use-snap-points.d.ts +38 -0
  278. package/lib/typescript/src/web/vaul/use-snap-points.d.ts.map +1 -0
  279. package/package.json +78 -34
  280. package/react-native.config.js +9 -2
  281. package/src/TrueSheet.tsx +276 -60
  282. package/src/TrueSheet.types.ts +525 -71
  283. package/src/TrueSheet.web.tsx +1366 -0
  284. package/src/TrueSheetPeek.tsx +11 -0
  285. package/src/TrueSheetPeek.web.tsx +63 -0
  286. package/src/TrueSheetProvider.tsx +33 -0
  287. package/src/TrueSheetProvider.web.tsx +220 -0
  288. package/src/fabric/TrueSheetContainerViewNativeComponent.ts +1 -1
  289. package/src/fabric/TrueSheetContentViewNativeComponent.ts +5 -1
  290. package/src/fabric/TrueSheetFooterViewNativeComponent.ts +10 -2
  291. package/src/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
  292. package/src/fabric/TrueSheetPeekViewNativeComponent.ts +8 -0
  293. package/src/fabric/TrueSheetViewNativeComponent.ts +105 -18
  294. package/src/index.ts +2 -2
  295. package/src/mocks/index.ts +89 -0
  296. package/src/mocks/navigation.ts +72 -0
  297. package/src/mocks/reanimated.ts +101 -0
  298. package/src/navigation/TrueSheetRouter.ts +234 -0
  299. package/src/navigation/TrueSheetView.tsx +99 -0
  300. package/src/navigation/createTrueSheetNavigator.tsx +93 -0
  301. package/src/navigation/index.ts +14 -0
  302. package/src/navigation/screen/ReanimatedTrueSheetScreen.tsx +61 -0
  303. package/src/navigation/screen/TrueSheetScreen.tsx +54 -0
  304. package/src/navigation/screen/index.ts +3 -0
  305. package/src/navigation/screen/types.ts +21 -0
  306. package/src/navigation/screen/useSheetScreenState.ts +107 -0
  307. package/src/navigation/types.ts +219 -0
  308. package/src/navigation/useTrueSheetNavigation.ts +26 -0
  309. package/src/reanimated/ReanimatedTrueSheet.tsx +12 -7
  310. package/src/reanimated/ReanimatedTrueSheet.web.tsx +75 -0
  311. package/src/reanimated/ReanimatedTrueSheetProvider.tsx +12 -8
  312. package/src/reanimated/useReanimatedPositionChangeHandler.web.ts +31 -0
  313. package/src/specs/NativeTrueSheetModule.ts +28 -3
  314. package/src/web/constants.ts +13 -0
  315. package/src/web/vaul/README.md +9 -0
  316. package/src/web/vaul/browser.ts +38 -0
  317. package/src/web/vaul/constants.ts +20 -0
  318. package/src/web/vaul/context.ts +101 -0
  319. package/src/web/vaul/helpers.ts +124 -0
  320. package/src/web/vaul/index.tsx +1740 -0
  321. package/src/web/vaul/style.css +287 -0
  322. package/src/web/vaul/style.css.d.ts +1 -0
  323. package/src/web/vaul/types.ts +7 -0
  324. package/src/web/vaul/use-composed-refs.ts +35 -0
  325. package/src/web/vaul/use-controllable-state.ts +66 -0
  326. package/src/web/vaul/use-position-fixed.ts +147 -0
  327. package/src/web/vaul/use-prevent-scroll.ts +309 -0
  328. package/src/web/vaul/use-scale-background.ts +64 -0
  329. package/src/web/vaul/use-snap-points.ts +455 -0
  330. package/android/src/main/java/com/lodev09/truesheet/events/DetentChangeEvent.kt +0 -26
  331. package/android/src/main/java/com/lodev09/truesheet/events/DidDismissEvent.kt +0 -20
  332. package/android/src/main/java/com/lodev09/truesheet/events/DidPresentEvent.kt +0 -26
  333. package/android/src/main/java/com/lodev09/truesheet/events/DragBeginEvent.kt +0 -26
  334. package/android/src/main/java/com/lodev09/truesheet/events/DragChangeEvent.kt +0 -26
  335. package/android/src/main/java/com/lodev09/truesheet/events/DragEndEvent.kt +0 -26
  336. package/android/src/main/java/com/lodev09/truesheet/events/MountEvent.kt +0 -20
  337. package/android/src/main/java/com/lodev09/truesheet/events/PositionChangeEvent.kt +0 -32
  338. package/android/src/main/java/com/lodev09/truesheet/events/SizeChangeEvent.kt +0 -27
  339. package/android/src/main/java/com/lodev09/truesheet/events/WillDismissEvent.kt +0 -20
  340. package/android/src/main/java/com/lodev09/truesheet/events/WillPresentEvent.kt +0 -26
  341. package/android/src/main/res/values/styles.xml +0 -8
  342. package/ios/events/OnDetentChangeEvent.h +0 -28
  343. package/ios/events/OnDetentChangeEvent.mm +0 -30
  344. package/ios/events/OnDidDismissEvent.mm +0 -25
  345. package/ios/events/OnDidPresentEvent.h +0 -28
  346. package/ios/events/OnDidPresentEvent.mm +0 -30
  347. package/ios/events/OnDragBeginEvent.h +0 -28
  348. package/ios/events/OnDragBeginEvent.mm +0 -30
  349. package/ios/events/OnDragChangeEvent.h +0 -28
  350. package/ios/events/OnDragChangeEvent.mm +0 -30
  351. package/ios/events/OnDragEndEvent.h +0 -28
  352. package/ios/events/OnDragEndEvent.mm +0 -30
  353. package/ios/events/OnMountEvent.mm +0 -25
  354. package/ios/events/OnPositionChangeEvent.mm +0 -32
  355. package/ios/events/OnSizeChangeEvent.h +0 -28
  356. package/ios/events/OnSizeChangeEvent.mm +0 -30
  357. package/ios/events/OnWillDismissEvent.mm +0 -25
  358. package/ios/events/OnWillPresentEvent.h +0 -28
  359. package/ios/events/OnWillPresentEvent.mm +0 -30
  360. package/ios/utils/LayoutUtil.h +0 -44
  361. package/ios/utils/LayoutUtil.mm +0 -50
  362. package/lib/module/TrueSheetGrabber.js +0 -51
  363. package/lib/module/TrueSheetGrabber.js.map +0 -1
  364. package/lib/typescript/src/TrueSheetGrabber.d.ts +0 -39
  365. package/lib/typescript/src/TrueSheetGrabber.d.ts.map +0 -1
  366. package/src/TrueSheetGrabber.tsx +0 -82
  367. package/src/__mocks__/index.js +0 -67
@@ -0,0 +1,1201 @@
1
+ "use strict";
2
+
3
+ /// <reference lib="dom" />
4
+ import { createElement, forwardRef, isValidElement, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
5
+ import { StyleSheet, useColorScheme, useWindowDimensions, View } from 'react-native';
6
+ import { measurePeekContentHeight, TrueSheetPeekContext } from "./TrueSheetPeek.web.js";
7
+ import { usePortalContainer, useRegisterSheet, useSheetStack } from "./TrueSheetProvider.web.js";
8
+ import { COLOR_SURFACE_CONTAINER_LOW_DARK, COLOR_SURFACE_CONTAINER_LOW_LIGHT, DEFAULT_ANCHOR_OFFSET, DEFAULT_CORNER_RADIUS, DEFAULT_DETACHED_OFFSET, DEFAULT_FORM_SHEET_HEIGHT_RATIO, DEFAULT_FORM_SHEET_WIDTH, DEFAULT_GRABBER_COLOR_DARK, DEFAULT_GRABBER_COLOR_LIGHT, DEFAULT_GRABBER_HEIGHT, DEFAULT_GRABBER_TOP_MARGIN, DEFAULT_GRABBER_WIDTH, DEFAULT_MAX_WIDTH } from "./web/constants.js";
9
+ import { Drawer } from "./web/vaul/index.js";
10
+ import { DEFAULT_PEEK_HEIGHT, TRANSITIONS } from "./web/vaul/constants.js";
11
+
12
+ // First vertically scrollable descendant — web mirror of native's
13
+ // findScrollView (RN-web ScrollView/FlatList render a node with
14
+ // `overflow-y: auto`; its first child is the content container).
15
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
16
+ const findVerticalScroller = root => {
17
+ for (const el of root.querySelectorAll('*')) {
18
+ const {
19
+ overflowY
20
+ } = window.getComputedStyle(el);
21
+ if (overflowY === 'auto' || overflowY === 'scroll') return el;
22
+ }
23
+ return null;
24
+ };
25
+ const TrueSheetComponent = /*#__PURE__*/forwardRef((props, ref) => {
26
+ const {
27
+ children,
28
+ name,
29
+ dismissible = true,
30
+ draggable = true,
31
+ cornerRadius,
32
+ style,
33
+ backgroundColor: backgroundColorProp,
34
+ maxContentHeight,
35
+ maxContentWidth,
36
+ anchor = 'center',
37
+ anchorOffset = DEFAULT_ANCHOR_OFFSET,
38
+ grabber = true,
39
+ grabberOptions,
40
+ accessibilityOptions,
41
+ detents = [0.5, 1],
42
+ dimmed = true,
43
+ dimmedDetentIndex = 0,
44
+ initialDetentIndex = -1,
45
+ header,
46
+ headerStyle,
47
+ headerOptions,
48
+ footer,
49
+ footerStyle,
50
+ footerOptions,
51
+ presentation = 'page',
52
+ detached = false,
53
+ detachedOffset = DEFAULT_DETACHED_OFFSET,
54
+ elevation = 4,
55
+ insetAdjustment = 'automatic',
56
+ initialDetentAnimated = true,
57
+ onPositionChange,
58
+ onWillPresent,
59
+ onDidPresent,
60
+ onWillDismiss,
61
+ onDidDismiss,
62
+ onDetentChange,
63
+ onDragBegin,
64
+ onDragChange,
65
+ onDragEnd,
66
+ onMount,
67
+ onWillFocus,
68
+ onDidFocus,
69
+ onWillBlur,
70
+ onDidBlur
71
+ } = props;
72
+ const validDetents = useMemo(() => detents.filter(d => typeof d === 'number' || d === 'auto' || d === 'peek'), [detents]);
73
+ const snapPointsProps = useMemo(() => {
74
+ if (validDetents.length === 0) return {};
75
+ return {
76
+ snapPoints: validDetents,
77
+ fadeFromIndex: Math.min(dimmedDetentIndex, validDetents.length - 1)
78
+ };
79
+ }, [validDetents, dimmedDetentIndex]);
80
+ const {
81
+ width: windowWidth,
82
+ height: windowHeight
83
+ } = useWindowDimensions();
84
+ const isLandscapeOrTablet = windowWidth >= 600 || windowWidth > windowHeight;
85
+ const isFormSheet = isLandscapeOrTablet && presentation === 'form';
86
+
87
+ // A form sheet floats (detached) only on tablet/landscape — mirrors iOS where
88
+ // a form sheet is a centered card on iPad but an edge-attached bottom sheet on
89
+ // a compact iPhone. On mobile portrait it stays edge-attached unless `detached`
90
+ // is explicitly set.
91
+ const effectiveDetached = isFormSheet || detached;
92
+ const colorScheme = useColorScheme();
93
+ const backgroundColor = backgroundColorProp ?? (colorScheme === 'dark' ? COLOR_SURFACE_CONTAINER_LOW_DARK : COLOR_SURFACE_CONTAINER_LOW_LIGHT);
94
+ const shouldAutoPresent = initialDetentIndex >= 0 && initialDetentIndex < validDetents.length;
95
+ const [isOpen, setIsOpen] = useState(shouldAutoPresent);
96
+ const [activeSnapPoint, setActiveSnapPoint] = useState(() => validDetents[shouldAutoPresent ? initialDetentIndex : 0] ?? null);
97
+
98
+ // Keep activeSnapPoint valid if detents change (e.g., prop updates).
99
+ useEffect(() => {
100
+ if (validDetents.length === 0) return;
101
+ setActiveSnapPoint(current => current != null && validDetents.includes(current) ? current : validDetents[0]);
102
+ }, [validDetents]);
103
+ const validDetentsRef = useRef(validDetents);
104
+ validDetentsRef.current = validDetents;
105
+ const hasAutoDetent = validDetents.includes('auto');
106
+ const handleSetActiveSnapPoint = useCallback(snapPoint => {
107
+ setActiveSnapPoint(snapPoint == null ? null : typeof snapPoint === 'number' || snapPoint === 'auto' || snapPoint === 'peek' ? snapPoint : null);
108
+ }, []);
109
+ const handleOpenChange = useCallback(open => {
110
+ if (!open && isOpen) {
111
+ setIsOpen(false);
112
+ }
113
+ }, [isOpen]);
114
+ const portalContainer = usePortalContainer();
115
+ const handlePointerDownOutside = e => {
116
+ const target = e.target;
117
+ if (!(target instanceof Node)) return;
118
+ // Pointer down that landed outside this sheet's portal container (e.g.,
119
+ // in another screen's tree when navigating) should not close the drawer.
120
+ if (portalContainer && !portalContainer.contains(target)) {
121
+ e.preventDefault();
122
+ return;
123
+ }
124
+ // The footer is rendered via vaul's `detachedSiblings` as a sibling of
125
+ // Drawer.Content inside [data-vaul-detached-wrapper], so Radix treats
126
+ // clicks on it as "outside" the content. Don't dismiss for clicks that
127
+ // landed inside the wrapper.
128
+ if (target instanceof Element) {
129
+ const wrapper = drawerContentRef.current?.closest('[data-vaul-detached-wrapper]');
130
+ if (wrapper && wrapper.contains(target)) {
131
+ e.preventDefault();
132
+ }
133
+ }
134
+ };
135
+ const dismissAboveRef = useRef(async () => {});
136
+ const methods = useMemo(() => ({
137
+ present: async (index = 0) => {
138
+ const detent = validDetentsRef.current[index];
139
+ if (detent === undefined) {
140
+ throw new Error(`TrueSheet: present index (${index}) is out of bounds. detents array has ${validDetentsRef.current.length} item(s)`);
141
+ }
142
+ setActiveSnapPoint(detent);
143
+ setIsOpen(true);
144
+ },
145
+ dismiss: async () => {
146
+ setIsOpen(false);
147
+ },
148
+ resize: async index => {
149
+ const detent = validDetentsRef.current[index];
150
+ if (detent === undefined) {
151
+ throw new Error(`TrueSheet: resize index (${index}) is out of bounds. detents array has ${validDetentsRef.current.length} item(s)`);
152
+ }
153
+ setActiveSnapPoint(detent);
154
+ },
155
+ dismissStack: async animated => {
156
+ await dismissAboveRef.current(animated);
157
+ }
158
+ }), []);
159
+ useImperativeHandle(ref, () => methods, [methods]);
160
+ const methodsRef = useRef(methods);
161
+ useRegisterSheet(name, methodsRef);
162
+ const drawerContentRef = useRef(null);
163
+
164
+ // Measured header/footer heights drive the 'peek' snap point — mirrors
165
+ // native, where the controller tracks headerHeight/footerHeight.
166
+ const [headerHeight, setHeaderHeight] = useState(0);
167
+ const [footerHeight, setFooterHeight] = useState(0);
168
+ const handleHeaderLayout = useCallback(e => {
169
+ setHeaderHeight(e.nativeEvent.layout.height);
170
+ }, []);
171
+ const handleFooterLayout = useCallback(e => {
172
+ setFooterHeight(e.nativeEvent.layout.height);
173
+ }, []);
174
+
175
+ // DOM refs for live 'peek' measurement in computeDetentGeometry — the
176
+ // state above (which drives vaul's `peekHeight` prop) comes from RN-web
177
+ // `onLayout`, which dispatches a frame after mount: too late for the first
178
+ // willPresent.
179
+ const headerElRef = useRef(null);
180
+ const footerElRef = useRef(null);
181
+
182
+ // Distance from the content top to the bottom of a `TrueSheetPeek` rendered
183
+ // within the content — measured by the peek against `contentRef`.
184
+ const [peekContentHeight, setPeekContentHeight] = useState(0);
185
+ const contentRef = useRef(null);
186
+ const peekElRef = useRef(null);
187
+ const peekContext = useMemo(() => ({
188
+ contentRef,
189
+ peekRef: peekElRef,
190
+ setPeekContentHeight
191
+ }), []);
192
+
193
+ // An absolute (floating) header overlaps the content, so it contributes no
194
+ // height to the 'auto' detent measurement.
195
+ const absoluteHeader = headerOptions?.position === 'absolute';
196
+ const absoluteHeaderRef = useRef(absoluteHeader);
197
+ absoluteHeaderRef.current = absoluteHeader;
198
+ const resolvedHeaderStyle = absoluteHeader ? [absoluteHeaderStyle, headerStyle] : headerStyle;
199
+
200
+ // Same for an absolute (floating) footer — rendered via vaul's
201
+ // `detachedSiblings` instead of in the content flow.
202
+ const absoluteFooter = footerOptions?.position === 'absolute';
203
+ const absoluteFooterRef = useRef(absoluteFooter);
204
+ absoluteFooterRef.current = absoluteFooter;
205
+
206
+ // The footer owns the sheet's bottom edge, so it absorbs the bottom
207
+ // safe-area inset as padding (on top of its own) — mirrors native, where the
208
+ // footer shadow node pads the inset so its background fills it.
209
+ const footerOwnsInset = Boolean(footer) && insetAdjustment === 'automatic';
210
+ const resolvedFooterStyle = useMemo(() => {
211
+ if (!footerOwnsInset) return footerStyle;
212
+ const flat = StyleSheet.flatten(footerStyle);
213
+ const base = flat?.paddingBottom ?? flat?.paddingVertical ?? flat?.padding;
214
+ const baseCss = typeof base === 'number' ? `${base}px` : typeof base === 'string' ? base : '0px';
215
+ return [footerStyle, {
216
+ paddingBottom: `calc(${baseCss} + env(safe-area-inset-bottom, 0px))`
217
+ }];
218
+ }, [footerOwnsInset, footerStyle]);
219
+
220
+ // A relative footer is laid out below the content, so it's pushed off-screen
221
+ // at the peek detent and contributes no height.
222
+ const peekHeight = (header ? headerHeight : 0) + (footer && absoluteFooter ? footerHeight : 0) + peekContentHeight || DEFAULT_PEEK_HEIGHT;
223
+
224
+ // Web mirror of native's scrollable handling for 'auto' detents: a plugged
225
+ // scrollable keeps the sized (bounded) layout so its viewport is capped to
226
+ // the visible sheet and can scroll, while the 'auto' height is measured with
227
+ // the viewport replaced by the scrollable's content size — mirrors native
228
+ // `naturalHeight`.
229
+ const [hasBoundedScrollable, setHasBoundedScrollable] = useState(false);
230
+ const [scrollableAutoHeight, setScrollableAutoHeight] = useState(0);
231
+ const pinnedScrollerRef = useRef(null);
232
+
233
+ // Natural content height (header + content + footer, with a pinned
234
+ // scrollable's viewport replaced by its content size) — the height the
235
+ // content wants regardless of the sheet's bounds.
236
+ const measureNaturalHeight = useCallback(() => {
237
+ const contentEl = contentRef.current;
238
+ if (!contentEl || !contentEl.isConnected) return 0;
239
+ const headerEl = absoluteHeaderRef.current ? null : headerElRef.current;
240
+ const footerEl = absoluteFooterRef.current ? null : footerElRef.current;
241
+ let height = (headerEl?.offsetHeight ?? 0) + (footerEl?.offsetHeight ?? 0) + contentEl.offsetHeight;
242
+ const scroller = pinnedScrollerRef.current;
243
+ const scrollContent = scroller?.firstElementChild;
244
+ if (scroller?.isConnected && scrollContent instanceof HTMLElement) {
245
+ height += scrollContent.offsetHeight - scroller.clientHeight;
246
+ }
247
+ return Math.max(0, height);
248
+ }, []);
249
+ useEffect(() => {
250
+ if (!isOpen || !hasAutoDetent) return undefined;
251
+ let canceled = false;
252
+ let rafId = 0;
253
+ let mutationObserver = null;
254
+ let resizeObserver = null;
255
+ const attach = () => {
256
+ if (canceled) return;
257
+ const drawerEl = drawerContentRef.current;
258
+ if (!drawerEl || !drawerEl.isConnected) {
259
+ // Radix Presence defers the portal mount; poll until the drawer is live.
260
+ rafId = window.requestAnimationFrame(attach);
261
+ return;
262
+ }
263
+ const measure = () => setScrollableAutoHeight(measureNaturalHeight());
264
+ let observed = null;
265
+
266
+ // (Re)pin the first vertical scrollable and observe the nodes whose size
267
+ // feeds the natural height — content growth inside a bounded scroller is
268
+ // invisible to the sheet's own layout (mirrors native's contentSize
269
+ // observation). Resolves the content node live: the layout-branch swap
270
+ // (natural flow ↔ sized) remounts it.
271
+ const observe = () => {
272
+ const contentEl = contentRef.current;
273
+ const headerEl = headerElRef.current;
274
+
275
+ // Skip mutations that don't change the observed topology — e.g. a
276
+ // virtualized list mounting rows inside the pinned scroller, which
277
+ // would otherwise trigger a full-subtree rescan (findVerticalScroller
278
+ // resolves computed styles) on every scroll frame. Size changes are
279
+ // already covered by the ResizeObserver.
280
+ if (observed && observed.contentEl === contentEl && contentEl?.isConnected && observed.headerEl === headerEl && observed.scroller.isConnected && observed.scrollContent === observed.scroller.firstElementChild) {
281
+ return;
282
+ }
283
+ const scroller = contentEl && contentEl.isConnected ? findVerticalScroller(contentEl) : null;
284
+ pinnedScrollerRef.current = scroller;
285
+ setHasBoundedScrollable(scroller != null);
286
+ observed = scroller ? {
287
+ contentEl,
288
+ headerEl,
289
+ scroller,
290
+ scrollContent: scroller.firstElementChild
291
+ } : null;
292
+ resizeObserver?.disconnect();
293
+ resizeObserver = new ResizeObserver(measure);
294
+ if (contentEl?.isConnected) resizeObserver.observe(contentEl);
295
+ if (headerEl) resizeObserver.observe(headerEl);
296
+ if (scroller) {
297
+ resizeObserver.observe(scroller);
298
+ if (scroller.firstElementChild) resizeObserver.observe(scroller.firstElementChild);
299
+ }
300
+ measure();
301
+ };
302
+ observe();
303
+ // Watch the whole drawer subtree — catches the scrollable mounting/
304
+ // unmounting AND the layout-branch swap, which remounts the content node
305
+ // (a content-scoped observer would go stale after the swap).
306
+ mutationObserver = new MutationObserver(observe);
307
+ mutationObserver.observe(drawerEl, {
308
+ childList: true,
309
+ subtree: true
310
+ });
311
+ };
312
+ rafId = window.requestAnimationFrame(attach);
313
+ return () => {
314
+ canceled = true;
315
+ window.cancelAnimationFrame(rafId);
316
+ mutationObserver?.disconnect();
317
+ resizeObserver?.disconnect();
318
+ };
319
+ }, [isOpen, hasAutoDetent, measureNaturalHeight]);
320
+
321
+ // Below the last detent a vertical touch pan moves the sheet, not the
322
+ // content — `[data-vaul-scroll-locked]` disables vertical touch panning on
323
+ // the scroll container and everything inside it (see vaul/style.css).
324
+ const isScrollLocked = validDetents.length > 0 && activeSnapPoint !== validDetents[validDetents.length - 1];
325
+
326
+ // Vaul measures the auto-size wrapper's offsetHeight (always, post fork).
327
+ // Track it here so the form sheet can size its card to fit content,
328
+ // clamped between a minimum ratio of the viewport and a maximum derived
329
+ // from `detachedOffset` (the breathing room left at top + bottom of the
330
+ // floating card).
331
+ const [measuredContentHeight, setMeasuredContentHeight] = useState(0);
332
+ const effectiveMaxContentHeight = useMemo(() => {
333
+ if (maxContentHeight !== undefined) return maxContentHeight;
334
+ if (!isFormSheet) return undefined;
335
+ const min = windowHeight * DEFAULT_FORM_SHEET_HEIGHT_RATIO;
336
+ const max = Math.max(min, windowHeight - 2 * detachedOffset);
337
+ if (measuredContentHeight <= 0) return min;
338
+ return Math.max(min, Math.min(measuredContentHeight, max));
339
+ }, [maxContentHeight, isFormSheet, windowHeight, detachedOffset, measuredContentHeight]);
340
+
341
+ // Center the form sheet using the actual visible drawer height. Vaul
342
+ // auto-sizes to content (capped by `maxContentHeight`), so when content is
343
+ // shorter than `effectiveMaxContentHeight`'s min-clamped floor, using that
344
+ // for the offset would push a small sheet below the viewport center.
345
+ const effectiveDetachedOffset = useMemo(() => {
346
+ if (!isFormSheet) return detachedOffset;
347
+ const max = Math.max(0, windowHeight - 2 * detachedOffset);
348
+ const visibleHeight = measuredContentHeight > 0 ? Math.min(measuredContentHeight, max) : effectiveMaxContentHeight ?? 0;
349
+ return Math.max(0, (windowHeight - visibleHeight) / 2);
350
+ }, [isFormSheet, windowHeight, detachedOffset, measuredContentHeight, effectiveMaxContentHeight]);
351
+
352
+ // Present/dismiss events. The sheet settles via a CSS `transform` transition
353
+ // on either the drawer (snap-points on autopresent) or the wrapper (whole-
354
+ // card slide on reopen/dismiss). `Animation.finished` from the Web Animations
355
+ // API tracks whichever is actually running — reflects what the browser is
356
+ // doing, doesn't miss when no transition runs (same-value change), and
357
+ // handles interruptions correctly (a drag/resnap mid-present resolves only
358
+ // once all transform animations drain).
359
+ const onWillPresentRef = useRef(onWillPresent);
360
+ const onDidPresentRef = useRef(onDidPresent);
361
+ const onWillDismissRef = useRef(onWillDismiss);
362
+ const onDidDismissRef = useRef(onDidDismiss);
363
+ const onDetentChangeRef = useRef(onDetentChange);
364
+ const onDragBeginRef = useRef(onDragBegin);
365
+ const onDragChangeRef = useRef(onDragChange);
366
+ const onDragEndRef = useRef(onDragEnd);
367
+ const onPositionChangeRef = useRef(onPositionChange);
368
+ const activeSnapPointRef = useRef(activeSnapPoint);
369
+ useEffect(() => {
370
+ onWillPresentRef.current = onWillPresent;
371
+ onDidPresentRef.current = onDidPresent;
372
+ onWillDismissRef.current = onWillDismiss;
373
+ onDidDismissRef.current = onDidDismiss;
374
+ onDetentChangeRef.current = onDetentChange;
375
+ onDragBeginRef.current = onDragBegin;
376
+ onDragChangeRef.current = onDragChange;
377
+ onDragEndRef.current = onDragEnd;
378
+ onPositionChangeRef.current = onPositionChange;
379
+ activeSnapPointRef.current = activeSnapPoint;
380
+ });
381
+
382
+ // Detent geometry — target top-Y (`positions`) and height ratio (`values`)
383
+ // per detent. Mirrors vaul's snap-offset math exactly (same effective
384
+ // height, ceiling, and 'auto'/'peek' resolution) so computed targets match
385
+ // where the drawer actually settles. Numeric detent d → top-Y =
386
+ // (1 - d) * effectiveH. 'auto' and 'peek' are measured live from the DOM
387
+ // (see below). Inputs live in a render-synced ref so the compute callbacks
388
+ // stay referentially stable for the event effects.
389
+ const geometryInputsRef = useRef({
390
+ effectiveDetached,
391
+ effectiveDetachedOffset,
392
+ effectiveMaxContentHeight,
393
+ peekHeight,
394
+ peekContentHeight,
395
+ measuredContentHeight
396
+ });
397
+ geometryInputsRef.current = {
398
+ effectiveDetached,
399
+ effectiveDetachedOffset,
400
+ effectiveMaxContentHeight,
401
+ peekHeight,
402
+ peekContentHeight,
403
+ measuredContentHeight
404
+ };
405
+ const computeDetentGeometry = useCallback(() => {
406
+ const inputs = geometryInputsRef.current;
407
+ const windowH = window.innerHeight;
408
+ const effectiveH = inputs.effectiveDetached ? windowH - inputs.effectiveDetachedOffset : windowH;
409
+ // Matches vaul's height ceiling: min(effectiveH, maxContentHeight).
410
+ const ceiling = inputs.effectiveMaxContentHeight !== undefined ? Math.min(effectiveH, inputs.effectiveMaxContentHeight) : effectiveH;
411
+ // 'auto' resolves to the content's natural height. Read it live — the
412
+ // `measuredContentHeight` state lags mount by a frame (vaul's initial
413
+ // ref-callback measure runs while the portal subtree is still detached,
414
+ // so it reads 0 until the ResizeObserver fires). Falls back to the state
415
+ // value, then to vaul's pre-measure fallback (effectiveHeight / 2).
416
+ const measuredHeight = measureNaturalHeight() || inputs.measuredContentHeight;
417
+ const autoHeight = Math.min(measuredHeight > 0 ? measuredHeight : effectiveH / 2, ceiling);
418
+
419
+ // 'peek' is measured live from the DOM (offsetHeight is layout-based, so
420
+ // in-flight transforms don't skew it): the state-driven `peekHeight` prop
421
+ // comes from RN-web onLayout, which dispatches a frame after mount — too
422
+ // late for the first willPresent on autopresent. Ref callbacks can't
423
+ // measure either: they fire while the portal subtree is still detached.
424
+ // Geometry only runs while the drawer is mounted, so the elements are
425
+ // measurable here; fall back to the state value when they're absent.
426
+ const headerEl = headerElRef.current;
427
+ // A relative footer is pushed off-screen at the peek detent — excluded
428
+ const footerEl = absoluteFooterRef.current ? footerElRef.current : null;
429
+ const peekEl = peekElRef.current;
430
+ const contentEl = contentRef.current;
431
+ const livePeekContentHeight = peekEl && contentEl ? measurePeekContentHeight(peekEl, contentEl) : inputs.peekContentHeight;
432
+ const livePeekHeight = headerEl || footerEl || peekEl ? (headerEl?.offsetHeight ?? 0) + (footerEl?.offsetHeight ?? 0) + livePeekContentHeight || DEFAULT_PEEK_HEIGHT : inputs.peekHeight;
433
+ const positions = [];
434
+ const values = [];
435
+ for (const d of validDetentsRef.current) {
436
+ const h = typeof d === 'number' ? Math.min(d * effectiveH, ceiling) : d === 'peek' ? Math.min(livePeekHeight, ceiling) : autoHeight;
437
+ positions.push(effectiveH - h);
438
+ values.push(effectiveH > 0 ? h / effectiveH : 0);
439
+ }
440
+ return {
441
+ windowH,
442
+ effectiveH,
443
+ ceiling,
444
+ positions,
445
+ values
446
+ };
447
+ }, [measureNaturalHeight]);
448
+
449
+ // Detent info for lifecycle events. Position/detent come from the active
450
+ // detent's target geometry — not the live DOM rect — so willPresent (drawer
451
+ // not mounted yet), detentChange (animation just started), and didPresent
452
+ // all emit the settled detent position, matching iOS/Android. Drag events
453
+ // pass `live: true` to report the in-flight rect position instead, also
454
+ // matching native.
455
+ const computeDetentInfo = useCallback((live = false) => {
456
+ const snap = activeSnapPointRef.current;
457
+ const index = snap != null ? validDetentsRef.current.indexOf(snap) : -1;
458
+ const {
459
+ windowH,
460
+ positions,
461
+ values
462
+ } = computeDetentGeometry();
463
+ const target = index >= 0 ? positions[index] : undefined;
464
+ const position = live ? drawerContentRef.current?.getBoundingClientRect().top ?? target ?? windowH : target ?? windowH;
465
+ return {
466
+ index,
467
+ position,
468
+ detent: index >= 0 ? values[index] ?? 0 : 0
469
+ };
470
+ }, [computeDetentGeometry]);
471
+
472
+ // Mirror Android: interpolate fractional index and detent from the drawer's
473
+ // top-Y so continuous position updates (drag, animation) carry smooth values
474
+ // between detent boundaries.
475
+ const interpolateFromPosition = useCallback(position => {
476
+ const {
477
+ windowH,
478
+ positions,
479
+ values
480
+ } = computeDetentGeometry();
481
+ const count = positions.length;
482
+ if (count === 0) return {
483
+ index: -1,
484
+ detent: 0
485
+ };
486
+
487
+ // Absorb subpixel drift from getBoundingClientRect so at-rest positions
488
+ // don't sneak into the below-first branch and emit near-zero negatives
489
+ // like `-1e-8` (which render as "-1" via JS scientific-notation toString).
490
+ const epsilon = 0.5;
491
+ const firstPos = positions[0];
492
+ const lastPos = positions[count - 1];
493
+ if (position > firstPos + epsilon) {
494
+ // Two ranges: index spans the full animation (windowH of wrapper
495
+ // travel) so it's smooth for driving dependent animations end-to-end;
496
+ // detent tracks the sheet's visible-height ratio (windowH - firstPos)
497
+ // so its 0–values[0] fade has fine resolution while the sheet is still
498
+ // in view. Both clamp to keep outputs in [-1, 0].
499
+ const indexRaw = (position - firstPos) / windowH;
500
+ const detentRaw = (position - firstPos) / Math.max(1, windowH - firstPos);
501
+ const indexProgress = Math.max(0, Math.min(1, indexRaw));
502
+ const detentProgress = Math.max(0, Math.min(1, detentRaw));
503
+ return {
504
+ index: -indexProgress,
505
+ detent: Math.max(0, values[0] * (1 - detentProgress))
506
+ };
507
+ }
508
+ if (count === 1) return {
509
+ index: 0,
510
+ detent: values[0]
511
+ };
512
+
513
+ // Clamp into the segment range so subpixel drift at the boundaries
514
+ // resolves cleanly to the nearest segment edge (index 0 or count-1).
515
+ const clamped = Math.max(lastPos, Math.min(firstPos, position));
516
+ for (let i = 0; i < count - 1; i++) {
517
+ const pos = positions[i];
518
+ const nextPos = positions[i + 1];
519
+ if (clamped >= nextPos && clamped <= pos) {
520
+ const range = pos - nextPos;
521
+ const progress = range > 0 ? (pos - clamped) / range : 0;
522
+ const clampedProgress = Math.max(0, Math.min(1, progress));
523
+ return {
524
+ index: i + clampedProgress,
525
+ detent: values[i] + clampedProgress * (values[i + 1] - values[i])
526
+ };
527
+ }
528
+ }
529
+ return {
530
+ index: count - 1,
531
+ detent: values[count - 1]
532
+ };
533
+ }, [computeDetentGeometry]);
534
+
535
+ // Mirror native synchronous layout: while dragging (and through the post-
536
+ // release settle) the sized layout tracks the sheet's visible height in
537
+ // realtime, clamped to the smallest detent — dragging below it slides the
538
+ // sheet out without resizing. Once settled, the inline height is cleared so
539
+ // the CSS calc() owns sizing again (adapts to viewport resizes at rest).
540
+ const sizedLayoutRef = useRef(null);
541
+ const isDraggingRef = useRef(false);
542
+ const isSettlingAfterDragRef = useRef(false);
543
+ const updateSizedLayoutHeight = useCallback(position => {
544
+ const node = sizedLayoutRef.current;
545
+ if (!node) return;
546
+ const {
547
+ effectiveH,
548
+ ceiling,
549
+ positions
550
+ } = computeDetentGeometry();
551
+ if (positions.length === 0) return;
552
+ if (isSettlingAfterDragRef.current) {
553
+ const snap = activeSnapPointRef.current;
554
+ const index = snap != null ? validDetentsRef.current.indexOf(snap) : -1;
555
+ const target = index >= 0 ? positions[index] : null;
556
+ if (target != null && Math.abs(position - target) < 1) {
557
+ isSettlingAfterDragRef.current = false;
558
+ // Restore the calc — height is an inline style, so clearing it would
559
+ // leave the div unsized (React won't re-apply it without a render)
560
+ node.style.height = SIZED_LAYOUT_HEIGHT;
561
+ return;
562
+ }
563
+ }
564
+
565
+ // positions[0] is the smallest detent's top-Y — its height is the clamp floor.
566
+ const minHeight = effectiveH - positions[0];
567
+ const height = Math.min(Math.max(effectiveH - position, minHeight), ceiling);
568
+ node.style.height = `${height}px`;
569
+ }, [computeDetentGeometry]);
570
+ const handlePositionChange = useCallback(position => {
571
+ if (isDraggingRef.current || isSettlingAfterDragRef.current) {
572
+ updateSizedLayoutHeight(position);
573
+ }
574
+ const {
575
+ index,
576
+ detent
577
+ } = interpolateFromPosition(position);
578
+ onPositionChangeRef.current?.({
579
+ nativeEvent: {
580
+ index,
581
+ position,
582
+ detent,
583
+ realtime: true
584
+ }
585
+ });
586
+ }, [interpolateFromPosition, updateSizedLayoutHeight]);
587
+
588
+ // Fire onMount once after first render. React-mount is the earliest point
589
+ // the component is ready for imperative calls, matching the native
590
+ // "ready for present" contract. Declared before the present/dismiss effect
591
+ // so it fires first during autopresent (onMount → onWillPresent).
592
+ const onMountRef = useRef(onMount);
593
+ useEffect(() => {
594
+ onMountRef.current = onMount;
595
+ });
596
+ useEffect(() => {
597
+ onMountRef.current?.({
598
+ nativeEvent: null
599
+ });
600
+ }, []);
601
+
602
+ // Start at `false` so a mount with `isOpen=true` (autopresent via
603
+ // `initialDetentIndex`) is detected as a false→true transition and fires
604
+ // `onWillPresent`.
605
+ const wasOpenRef = useRef(false);
606
+ useEffect(() => {
607
+ const wasOpen = wasOpenRef.current;
608
+ wasOpenRef.current = isOpen;
609
+ if (isOpen === wasOpen) return undefined;
610
+ const present = isOpen;
611
+ if (!present) {
612
+ // Pair willBlur with willDismiss on dismiss — mirrors native iOS
613
+ // emitWillDismissEvents (blur fires before dismiss). willPresent is
614
+ // deferred to `start()` below (needs the mounted drawer's geometry).
615
+ onWillBlurRef.current?.({
616
+ nativeEvent: null
617
+ });
618
+ onWillDismissRef.current?.({
619
+ nativeEvent: null
620
+ });
621
+ }
622
+ const fireDone = () => {
623
+ if (present) {
624
+ onDidPresentRef.current?.({
625
+ nativeEvent: computeDetentInfo()
626
+ });
627
+ onDidFocusRef.current?.({
628
+ nativeEvent: null
629
+ });
630
+ } else {
631
+ onDidBlurRef.current?.({
632
+ nativeEvent: null
633
+ });
634
+ onDidDismissRef.current?.({
635
+ nativeEvent: null
636
+ });
637
+ }
638
+ };
639
+ let canceled = false;
640
+ let rafId = 0;
641
+ const start = () => {
642
+ if (canceled) return;
643
+ const drawer = drawerContentRef.current;
644
+ if (!drawer || !drawer.isConnected) {
645
+ // Drawer hasn't mounted yet (Radix Presence defers the portal mount
646
+ // past the first effect pass), or its subtree isn't attached to the
647
+ // document yet (autopresent commits the portal before the app tree
648
+ // attaches, so nothing is measurable). Poll until it's live.
649
+ rafId = window.requestAnimationFrame(start);
650
+ return;
651
+ }
652
+ if (present) {
653
+ // Emit will-events only once the drawer is mounted and attached —
654
+ // detent geometry ('auto' height, 'peek', form-sheet sizing) is
655
+ // measurable from the DOM here; a synchronous emission would use the
656
+ // pre-measure fallbacks on first present. Pairing willFocus with
657
+ // willPresent mirrors native iOS where viewWillAppear dispatches
658
+ // both; the descendant-stack focus effect handles subsequent
659
+ // transitions.
660
+ onWillPresentRef.current?.({
661
+ nativeEvent: computeDetentInfo()
662
+ });
663
+ onWillFocusRef.current?.({
664
+ nativeEvent: null
665
+ });
666
+ }
667
+ const wrapper = drawer.closest('[data-vaul-detached-wrapper]') ?? null;
668
+ const targets = wrapper ? [drawer, wrapper] : [drawer];
669
+ const waitForSettle = () => {
670
+ if (canceled) return;
671
+ // Force style recalc so transitions queued by vaul's effects this
672
+ // commit are registered in `getAnimations()`. RAF callbacks run BEFORE
673
+ // the frame's style recalc, and ignoring this returns a stale empty
674
+ // list — we'd fire `did` immediately with nothing queued.
675
+
676
+ drawer.offsetHeight;
677
+ const pending = targets.flatMap(el => el.getAnimations().filter(a => a.playState !== 'finished'));
678
+ if (pending.length === 0) {
679
+ fireDone();
680
+ return;
681
+ }
682
+ // allSettled: resolve even when a transition is canceled (drag /
683
+ // resnap), then re-check — a replacement transition may have started.
684
+ Promise.allSettled(pending.map(a => a.finished)).then(() => {
685
+ if (!canceled) waitForSettle();
686
+ });
687
+ };
688
+ waitForSettle();
689
+ };
690
+ rafId = window.requestAnimationFrame(start);
691
+ return () => {
692
+ canceled = true;
693
+ window.cancelAnimationFrame(rafId);
694
+ };
695
+ }, [isOpen, computeDetentInfo]);
696
+
697
+ // Fire onDetentChange only while open→open. Present/dismiss have their own
698
+ // events and carry detent info via onDidPresent, so we skip those edges.
699
+ const detentChangeStateRef = useRef({
700
+ isOpen,
701
+ activeSnapPoint
702
+ });
703
+ useEffect(() => {
704
+ const prev = detentChangeStateRef.current;
705
+ detentChangeStateRef.current = {
706
+ isOpen,
707
+ activeSnapPoint
708
+ };
709
+ if (!prev.isOpen || !isOpen) return;
710
+ if (prev.activeSnapPoint === activeSnapPoint) return;
711
+ onDetentChangeRef.current?.({
712
+ nativeEvent: computeDetentInfo()
713
+ });
714
+ }, [isOpen, activeSnapPoint, computeDetentInfo]);
715
+
716
+ // Vaul's `onDrag` fires once per pointermove while dragging; the first tick
717
+ // after an idle gap marks the drag boundary, so track it via a ref.
718
+ const handleDrag = useCallback(() => {
719
+ if (!isDraggingRef.current) {
720
+ isDraggingRef.current = true;
721
+ onDragBeginRef.current?.({
722
+ nativeEvent: computeDetentInfo(true)
723
+ });
724
+ }
725
+ onDragChangeRef.current?.({
726
+ nativeEvent: computeDetentInfo(true)
727
+ });
728
+ }, [computeDetentInfo]);
729
+ const handleRelease = useCallback((_event, open) => {
730
+ if (!isDraggingRef.current) return;
731
+ isDraggingRef.current = false;
732
+ // Track the sized layout through the settle animation only when the sheet
733
+ // stays open — a dismissal slides out at the min-clamped height.
734
+ isSettlingAfterDragRef.current = open;
735
+ onDragEndRef.current?.({
736
+ nativeEvent: computeDetentInfo(true)
737
+ });
738
+ }, [computeDetentInfo]);
739
+ const {
740
+ isNested,
741
+ dismissAbove,
742
+ descendants
743
+ } = useSheetStack(methodsRef, drawerContentRef, isOpen, isFormSheet);
744
+ dismissAboveRef.current = dismissAbove;
745
+
746
+ // Mirror Android: translate this sheet down to match the deepest descendant's
747
+ // top so the whole stack visually aligns. Cascades because every ancestor
748
+ // re-runs whenever the stack (and thus its descendants) changes.
749
+ useEffect(() => {
750
+ const parent = drawerContentRef.current;
751
+ if (!parent) return;
752
+ // Skip while dismissing: this sheet's stack pop changes `descendants`,
753
+ // which would re-fire the effect and write `wrapper.style.transition =
754
+ // 'clip-path …'`, clobbering vaul's just-written `'transform …'` for the
755
+ // dismiss animation. Vaul fully owns this sheet's transitions on the way
756
+ // out — nothing to align with anymore.
757
+ if (!isOpen) return;
758
+ const parentWrapper = parent.closest('[data-vaul-detached-wrapper]');
759
+ const transition = `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
760
+ const wrapperTransition = `clip-path ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
761
+ const CLIP_NONE = 'inset(0px round 0px)';
762
+
763
+ // Animate clip-path on the wrapper. Dedupes via DOM read so repeat ticks
764
+ // (mutation observer) skip identical writes. Seeds CLIP_NONE before the
765
+ // first inset() so the browser interpolates between two inset() shapes —
766
+ // `none → inset()` interpolates inconsistently.
767
+ const setClip = next => {
768
+ if (!parentWrapper) return;
769
+ const current = parentWrapper.style.clipPath;
770
+ if (current === next) return;
771
+ if (next === CLIP_NONE && !current) return;
772
+ if (!current) {
773
+ parentWrapper.style.transition = '';
774
+ parentWrapper.style.clipPath = CLIP_NONE;
775
+ // eslint-disable-next-line no-void
776
+ void parentWrapper.offsetHeight;
777
+ }
778
+ parentWrapper.style.transition = wrapperTransition;
779
+ parentWrapper.style.clipPath = next;
780
+ };
781
+ if (descendants.length === 0) {
782
+ parent.style.transition = transition;
783
+ parent.style.transform = '';
784
+ setClip(CLIP_NONE);
785
+ return;
786
+ }
787
+
788
+ // Track only the immediate child's snap point. Walking deeper descendants
789
+ // would push this sheet further when a grandchild opens, even when our
790
+ // own child didn't move (e.g., child skipped its cascade for a page
791
+ // grandchild) — leaving a visible gap between this sheet and its child.
792
+ const computeTargetY = () => {
793
+ const parentSnap = Number.parseFloat(parent.style.getPropertyValue('--snap-point-height')) || 0;
794
+ const node = descendants[0]?.nodeRef.current;
795
+ if (!node) return parentSnap;
796
+ const childSnap = Number.parseFloat(node.style.getPropertyValue('--snap-point-height')) || 0;
797
+ return Math.max(parentSnap, childSnap);
798
+ };
799
+
800
+ // When a form-sheet parent has a form-sheet descendant, clip the parent to
801
+ // the child card's viewport box so it doesn't peek above/around. Only
802
+ // applies when this sheet is itself form — a page parent should remain
803
+ // visible behind/around a floating form child. Geometry comes from the
804
+ // child's inline styles (not getBoundingClientRect) to read the at-rest
805
+ // box, unskewed by vaul's slide-in.
806
+ const applyFormClip = () => {
807
+ const form = isFormSheet ? descendants.find(d => d.isFormSheetRef.current) : undefined;
808
+ if (!form) {
809
+ setClip(CLIP_NONE);
810
+ return;
811
+ }
812
+ const childDrawer = form.nodeRef.current;
813
+ const childWrapper = childDrawer?.closest('[data-vaul-detached-wrapper]');
814
+ if (!parentWrapper || !childDrawer || !childWrapper) return;
815
+ const snapY = Number.parseFloat(childDrawer.style.getPropertyValue('--snap-point-height')) || 0;
816
+ const childBottomGap = Number.parseFloat(childWrapper.style.bottom) || 0;
817
+ const childMaxW = Number.parseFloat(childWrapper.style.maxWidth) || window.innerWidth;
818
+ const formLeft = (window.innerWidth - childMaxW) / 2;
819
+ const formRight = (window.innerWidth + childMaxW) / 2;
820
+ const formBottom = window.innerHeight - childBottomGap;
821
+ const rect = parentWrapper.getBoundingClientRect();
822
+ const top = Math.max(0, snapY - rect.top);
823
+ const left = Math.max(0, formLeft - rect.left);
824
+ const right = Math.max(0, rect.right - formRight);
825
+ const bottom = Math.max(0, rect.bottom - formBottom);
826
+ const radius = cornerRadius ?? DEFAULT_CORNER_RADIUS;
827
+ setClip(`inset(${top}px ${right}px ${bottom}px ${left}px round ${radius}px)`);
828
+ };
829
+ const apply = () => {
830
+ applyFormClip();
831
+ // Mirror iOS: a page-sheet child fully covers a form-sheet parent, so the
832
+ // cascade push-down has no visible effect — and would briefly peek above
833
+ // the page during the present animation. Leave the parent put.
834
+ const child = descendants[0];
835
+ if (isFormSheet && child && !child.isFormSheetRef.current) {
836
+ parent.style.transition = transition;
837
+ parent.style.transform = '';
838
+ return;
839
+ }
840
+ const targetY = computeTargetY();
841
+ const match = parent.style.transform.match(/translate3d\([^,]*,\s*(-?\d*\.?\d+)px/);
842
+ const currentY = match ? Number.parseFloat(match[1]) : 0;
843
+ if (Math.abs(currentY - targetY) < 0.5) return;
844
+ parent.style.transition = transition;
845
+ parent.style.transform = `translate3d(0, ${targetY}px, 0)`;
846
+ };
847
+ const raf = requestAnimationFrame(apply);
848
+ // Vaul re-runs snapToPoint on window resize (e.g., mobile keyboard open)
849
+ // which clobbers the cascade transform. Re-apply whenever the parent's
850
+ // inline style changes.
851
+ const observer = new MutationObserver(apply);
852
+ observer.observe(parent, {
853
+ attributes: true,
854
+ attributeFilter: ['style']
855
+ });
856
+ return () => {
857
+ cancelAnimationFrame(raf);
858
+ observer.disconnect();
859
+ };
860
+ }, [descendants, activeSnapPoint, cornerRadius, isFormSheet, isOpen]);
861
+
862
+ // Focus/blur events fire when a descendant sheet appears on top of this one
863
+ // (blur) or when all descendants are dismissed (focus). will-events fire
864
+ // synchronously at the transition boundary; did-events fire once the cascade
865
+ // transform drains. Intermediate count changes (1↔2) don't re-fire — this
866
+ // sheet stays blurred throughout.
867
+ const onWillBlurRef = useRef(onWillBlur);
868
+ const onDidBlurRef = useRef(onDidBlur);
869
+ const onWillFocusRef = useRef(onWillFocus);
870
+ const onDidFocusRef = useRef(onDidFocus);
871
+ useEffect(() => {
872
+ onWillBlurRef.current = onWillBlur;
873
+ onDidBlurRef.current = onDidBlur;
874
+ onWillFocusRef.current = onWillFocus;
875
+ onDidFocusRef.current = onDidFocus;
876
+ });
877
+ const prevDescendantCountRef = useRef(0);
878
+ useEffect(() => {
879
+ const prevCount = prevDescendantCountRef.current;
880
+ const count = descendants.length;
881
+ prevDescendantCountRef.current = count;
882
+ if (!isOpen) return;
883
+ const gained = count > 0 && prevCount === 0;
884
+ const lost = count === 0 && prevCount > 0;
885
+ if (!gained && !lost) return;
886
+ if (gained) {
887
+ onWillBlurRef.current?.({
888
+ nativeEvent: null
889
+ });
890
+ } else {
891
+ onWillFocusRef.current?.({
892
+ nativeEvent: null
893
+ });
894
+ }
895
+ const drawer = drawerContentRef.current;
896
+ if (!drawer) return;
897
+ let canceled = false;
898
+ const fireDone = () => {
899
+ if (canceled) return;
900
+ if (gained) onDidBlurRef.current?.({
901
+ nativeEvent: null
902
+ });else onDidFocusRef.current?.({
903
+ nativeEvent: null
904
+ });
905
+ };
906
+ const rafId = window.requestAnimationFrame(() => {
907
+ if (canceled) return;
908
+ // Force style recalc so the cascade effect's queued transform registers.
909
+
910
+ drawer.offsetHeight;
911
+ const pending = drawer.getAnimations().filter(a => a.playState !== 'finished');
912
+ if (pending.length === 0) {
913
+ fireDone();
914
+ return;
915
+ }
916
+ Promise.allSettled(pending.map(a => a.finished)).then(() => {
917
+ if (!canceled) fireDone();
918
+ });
919
+ });
920
+ return () => {
921
+ canceled = true;
922
+ window.cancelAnimationFrame(rafId);
923
+ };
924
+ }, [isOpen, descendants.length]);
925
+
926
+ // Definite-height flex layout (per-detent sizing) unless content must be
927
+ // measured in natural flow: 'auto' detents (without a plugged scrollable —
928
+ // those measure via `measureNaturalHeight`) and form-sheet content-fit sizing.
929
+ const useSizedLayout = (!hasAutoDetent || hasBoundedScrollable) && !isFormSheet;
930
+ const effectiveCornerRadius = cornerRadius ?? DEFAULT_CORNER_RADIUS;
931
+
932
+ // Shadow cast upward from the sheet's top edge toward the background. Matches
933
+ // Android's `elevation` semantics roughly — the sheet "lifts" off whatever is
934
+ // behind it. Scales linearly so higher elevation reads as more separation.
935
+ // Applied to the vaul wrapper (not the drawer) as `filter: drop-shadow`: the
936
+ // wrapper clips the drawer (overflow: hidden + contain: paint), which would
937
+ // cut off `box-shadow` on the drawer at the wrapper edges — visible in
938
+ // detached mode (bottom blur clipped in the floating gap) and when the
939
+ // wrapper is narrowed by maxWidth/anchor margins (lateral blur clipped at
940
+ // wrapper edges). drop-shadow on the wrapper follows the post-clip silhouette
941
+ // and isn't clipped by the wrapper itself.
942
+ const dropShadow = elevation > 0 ? `drop-shadow(0 ${-elevation}px ${elevation * 3}px rgba(0, 0, 0, 0.15))` : undefined;
943
+ const mergedContentStyle = useMemo(() => ({
944
+ position: 'fixed',
945
+ top: 0,
946
+ left: 0,
947
+ right: 0,
948
+ bottom: 0,
949
+ display: 'flex',
950
+ flexDirection: 'column',
951
+ borderTopLeftRadius: effectiveCornerRadius,
952
+ borderTopRightRadius: effectiveCornerRadius,
953
+ backgroundColor: backgroundColor,
954
+ // Clip children to the rounded top so headers/content with their own
955
+ // background don't bleed past the corners. `clip` (not `hidden`): a
956
+ // hidden box is still a scroll container, so browser focus-reveal (e.g.
957
+ // tapping a button near the sheet bottom) can scroll-offset the drawer —
958
+ // shifting content and blocking vaul's shouldDrag walk (scrollTop > 0).
959
+ overflow: 'clip',
960
+ // Lift content above iOS home indicator / bottom safe area when enabled.
961
+ // A relative footer owns the inset instead (see resolvedFooterStyle); an
962
+ // absolute footer floats over the content, so the content keeps its lift.
963
+ paddingBottom: insetAdjustment === 'automatic' && !(footerOwnsInset && !absoluteFooter) ? 'env(safe-area-inset-bottom, 0px)' : 0
964
+ }), [backgroundColor, effectiveCornerRadius, insetAdjustment, footerOwnsInset, absoluteFooter]);
965
+ const defaultGrabberColor = colorScheme === 'dark' ? DEFAULT_GRABBER_COLOR_DARK : DEFAULT_GRABBER_COLOR_LIGHT;
966
+ const grabberHeight = grabberOptions?.height ?? DEFAULT_GRABBER_HEIGHT;
967
+
968
+ // Footer is rendered inside the wrapper via `detachedSiblings`, so it
969
+ // follows the wrapper on dismiss and drag-overshoot. Positioning is
970
+ // relative to the wrapper (contain: paint creates the containing block).
971
+ const footerFloatStyle = useMemo(() => ({
972
+ position: 'fixed',
973
+ left: 0,
974
+ right: 0,
975
+ bottom: 0,
976
+ // Wrapper has `pointer-events: none` to let clicks fall through; the
977
+ // footer must opt back in.
978
+ pointerEvents: 'auto'
979
+ }), []);
980
+
981
+ // Form-sheet style (presentation='form'): centered floating card with a
982
+ // default width and a height fit to content. We reuse the existing detached
983
+ // mechanic so drag/snap math stays correct — the wrapper is bottom-attached
984
+ // with a computed offset (`effectiveDetachedOffset`, declared above) that
985
+ // centers it vertically. `presentation` is absolute: when 'form',
986
+ // `maxContentWidth` is ignored and the card uses DEFAULT_FORM_SHEET_WIDTH.
987
+
988
+ // The wrapper holds all horizontal sizing/anchoring so its rounded-bottom
989
+ // clip (when detached) aligns with the drawer's horizontal bounds on
990
+ // desktop — otherwise its corners sit at the far viewport edges.
991
+ // - presentation='form' → DEFAULT_FORM_SHEET_WIDTH on tablet/landscape;
992
+ // `maxContentWidth` is ignored ('form' is absolute).
993
+ // - presentation='page' → `maxContentWidth` (any viewport) or
994
+ // DEFAULT_MAX_WIDTH (tablet/landscape readability cap).
995
+ // Detached without a width constraint applies anchorOffset on both edges so
996
+ // the floating card breathes from the viewport sides.
997
+ const wrapperStyle = useMemo(() => {
998
+ // Mobile portrait ignores width sizing entirely (matches iOS/Android:
999
+ // both apply `maxContentWidth` only when not on a portrait phone).
1000
+ // `detached` + `detachedOffset` are still respected via the wrapper.
1001
+ const maxWidth = isLandscapeOrTablet ? presentation === 'form' ? DEFAULT_FORM_SHEET_WIDTH : maxContentWidth ?? DEFAULT_MAX_WIDTH : undefined;
1002
+ const needsMargins = maxWidth != null || effectiveDetached;
1003
+ if (!needsMargins && !dropShadow) return undefined;
1004
+ const next = {};
1005
+ if (dropShadow) next.filter = dropShadow;
1006
+ if (!needsMargins) return next;
1007
+ let marginLeft;
1008
+ let marginRight;
1009
+ if (isFormSheet) {
1010
+ marginLeft = 'auto';
1011
+ marginRight = 'auto';
1012
+ } else if (maxWidth == null) {
1013
+ marginLeft = anchorOffset;
1014
+ marginRight = anchorOffset;
1015
+ } else {
1016
+ marginLeft = anchor === 'left' ? anchorOffset : 'auto';
1017
+ marginRight = anchor === 'right' ? anchorOffset : 'auto';
1018
+ }
1019
+ if (maxWidth != null) next.maxWidth = maxWidth;
1020
+ next.marginLeft = marginLeft;
1021
+ next.marginRight = marginRight;
1022
+ return next;
1023
+ }, [isLandscapeOrTablet, isFormSheet, maxContentWidth, presentation, anchor, anchorOffset, effectiveDetached, dropShadow]);
1024
+
1025
+ // Absolute-position the grabber so it overlays the content top-edge
1026
+ // instead of consuming flow height — mirrors native iOS/Android, where
1027
+ // the grabber sits in the rounded corner zone above the content and
1028
+ // doesn't push the header down or inflate the 'auto' detent measurement.
1029
+ const handleStyle = useMemo(() => ({
1030
+ position: 'absolute',
1031
+ top: grabberOptions?.topMargin ?? DEFAULT_GRABBER_TOP_MARGIN,
1032
+ left: '50%',
1033
+ transform: 'translateX(-50%)',
1034
+ height: grabberHeight,
1035
+ width: grabberOptions?.width ?? DEFAULT_GRABBER_WIDTH,
1036
+ borderRadius: grabberOptions?.cornerRadius ?? grabberHeight / 2,
1037
+ backgroundColor: grabberOptions?.color ?? defaultGrabberColor,
1038
+ opacity: 1,
1039
+ // Above absolute-positioned headers (which often use zIndex:1 to overlay
1040
+ // scroll content) so the grabber stays draggable — critical when
1041
+ // `handleOnly` mode means only the grabber can drag the sheet.
1042
+ zIndex: 2
1043
+ }), [grabberOptions, grabberHeight, defaultGrabberColor]);
1044
+ return /*#__PURE__*/_jsx(TrueSheetPeekContext.Provider, {
1045
+ value: peekContext,
1046
+ children: /*#__PURE__*/_jsx(Drawer.Root, {
1047
+ open: isOpen,
1048
+ onOpenChange: handleOpenChange,
1049
+ onPositionChange: handlePositionChange,
1050
+ onDrag: handleDrag,
1051
+ onRelease: handleRelease,
1052
+ dismissible: dismissible,
1053
+ draggable: draggable,
1054
+ repositionInputs: false,
1055
+ modal: dimmed,
1056
+ nested: isNested,
1057
+ detached: effectiveDetached,
1058
+ detachedOffset: effectiveDetachedOffset,
1059
+ detachedRadius: effectiveCornerRadius,
1060
+ maxContentHeight: effectiveMaxContentHeight,
1061
+ peekHeight: peekHeight,
1062
+ initialAnimated: initialDetentAnimated,
1063
+ detachedWrapperStyle: wrapperStyle,
1064
+ onContentHeightChange: setMeasuredContentHeight,
1065
+ contentHeight:
1066
+ // Bounded scrollable → the auto-size wrapper measures 0 (sized
1067
+ // layout is absolute), so feed vaul the natural height instead.
1068
+ hasAutoDetent && hasBoundedScrollable && scrollableAutoHeight > 0 ? scrollableAutoHeight : undefined,
1069
+ activeSnapPoint: activeSnapPoint,
1070
+ setActiveSnapPoint: handleSetActiveSnapPoint,
1071
+ ...snapPointsProps,
1072
+ children: /*#__PURE__*/_jsxs(Drawer.Portal, {
1073
+ container: portalContainer ?? undefined,
1074
+ children: [/*#__PURE__*/_jsx(Drawer.Overlay, {
1075
+ style: overlayStyle
1076
+ }), /*#__PURE__*/_jsxs(Drawer.Content, {
1077
+ ref: drawerContentRef,
1078
+ style: mergedContentStyle,
1079
+ onPointerDownOutside: handlePointerDownOutside,
1080
+ detachedSiblings: footer && absoluteFooter ? /*#__PURE__*/_jsx("div", {
1081
+ style: footerFloatStyle,
1082
+ children: /*#__PURE__*/_jsx(View, {
1083
+ ref: footerElRef,
1084
+ style: resolvedFooterStyle,
1085
+ onLayout: handleFooterLayout,
1086
+ children: /*#__PURE__*/isValidElement(footer) ? footer : /*#__PURE__*/createElement(footer)
1087
+ })
1088
+ }) : undefined,
1089
+ children: [/*#__PURE__*/_jsx(Drawer.Title, {
1090
+ style: visuallyHiddenStyle,
1091
+ children: accessibilityOptions?.paneTitle ?? 'Sheet'
1092
+ }), grabber && /*#__PURE__*/_jsx(Drawer.Handle, {
1093
+ style: handleStyle
1094
+ }), useSizedLayout ?
1095
+ /*#__PURE__*/
1096
+ // vaul wraps children in `[data-vaul-auto-size-wrapper]` (display:
1097
+ // flow-root) which doesn't honor descendant flex layout. Use an
1098
+ // absolute fill sized to the visible portion (via vaul's
1099
+ // `--snap-point-height` var) so the inner flex column has a
1100
+ // definite height for flex layouts to fill — mirrors native, where
1101
+ // the container is sized to the sheet's visible height per detent.
1102
+ _jsxs("div", {
1103
+ ref: sizedLayoutRef,
1104
+ style: sizedLayoutStyle,
1105
+ "data-vaul-scroll-locked": isScrollLocked ? '' : undefined,
1106
+ children: [header && /*#__PURE__*/_jsx(View, {
1107
+ ref: headerElRef,
1108
+ style: resolvedHeaderStyle,
1109
+ onLayout: handleHeaderLayout,
1110
+ children: /*#__PURE__*/isValidElement(header) ? header : /*#__PURE__*/createElement(header)
1111
+ }), /*#__PURE__*/_jsx(View, {
1112
+ ref: contentRef,
1113
+ style: hasAutoDetent && hasBoundedScrollable ? [contentFillStyle, style] : style,
1114
+ children: children
1115
+ }), footer && !absoluteFooter && /*#__PURE__*/_jsx(View, {
1116
+ ref: footerElRef,
1117
+ style: [relativeFooterStyle, resolvedFooterStyle],
1118
+ onLayout: handleFooterLayout,
1119
+ children: /*#__PURE__*/isValidElement(footer) ? footer : /*#__PURE__*/createElement(footer)
1120
+ })]
1121
+ }) :
1122
+ /*#__PURE__*/
1123
+ // Natural flow so vaul can measure content height — required for
1124
+ // 'auto' detents and form-sheet content-fit sizing.
1125
+ _jsxs(_Fragment, {
1126
+ children: [header && /*#__PURE__*/_jsx(View, {
1127
+ ref: headerElRef,
1128
+ style: resolvedHeaderStyle,
1129
+ onLayout: handleHeaderLayout,
1130
+ children: /*#__PURE__*/isValidElement(header) ? header : /*#__PURE__*/createElement(header)
1131
+ }), /*#__PURE__*/_jsx(View, {
1132
+ ref: contentRef,
1133
+ style: style,
1134
+ children: children
1135
+ }), footer && !absoluteFooter && /*#__PURE__*/_jsx(View, {
1136
+ ref: footerElRef,
1137
+ style: resolvedFooterStyle,
1138
+ onLayout: handleFooterLayout,
1139
+ children: /*#__PURE__*/isValidElement(footer) ? footer : /*#__PURE__*/createElement(footer)
1140
+ })]
1141
+ })]
1142
+ })]
1143
+ })
1144
+ })
1145
+ });
1146
+ });
1147
+ const overlayStyle = {
1148
+ position: 'fixed',
1149
+ inset: 0,
1150
+ backgroundColor: 'rgba(0, 0, 0, 0.5)'
1151
+ };
1152
+
1153
+ // Pinned to the sheet's bottom edge — takes up layout space below the content
1154
+ const relativeFooterStyle = {
1155
+ marginTop: 'auto'
1156
+ };
1157
+
1158
+ // Floats over the content so it doesn't take up layout space
1159
+ const absoluteHeaderStyle = {
1160
+ position: 'absolute',
1161
+ top: 0,
1162
+ left: 0,
1163
+ right: 0,
1164
+ zIndex: 1
1165
+ };
1166
+ const SIZED_LAYOUT_HEIGHT = 'calc(100% - var(--snap-point-height, 0px))';
1167
+ const sizedLayoutStyle = {
1168
+ position: 'absolute',
1169
+ top: 0,
1170
+ left: 0,
1171
+ right: 0,
1172
+ height: SIZED_LAYOUT_HEIGHT,
1173
+ display: 'flex',
1174
+ flexDirection: 'column'
1175
+ };
1176
+ const contentFillStyle = {
1177
+ flex: 1,
1178
+ minHeight: 0
1179
+ };
1180
+ const visuallyHiddenStyle = {
1181
+ position: 'absolute',
1182
+ width: 1,
1183
+ height: 1,
1184
+ padding: 0,
1185
+ margin: -1,
1186
+ overflow: 'hidden',
1187
+ clip: 'rect(0, 0, 0, 0)',
1188
+ whiteSpace: 'nowrap',
1189
+ border: 0
1190
+ };
1191
+ const STATIC_METHOD_ERROR = 'Static methods are not supported on web. Use the useTrueSheet() hook instead.';
1192
+ export const TrueSheet = TrueSheetComponent;
1193
+ const rejectStatic = async () => {
1194
+ throw new Error(STATIC_METHOD_ERROR);
1195
+ };
1196
+ TrueSheet.present = rejectStatic;
1197
+ TrueSheet.dismiss = rejectStatic;
1198
+ TrueSheet.dismissStack = rejectStatic;
1199
+ TrueSheet.resize = rejectStatic;
1200
+ TrueSheet.dismissAll = rejectStatic;
1201
+ //# sourceMappingURL=TrueSheet.web.js.map