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