@lodev09/react-native-true-sheet 4.0.0-beta.0 → 4.0.0-beta.2

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