@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,1740 @@
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+ import { Presence } from '@radix-ui/react-presence';
7
+
8
+ import { DrawerContext, useDrawerContext, type DragEvent } from './context';
9
+ import './style.css';
10
+
11
+ import { isIOS, isMobileFirefox } from './browser';
12
+ import {
13
+ BORDER_RADIUS,
14
+ CLOSE_THRESHOLD,
15
+ DRAG_CLASS,
16
+ NESTED_DISPLACEMENT,
17
+ SCROLL_LOCK_TIMEOUT,
18
+ TRANSITIONS,
19
+ VELOCITY_THRESHOLD,
20
+ WINDOW_TOP_OFFSET,
21
+ } from './constants';
22
+ import { dampenValue, getTranslate, isVertical, reset, set } from './helpers';
23
+ import type { DrawerDirection } from './types';
24
+ import { useComposedRefs } from './use-composed-refs';
25
+ import { useControllableState } from './use-controllable-state';
26
+ import { usePositionFixed } from './use-position-fixed';
27
+ import { isInput, isScrollable, usePreventScroll } from './use-prevent-scroll';
28
+ import { useScaleBackground } from './use-scale-background';
29
+ import { useSnapPoints } from './use-snap-points';
30
+
31
+ export interface WithFadeFromProps {
32
+ /**
33
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
34
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
35
+ * You can also use px values, which doesn't take screen height into account.
36
+ */
37
+ snapPoints: (number | string)[];
38
+ /**
39
+ * Index of a `snapPoint` from which the overlay fade should be applied. Defaults to the last snap point.
40
+ */
41
+ fadeFromIndex: number;
42
+ }
43
+
44
+ export interface WithoutFadeFromProps {
45
+ /**
46
+ * Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up.
47
+ * Should go from least visible. Example `[0.2, 0.5, 0.8]`.
48
+ * You can also use px values, which doesn't take screen height into account.
49
+ */
50
+ snapPoints?: (number | string)[];
51
+ fadeFromIndex?: never;
52
+ }
53
+
54
+ export type DialogProps = {
55
+ activeSnapPoint?: number | string | null;
56
+ setActiveSnapPoint?: (snapPoint: number | string | null) => void;
57
+ children?: React.ReactNode;
58
+ open?: boolean;
59
+ /**
60
+ * Number between 0 and 1 that determines when the drawer should be closed.
61
+ * Example: threshold of 0.5 would close the drawer if the user swiped for 50% of the height of the drawer or more.
62
+ * @default 0.25
63
+ */
64
+ closeThreshold?: number;
65
+ /**
66
+ * When `true` the `body` doesn't get any styles assigned from Vaul
67
+ */
68
+ noBodyStyles?: boolean;
69
+ onOpenChange?: (open: boolean) => void;
70
+ shouldScaleBackground?: boolean;
71
+ /**
72
+ * When `false` we don't change body's background color when the drawer is open.
73
+ * @default true
74
+ */
75
+ setBackgroundColorOnScale?: boolean;
76
+ /**
77
+ * Duration for which the drawer is not draggable after scrolling content inside of the drawer.
78
+ * @default 500ms
79
+ */
80
+ scrollLockTimeout?: number;
81
+ /**
82
+ * When `true`, don't move the drawer upwards if there's space, but rather only change it's height so it's fully scrollable when the keyboard is open
83
+ */
84
+ fixed?: boolean;
85
+ /**
86
+ * When `true` only allows the drawer to be dragged by the `<Drawer.Handle />` component.
87
+ * @default false
88
+ */
89
+ handleOnly?: boolean;
90
+ /**
91
+ * When `false` dragging, clicking outside, pressing esc, etc. will not close the drawer.
92
+ * Use this in comination with the `open` prop, otherwise you won't be able to open/close the drawer.
93
+ * @default true
94
+ */
95
+ dismissible?: boolean;
96
+ /**
97
+ * When `false` the drawer can't be dragged by the user. Programmatic snap-point
98
+ * changes still animate. Defaults to `true`.
99
+ */
100
+ draggable?: boolean;
101
+ onDrag?: (event: React.PointerEvent<HTMLDivElement>, percentageDragged: number) => void;
102
+ onRelease?: (event: React.PointerEvent<HTMLDivElement>, open: boolean) => void;
103
+ /**
104
+ * When `false` it allows to interact with elements outside of the drawer without closing it.
105
+ * @default true
106
+ */
107
+ modal?: boolean;
108
+ nested?: boolean;
109
+ onClose?: () => void;
110
+ /**
111
+ * Direction of the drawer. Can be `top` or `bottom`, `left`, `right`.
112
+ * @default 'bottom'
113
+ */
114
+ direction?: 'top' | 'bottom' | 'left' | 'right';
115
+ /**
116
+ * Opened by default, skips initial enter animation. Still reacts to `open` state changes
117
+ * @default false
118
+ */
119
+ defaultOpen?: boolean;
120
+ /**
121
+ * When set to `true` prevents scrolling on the document body on mount, and restores it on unmount.
122
+ * @default false
123
+ */
124
+ disablePreventScroll?: boolean;
125
+ /**
126
+ * When `true` Vaul will reposition inputs rather than scroll then into view if the keyboard is in the way.
127
+ * Setting it to `false` will fall back to the default browser behavior.
128
+ * @default true when {@link snapPoints} is defined
129
+ */
130
+ repositionInputs?: boolean;
131
+ /**
132
+ * Disabled velocity based swiping for snap points.
133
+ * This means that a snap point won't be skipped even if the velocity is high enough.
134
+ * Useful if each snap point in a drawer is equally important.
135
+ * @default false
136
+ */
137
+ snapToSequentialPoint?: boolean;
138
+ container?: HTMLElement | null;
139
+ /**
140
+ * Gets triggered after the open or close animation ends, it receives an `open` argument with the `open` state of the drawer by the time the function was triggered.
141
+ * Useful to revert any state changes for example.
142
+ */
143
+ onAnimationEnd?: (open: boolean) => void;
144
+ /**
145
+ * Fires on every animation frame while the drawer is open with the drawer's
146
+ * current top edge in the viewport (px). Emits during drag, snap, and the
147
+ * open/close transitions.
148
+ */
149
+ onPositionChange?: (position: number) => void;
150
+ preventScrollRestoration?: boolean;
151
+ autoFocus?: boolean;
152
+ /**
153
+ * Renders the drawer as a floating card offset from the bottom edge so it
154
+ * doesn't visually attach to the viewport. Snap points are computed against
155
+ * the reduced floating area, so {@link detachedOffset} is preserved during
156
+ * drag and snap.
157
+ * @default false
158
+ */
159
+ detached?: boolean;
160
+ /**
161
+ * Gap (in px) between the drawer's bottom edge and the viewport bottom when
162
+ * {@link detached} is `true`.
163
+ * @default 0
164
+ */
165
+ detachedOffset?: number;
166
+ /**
167
+ * Corner radius (in px) applied to the clip wrapper's bottom when
168
+ * {@link detached} is `true`, so the floating card's bottom edge stays
169
+ * rounded while it's clipped at the floating anchor.
170
+ * @default 0
171
+ */
172
+ detachedRadius?: number;
173
+ /**
174
+ * Extra styles merged into the detached clip wrapper. Use this to match the
175
+ * wrapper's horizontal bounds to the drawer's on desktop (e.g. `maxWidth` +
176
+ * auto margins) so its rounded-bottom clip aligns with the drawer.
177
+ */
178
+ detachedWrapperStyle?: React.CSSProperties;
179
+ /**
180
+ * Caps the visible sheet height (in px) so full and 'auto' snap points
181
+ * respect a user-specified ceiling.
182
+ */
183
+ maxContentHeight?: number;
184
+ /**
185
+ * Resolved height (in px) for the 'peek' snap point — the caller measures
186
+ * its header/footer and passes the combined height.
187
+ */
188
+ peekHeight?: number;
189
+ /**
190
+ * When `false` the first snap on mount is applied without a transition so
191
+ * the sheet appears at its target detent instantly. Defaults to `true`.
192
+ */
193
+ initialAnimated?: boolean;
194
+ /**
195
+ * Fires when the auto-size wrapper's measured content height changes.
196
+ * Useful for callers that want to size the surrounding card to fit
197
+ * content (e.g. iPad-style form sheets).
198
+ */
199
+ onContentHeightChange?: (height: number) => void;
200
+ /**
201
+ * Overrides the measured content height used to resolve the 'auto' snap
202
+ * point. Used when the caller bounds the content to the visible sheet
203
+ * (e.g. a plugged scrollable) so the auto-size wrapper can't be measured
204
+ * from natural flow.
205
+ */
206
+ contentHeight?: number;
207
+ } & (WithFadeFromProps | WithoutFadeFromProps);
208
+
209
+ export function Root({
210
+ open: openProp,
211
+ onOpenChange,
212
+ children,
213
+ onDrag: onDragProp,
214
+ onRelease: onReleaseProp,
215
+ snapPoints,
216
+ shouldScaleBackground = false,
217
+ setBackgroundColorOnScale = true,
218
+ closeThreshold = CLOSE_THRESHOLD,
219
+ scrollLockTimeout = SCROLL_LOCK_TIMEOUT,
220
+ dismissible = true,
221
+ draggable = true,
222
+ handleOnly = false,
223
+ fadeFromIndex = snapPoints && snapPoints.length - 1,
224
+ activeSnapPoint: activeSnapPointProp,
225
+ setActiveSnapPoint: setActiveSnapPointProp,
226
+ fixed,
227
+ modal = true,
228
+ onClose,
229
+ nested,
230
+ noBodyStyles = false,
231
+ direction = 'bottom',
232
+ defaultOpen = false,
233
+ disablePreventScroll = true,
234
+ snapToSequentialPoint = false,
235
+ preventScrollRestoration = false,
236
+ repositionInputs = true,
237
+ onAnimationEnd,
238
+ onPositionChange,
239
+ container,
240
+ autoFocus = false,
241
+ detached = false,
242
+ detachedOffset = 0,
243
+ detachedRadius = 0,
244
+ detachedWrapperStyle,
245
+ maxContentHeight,
246
+ peekHeight,
247
+ initialAnimated = true,
248
+ onContentHeightChange,
249
+ contentHeight: contentHeightProp,
250
+ }: DialogProps) {
251
+ const [isOpen = false, setIsOpen] = useControllableState({
252
+ defaultProp: defaultOpen,
253
+ prop: openProp,
254
+ onChange: (o: boolean) => {
255
+ onOpenChange?.(o);
256
+
257
+ if (!o && !nested) {
258
+ restorePositionSetting();
259
+ }
260
+
261
+ setTimeout(() => {
262
+ onAnimationEnd?.(o);
263
+ }, TRANSITIONS.DURATION * 1000);
264
+ },
265
+ });
266
+ const [hasBeenOpened, setHasBeenOpened] = React.useState<boolean>(false);
267
+ const [isDragging, setIsDragging] = React.useState<boolean>(false);
268
+ const [justReleased, setJustReleased] = React.useState<boolean>(false);
269
+ const overlayRef = React.useRef<HTMLDivElement>(null);
270
+ const openTime = React.useRef<Date | null>(null);
271
+ const dragStartTime = React.useRef<Date | null>(null);
272
+ const dragEndTime = React.useRef<Date | null>(null);
273
+ const lastTimeDragPrevented = React.useRef<Date | null>(null);
274
+ const isAllowedToDrag = React.useRef<boolean>(false);
275
+ const nestedOpenChangeTimer = React.useRef<NodeJS.Timeout | null>(null);
276
+ const pointerStart = React.useRef(0);
277
+ const keyboardIsOpen = React.useRef(false);
278
+ const shouldAnimate = React.useRef(!defaultOpen);
279
+ const previousDiffFromInitial = React.useRef(0);
280
+ const drawerRef = React.useRef<HTMLDivElement>(null);
281
+ const drawerHeightRef = React.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
282
+ const drawerWidthRef = React.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
283
+ const initialDrawerHeight = React.useRef(0);
284
+ const [measuredContentHeight, setContentHeight] = React.useState(0);
285
+ const contentHeight = contentHeightProp ?? measuredContentHeight;
286
+
287
+ const onContentHeightChangeRef = React.useRef(onContentHeightChange);
288
+ React.useEffect(() => {
289
+ onContentHeightChangeRef.current = onContentHeightChange;
290
+ });
291
+ React.useEffect(() => {
292
+ onContentHeightChangeRef.current?.(measuredContentHeight);
293
+ }, [measuredContentHeight]);
294
+
295
+ const onSnapPointChange = React.useCallback((activeSnapPointIndex: number) => {
296
+ // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
297
+ if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1)
298
+ openTime.current = new Date();
299
+ }, []);
300
+
301
+ const {
302
+ activeSnapPoint,
303
+ activeSnapPointIndex,
304
+ setActiveSnapPoint,
305
+ onRelease: onReleaseSnapPoints,
306
+ snapPointsOffset,
307
+ onDrag: onDragSnapPoints,
308
+ shouldFade,
309
+ getPercentageDragged: getSnapPointsPercentageDragged,
310
+ } = useSnapPoints({
311
+ snapPoints,
312
+ activeSnapPointProp,
313
+ setActiveSnapPointProp,
314
+ drawerRef,
315
+ fadeFromIndex,
316
+ overlayRef,
317
+ onSnapPointChange,
318
+ direction,
319
+ container,
320
+ snapToSequentialPoint,
321
+ isOpen,
322
+ contentHeight,
323
+ detachedOffset: detached ? detachedOffset : 0,
324
+ maxContentHeight,
325
+ peekHeight,
326
+ initialAnimated,
327
+ });
328
+
329
+ usePreventScroll({
330
+ isDisabled:
331
+ !isOpen ||
332
+ isDragging ||
333
+ !modal ||
334
+ justReleased ||
335
+ !hasBeenOpened ||
336
+ !repositionInputs ||
337
+ !disablePreventScroll,
338
+ });
339
+
340
+ const { restorePositionSetting } = usePositionFixed({
341
+ isOpen,
342
+ modal,
343
+ nested: nested ?? false,
344
+ hasBeenOpened,
345
+ preventScrollRestoration,
346
+ noBodyStyles,
347
+ });
348
+
349
+ // While the sheet itself is being dragged, scrollables in the touched chain
350
+ // are frozen (overflow: hidden). Touch browsers latch the scroll gesture at
351
+ // touchstart and ignore preventDefault once scrolling has started, so making
352
+ // the scroller non-scrollable mid-gesture is the only reliable way to keep
353
+ // the content from panning along with the sheet.
354
+ const frozenScrollablesRef = React.useRef<
355
+ { element: HTMLElement; overflowX: string; overflowY: string }[] | null
356
+ >(null);
357
+
358
+ function freezeScrollables(target: EventTarget) {
359
+ if (frozenScrollablesRef.current) return;
360
+ const frozen: { element: HTMLElement; overflowX: string; overflowY: string }[] = [];
361
+ let element = target instanceof HTMLElement ? target : null;
362
+ while (element && element !== drawerRef.current) {
363
+ if (isScrollable(element)) {
364
+ frozen.push({
365
+ element,
366
+ overflowX: element.style.overflowX,
367
+ overflowY: element.style.overflowY,
368
+ });
369
+ element.style.overflowX = 'hidden';
370
+ element.style.overflowY = 'hidden';
371
+ }
372
+ element = element.parentElement;
373
+ }
374
+ frozenScrollablesRef.current = frozen;
375
+ }
376
+
377
+ function unfreezeScrollables() {
378
+ const frozen = frozenScrollablesRef.current;
379
+ if (!frozen) return;
380
+ frozenScrollablesRef.current = null;
381
+ for (const { element, overflowX, overflowY } of frozen) {
382
+ element.style.overflowX = overflowX;
383
+ element.style.overflowY = overflowY;
384
+ }
385
+ }
386
+
387
+ function getScale() {
388
+ return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
389
+ }
390
+
391
+ function onPress(event: React.PointerEvent<HTMLDivElement>) {
392
+ if (!draggable) return;
393
+ if (!dismissible && !snapPoints) return;
394
+ if (drawerRef.current && !drawerRef.current.contains(event.target as Node)) return;
395
+
396
+ drawerHeightRef.current = drawerRef.current?.getBoundingClientRect().height || 0;
397
+ drawerWidthRef.current = drawerRef.current?.getBoundingClientRect().width || 0;
398
+ setIsDragging(true);
399
+ dragStartTime.current = new Date();
400
+
401
+ // iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging
402
+ if (isIOS()) {
403
+ window.addEventListener('touchend', () => (isAllowedToDrag.current = false), { once: true });
404
+ }
405
+ // Ensure we maintain correct pointer capture even when going outside of the drawer
406
+ (event.target as HTMLElement).setPointerCapture(event.pointerId);
407
+
408
+ pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
409
+ }
410
+
411
+ function shouldDrag(el: EventTarget, isDraggingInDirection: boolean) {
412
+ let element = el as HTMLElement;
413
+ const highlightedText = window.getSelection()?.toString();
414
+ const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
415
+ const date = new Date();
416
+
417
+ // Fixes https://github.com/emilkowalski/vaul/issues/483
418
+ if (element.tagName === 'SELECT') {
419
+ return false;
420
+ }
421
+
422
+ if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {
423
+ return false;
424
+ }
425
+
426
+ if (direction === 'right' || direction === 'left') {
427
+ return true;
428
+ }
429
+
430
+ // Allow scrolling when animating
431
+ if (openTime.current && date.getTime() - openTime.current.getTime() < 500) {
432
+ return false;
433
+ }
434
+
435
+ if (swipeAmount !== null) {
436
+ // Translated past the drag threshold → keep dragging. Below the last
437
+ // snap point the threshold is 0, so the sheet always wins over content
438
+ // scrolling. At the last snap point the threshold is its resting
439
+ // translate — which can still be > 0 when the max detent < 1 — so an
440
+ // at-rest sheet falls through to the scroll checks and content
441
+ // scrolling wins, matching native. Mid-drag/mid-animation the sheet is
442
+ // displaced past rest and still wins.
443
+ const atLastSnapPoint = snapPoints && activeSnapPointIndex === snapPoints.length - 1;
444
+ const restOffset = atLastSnapPoint ? (snapPointsOffset?.[activeSnapPointIndex!] ?? 0) : 0;
445
+ if (direction === 'bottom' ? swipeAmount > restOffset + 1 : swipeAmount < restOffset - 1) {
446
+ return true;
447
+ }
448
+ }
449
+
450
+ // Don't drag if there's highlighted text
451
+ if (highlightedText && highlightedText.length > 0) {
452
+ return false;
453
+ }
454
+
455
+ // Disallow dragging if drawer was scrolled within `scrollLockTimeout`.
456
+ // Don't re-arm the timestamp here — a prevented drag attempt is not a
457
+ // scroll, and re-arming would keep the lock alive for as long as the
458
+ // finger moves, deadening the whole gesture instead of just the first
459
+ // `scrollLockTimeout` ms after the last real scroll.
460
+ if (
461
+ lastTimeDragPrevented.current &&
462
+ date.getTime() - lastTimeDragPrevented.current.getTime() < scrollLockTimeout &&
463
+ swipeAmount === 0
464
+ ) {
465
+ return false;
466
+ }
467
+
468
+ if (isDraggingInDirection) {
469
+ lastTimeDragPrevented.current = date;
470
+
471
+ // We are dragging down so we should allow scrolling
472
+ return false;
473
+ }
474
+
475
+ // Keep climbing up the DOM tree as long as there's a parent
476
+ while (element) {
477
+ // Check if the element is scrollable
478
+ if (element.scrollHeight > element.clientHeight) {
479
+ // `> 0`, not `!== 0`: Safari reports a negative scrollTop during the
480
+ // rubber-band bounce at the top — that's "at the top" for drag
481
+ // purposes, and treating it as scrolled would arm the scroll lock and
482
+ // delay the sheet drag until the bounce fully settles.
483
+ if (element.scrollTop > 0) {
484
+ lastTimeDragPrevented.current = new Date();
485
+
486
+ // The element is scrollable and not scrolled to the top, so don't drag
487
+ return false;
488
+ }
489
+
490
+ if (element.getAttribute('role') === 'dialog') {
491
+ return true;
492
+ }
493
+ }
494
+
495
+ // Move up to the parent element
496
+ element = element.parentNode as HTMLElement;
497
+ }
498
+
499
+ // No scrollable parents not scrolled to the top found, so drag
500
+ return true;
501
+ }
502
+
503
+ function drag(event: DragEvent, pointerEvent?: React.PointerEvent<HTMLDivElement>) {
504
+ if (!drawerRef.current) {
505
+ return;
506
+ }
507
+
508
+ // We need to know how much of the drawer has been dragged in percentages so that we can transform background accordingly
509
+ if (isDragging) {
510
+ const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
511
+ const draggedDistance =
512
+ (pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX)) *
513
+ directionMultiplier;
514
+ const isDraggingInDirection = draggedDistance > 0;
515
+
516
+ // Pre condition for disallowing dragging in the close direction.
517
+ const noCloseSnapPointsPreCondition = snapPoints && !dismissible && !isDraggingInDirection;
518
+
519
+ // Disallow dragging down to close when first snap point is the active one and dismissible prop is set to false.
520
+ if (noCloseSnapPointsPreCondition && activeSnapPointIndex === 0) return;
521
+
522
+ // We need to capture last time when drag with scroll was triggered and have a timeout between
523
+ const absDraggedDistance = Math.abs(draggedDistance);
524
+ const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
525
+ const drawerDimension =
526
+ direction === 'bottom' || direction === 'top'
527
+ ? drawerHeightRef.current
528
+ : drawerWidthRef.current;
529
+
530
+ // Calculate the percentage dragged, where 1 is the closed position
531
+ let percentageDragged = absDraggedDistance / drawerDimension;
532
+ const snapPointPercentageDragged = getSnapPointsPercentageDragged(
533
+ absDraggedDistance,
534
+ isDraggingInDirection
535
+ );
536
+
537
+ if (snapPointPercentageDragged !== null) {
538
+ percentageDragged = snapPointPercentageDragged;
539
+ }
540
+
541
+ // Disallow close dragging beyond the smallest snap point.
542
+ if (noCloseSnapPointsPreCondition && percentageDragged >= 1) {
543
+ return;
544
+ }
545
+
546
+ if (!isAllowedToDrag.current) {
547
+ if (!shouldDrag(event.target, isDraggingInDirection)) return;
548
+ drawerRef.current.classList.add(DRAG_CLASS);
549
+ // If shouldDrag gave true once after pressing down on the drawer, we set isAllowedToDrag to true and it will remain true until we let go, there's no reason to disable dragging mid way, ever, and that's the solution to it
550
+ isAllowedToDrag.current = true;
551
+ // Touch pans latched onto a scroller would keep scrolling the content
552
+ // along with the sheet drag — freeze them for the drag's duration.
553
+ if (event.pointerType !== 'mouse') freezeScrollables(event.target);
554
+ // Drag can engage mid-gesture (content scrolled back to its top under
555
+ // the same finger, or the scroll lock expiring). Re-anchor and start
556
+ // moving on the next tick so the sheet tracks the finger from here
557
+ // instead of jumping by the distance the gesture already consumed.
558
+ pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
559
+ return;
560
+ }
561
+ set(drawerRef.current, {
562
+ transition: 'none',
563
+ });
564
+
565
+ set(overlayRef.current, {
566
+ transition: 'none',
567
+ });
568
+
569
+ if (pointerEvent) onDragProp?.(pointerEvent, percentageDragged);
570
+
571
+ if (snapPoints) {
572
+ onDragSnapPoints({ draggedDistance });
573
+ }
574
+
575
+ // Run this only if snapPoints are not defined or if we are at the last snap point (highest one)
576
+ if (isDraggingInDirection && !snapPoints) {
577
+ const dampenedDraggedDistance = dampenValue(draggedDistance);
578
+
579
+ const translateValue = Math.min(dampenedDraggedDistance * -1, 0) * directionMultiplier;
580
+ set(drawerRef.current, {
581
+ transform: isVertical(direction)
582
+ ? `translate3d(0, ${translateValue}px, 0)`
583
+ : `translate3d(${translateValue}px, 0, 0)`,
584
+ });
585
+ return;
586
+ }
587
+
588
+ const opacityValue = 1 - percentageDragged;
589
+
590
+ if (shouldFade || (fadeFromIndex && activeSnapPointIndex === fadeFromIndex - 1)) {
591
+ set(
592
+ overlayRef.current,
593
+ {
594
+ opacity: `${opacityValue}`,
595
+ transition: 'none',
596
+ },
597
+ true
598
+ );
599
+ }
600
+
601
+ if (wrapper && overlayRef.current && shouldScaleBackground) {
602
+ // Calculate percentageDragged as a fraction (0 to 1)
603
+ const scaleValue = Math.min(getScale() + percentageDragged * (1 - getScale()), 1);
604
+ const borderRadiusValue = 8 - percentageDragged * 8;
605
+
606
+ const translateValue = Math.max(0, 14 - percentageDragged * 14);
607
+
608
+ set(
609
+ wrapper,
610
+ {
611
+ borderRadius: `${borderRadiusValue}px`,
612
+ transform: isVertical(direction)
613
+ ? `scale(${scaleValue}) translate3d(0, ${translateValue}px, 0)`
614
+ : `scale(${scaleValue}) translate3d(${translateValue}px, 0, 0)`,
615
+ transition: 'none',
616
+ },
617
+ true
618
+ );
619
+ }
620
+
621
+ if (!snapPoints) {
622
+ const translateValue = absDraggedDistance * directionMultiplier;
623
+
624
+ set(drawerRef.current, {
625
+ transform: isVertical(direction)
626
+ ? `translate3d(0, ${translateValue}px, 0)`
627
+ : `translate3d(${translateValue}px, 0, 0)`,
628
+ });
629
+ }
630
+ }
631
+ }
632
+
633
+ React.useEffect(() => {
634
+ window.requestAnimationFrame(() => {
635
+ shouldAnimate.current = true;
636
+ });
637
+ }, []);
638
+
639
+ // Reset to the first snap point on every open so a prior session's active snap
640
+ // (kept in state by `useControllableState` after dismissal) doesn't leak into
641
+ // the next present. Skipped when `activeSnapPoint` is controlled externally.
642
+ React.useEffect(() => {
643
+ if (isOpen && snapPoints && activeSnapPointProp === undefined) {
644
+ setActiveSnapPoint(snapPoints[0]);
645
+ }
646
+ }, [isOpen]);
647
+
648
+ const onPositionChangeRef = React.useRef(onPositionChange);
649
+ React.useEffect(() => {
650
+ onPositionChangeRef.current = onPositionChange;
651
+ });
652
+
653
+ React.useEffect(() => {
654
+ function onVisualViewportChange() {
655
+ if (!drawerRef.current || !repositionInputs) return;
656
+
657
+ const focusedElement = document.activeElement as HTMLElement;
658
+ if (isInput(focusedElement) || keyboardIsOpen.current) {
659
+ const visualViewportHeight = window.visualViewport?.height || 0;
660
+ const totalHeight = window.innerHeight;
661
+ // This is the height of the keyboard
662
+ let diffFromInitial = totalHeight - visualViewportHeight;
663
+ const drawerHeight = drawerRef.current.getBoundingClientRect().height || 0;
664
+ // Adjust drawer height only if it's tall enough
665
+ const isTallEnough = drawerHeight > totalHeight * 0.8;
666
+
667
+ if (!initialDrawerHeight.current) {
668
+ initialDrawerHeight.current = drawerHeight;
669
+ }
670
+ const offsetFromTop = drawerRef.current.getBoundingClientRect().top;
671
+
672
+ // visualViewport height may change due to somq e subtle changes to the keyboard. Checking if the height changed by 60 or more will make sure that they keyboard really changed its open state.
673
+ if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 60) {
674
+ keyboardIsOpen.current = !keyboardIsOpen.current;
675
+ }
676
+
677
+ if (snapPoints && snapPoints.length > 0 && snapPointsOffset && activeSnapPointIndex) {
678
+ const activeSnapPointHeight = snapPointsOffset[activeSnapPointIndex] || 0;
679
+ diffFromInitial += activeSnapPointHeight;
680
+ }
681
+ previousDiffFromInitial.current = diffFromInitial;
682
+ // We don't have to change the height if the input is in view, when we are here we are in the opened keyboard state so we can correctly check if the input is in view
683
+ if (drawerHeight > visualViewportHeight || keyboardIsOpen.current) {
684
+ const height = drawerRef.current.getBoundingClientRect().height;
685
+ let newDrawerHeight = height;
686
+
687
+ if (height > visualViewportHeight) {
688
+ newDrawerHeight =
689
+ visualViewportHeight - (isTallEnough ? offsetFromTop : WINDOW_TOP_OFFSET);
690
+ }
691
+ // When fixed, don't move the drawer upwards if there's space, but rather only change it's height so it's fully scrollable when the keyboard is open
692
+ if (fixed) {
693
+ drawerRef.current.style.height = `${height - Math.max(diffFromInitial, 0)}px`;
694
+ } else {
695
+ drawerRef.current.style.height = `${Math.max(newDrawerHeight, visualViewportHeight - offsetFromTop)}px`;
696
+ }
697
+ } else if (!isMobileFirefox()) {
698
+ drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
699
+ }
700
+
701
+ if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
702
+ drawerRef.current.style.bottom = '0px';
703
+ } else {
704
+ // Negative bottom value would never make sense
705
+ drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
706
+ }
707
+ }
708
+ }
709
+
710
+ window.visualViewport?.addEventListener('resize', onVisualViewportChange);
711
+ return () => window.visualViewport?.removeEventListener('resize', onVisualViewportChange);
712
+ }, [activeSnapPointIndex, snapPoints, snapPointsOffset]);
713
+
714
+ function closeDrawer(fromWithin?: boolean) {
715
+ cancelDrag();
716
+ onClose?.();
717
+
718
+ if (!fromWithin) {
719
+ setIsOpen(false);
720
+ }
721
+ }
722
+
723
+ function resetDrawer() {
724
+ if (!drawerRef.current) return;
725
+ const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
726
+ const currentSwipeAmount = getTranslate(drawerRef.current, direction);
727
+
728
+ set(drawerRef.current, {
729
+ transform: 'translate3d(0, 0, 0)',
730
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
731
+ });
732
+
733
+ set(overlayRef.current, {
734
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
735
+ opacity: '1',
736
+ });
737
+
738
+ // Don't reset background if swiped upwards
739
+ if (shouldScaleBackground && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) {
740
+ set(
741
+ wrapper,
742
+ {
743
+ borderRadius: `${BORDER_RADIUS}px`,
744
+ overflow: 'hidden',
745
+ ...(isVertical(direction)
746
+ ? {
747
+ transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
748
+ transformOrigin: 'top',
749
+ }
750
+ : {
751
+ transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
752
+ transformOrigin: 'left',
753
+ }),
754
+ transitionProperty: 'transform, border-radius',
755
+ transitionDuration: `${TRANSITIONS.DURATION}s`,
756
+ transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
757
+ },
758
+ true
759
+ );
760
+ }
761
+ }
762
+
763
+ function cancelDrag() {
764
+ if (!isDragging || !drawerRef.current) return;
765
+
766
+ drawerRef.current.classList.remove(DRAG_CLASS);
767
+ isAllowedToDrag.current = false;
768
+ unfreezeScrollables();
769
+ setIsDragging(false);
770
+ dragEndTime.current = new Date();
771
+ }
772
+
773
+ function release(event: DragEvent | null, pointerEvent?: React.PointerEvent<HTMLDivElement>) {
774
+ if (!isDragging || !drawerRef.current) return;
775
+
776
+ drawerRef.current.classList.remove(DRAG_CLASS);
777
+ isAllowedToDrag.current = false;
778
+ unfreezeScrollables();
779
+ setIsDragging(false);
780
+ dragEndTime.current = new Date();
781
+ const swipeAmount = getTranslate(drawerRef.current, direction);
782
+
783
+ // Drag overshoot below the lowest snap point translates the detached
784
+ // wrapper while the drawer stays pinned (see onDrag in use-snap-points) —
785
+ // common when a clamped 'auto' puts the lowest snap point at 0. Count the
786
+ // wrapper's translation as movement, or the release is swallowed and the
787
+ // sheet is left stuck at the overshoot position.
788
+ const wrapper = drawerRef.current.closest<HTMLElement>('[data-vaul-detached-wrapper]');
789
+ const wrapperSwipeAmount = wrapper ? getTranslate(wrapper, direction) : null;
790
+ const hasMoved = Boolean(swipeAmount) || Boolean(wrapperSwipeAmount);
791
+
792
+ if (!event || !shouldDrag(event.target, false) || !hasMoved || Number.isNaN(swipeAmount))
793
+ return;
794
+
795
+ if (dragStartTime.current === null) return;
796
+
797
+ const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
798
+ const distMoved = pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX);
799
+ const velocity = Math.abs(distMoved) / timeTaken;
800
+
801
+ if (velocity > 0.05) {
802
+ // `justReleased` is needed to prevent the drawer from focusing on an input when the drag ends, as it's not the intent most of the time.
803
+ setJustReleased(true);
804
+
805
+ setTimeout(() => {
806
+ setJustReleased(false);
807
+ }, 200);
808
+ }
809
+
810
+ if (snapPoints) {
811
+ const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
812
+ onReleaseSnapPoints({
813
+ draggedDistance: distMoved * directionMultiplier,
814
+ closeDrawer,
815
+ velocity,
816
+ dismissible,
817
+ });
818
+ if (pointerEvent) onReleaseProp?.(pointerEvent, true);
819
+ return;
820
+ }
821
+
822
+ // Moved upwards, don't do anything
823
+ if (direction === 'bottom' || direction === 'right' ? distMoved > 0 : distMoved < 0) {
824
+ resetDrawer();
825
+ if (pointerEvent) onReleaseProp?.(pointerEvent, true);
826
+ return;
827
+ }
828
+
829
+ if (velocity > VELOCITY_THRESHOLD) {
830
+ closeDrawer();
831
+ if (pointerEvent) onReleaseProp?.(pointerEvent, false);
832
+ return;
833
+ }
834
+
835
+ const visibleDrawerHeight = Math.min(
836
+ drawerRef.current.getBoundingClientRect().height ?? 0,
837
+ window.innerHeight
838
+ );
839
+ const visibleDrawerWidth = Math.min(
840
+ drawerRef.current.getBoundingClientRect().width ?? 0,
841
+ window.innerWidth
842
+ );
843
+
844
+ const isHorizontalSwipe = direction === 'left' || direction === 'right';
845
+ if (
846
+ Math.abs(swipeAmount ?? 0) >=
847
+ (isHorizontalSwipe ? visibleDrawerWidth : visibleDrawerHeight) * closeThreshold
848
+ ) {
849
+ closeDrawer();
850
+ if (pointerEvent) onReleaseProp?.(pointerEvent, false);
851
+ return;
852
+ }
853
+
854
+ if (pointerEvent) onReleaseProp?.(pointerEvent, true);
855
+ resetDrawer();
856
+ }
857
+
858
+ React.useEffect(() => {
859
+ // Trigger enter animation without using CSS animation
860
+ if (isOpen) {
861
+ set(document.documentElement, {
862
+ scrollBehavior: 'auto',
863
+ });
864
+
865
+ openTime.current = new Date();
866
+ }
867
+
868
+ return () => {
869
+ reset(document.documentElement, 'scrollBehavior');
870
+ };
871
+ }, [isOpen]);
872
+
873
+ function onNestedOpenChange(o: boolean) {
874
+ const scale = o ? (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth : 1;
875
+
876
+ const initialTranslate = o ? -NESTED_DISPLACEMENT : 0;
877
+
878
+ if (nestedOpenChangeTimer.current) {
879
+ window.clearTimeout(nestedOpenChangeTimer.current);
880
+ }
881
+
882
+ set(drawerRef.current, {
883
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
884
+ transform: isVertical(direction)
885
+ ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)`
886
+ : `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`,
887
+ });
888
+
889
+ if (!o && drawerRef.current) {
890
+ nestedOpenChangeTimer.current = setTimeout(() => {
891
+ const translateValue = getTranslate(drawerRef.current as HTMLElement, direction);
892
+ set(drawerRef.current, {
893
+ transition: 'none',
894
+ transform: isVertical(direction)
895
+ ? `translate3d(0, ${translateValue}px, 0)`
896
+ : `translate3d(${translateValue}px, 0, 0)`,
897
+ });
898
+ }, 500);
899
+ }
900
+ }
901
+
902
+ function onNestedDrag(_event: React.PointerEvent<HTMLDivElement>, percentageDragged: number) {
903
+ if (percentageDragged < 0) return;
904
+
905
+ const initialScale = (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth;
906
+ const newScale = initialScale + percentageDragged * (1 - initialScale);
907
+ const newTranslate = -NESTED_DISPLACEMENT + percentageDragged * NESTED_DISPLACEMENT;
908
+
909
+ set(drawerRef.current, {
910
+ transform: isVertical(direction)
911
+ ? `scale(${newScale}) translate3d(0, ${newTranslate}px, 0)`
912
+ : `scale(${newScale}) translate3d(${newTranslate}px, 0, 0)`,
913
+ transition: 'none',
914
+ });
915
+ }
916
+
917
+ function onNestedRelease(_event: React.PointerEvent<HTMLDivElement>, o: boolean) {
918
+ const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
919
+ const scale = o ? (dim - NESTED_DISPLACEMENT) / dim : 1;
920
+ const translate = o ? -NESTED_DISPLACEMENT : 0;
921
+
922
+ if (o) {
923
+ set(drawerRef.current, {
924
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
925
+ transform: isVertical(direction)
926
+ ? `scale(${scale}) translate3d(0, ${translate}px, 0)`
927
+ : `scale(${scale}) translate3d(${translate}px, 0, 0)`,
928
+ });
929
+ }
930
+ }
931
+
932
+ return (
933
+ <DialogPrimitive.Root
934
+ defaultOpen={defaultOpen}
935
+ onOpenChange={(open) => {
936
+ if (!dismissible && !open) return;
937
+ if (open) {
938
+ setHasBeenOpened(true);
939
+ } else {
940
+ closeDrawer(true);
941
+ }
942
+
943
+ setIsOpen(open);
944
+ }}
945
+ open={isOpen}
946
+ // Always non-modal at the Radix level — Radix's modal mode locks
947
+ // body.style.pointerEvents and its restore on layer unmount is buggy
948
+ // (see git history). Vaul's own overlay handles click-trapping; the
949
+ // overlay sets pointer-events: none below fadeFromIndex so clicks
950
+ // pass through to the page (matches native dimmedDetentIndex). Vaul's
951
+ // own `modal` prop still drives overlay rendering and click-outside
952
+ // behavior below.
953
+ modal={false}
954
+ >
955
+ <DrawerContext.Provider
956
+ value={{
957
+ activeSnapPoint,
958
+ snapPoints,
959
+ setActiveSnapPoint,
960
+ drawerRef,
961
+ overlayRef,
962
+ onOpenChange,
963
+ onPress,
964
+ onRelease: (event) => release(event, event ?? undefined),
965
+ onDrag: (event) => drag(event, event),
966
+ onTouchDrag: (event, pointerEvent) => drag(event, pointerEvent),
967
+ onTouchRelease: (event, pointerEvent) => release(event, pointerEvent),
968
+ dismissible,
969
+ shouldAnimate,
970
+ handleOnly,
971
+ isOpen,
972
+ isDragging,
973
+ shouldFade,
974
+ closeDrawer,
975
+ onNestedDrag,
976
+ onNestedOpenChange,
977
+ onNestedRelease,
978
+ keyboardIsOpen,
979
+ modal,
980
+ snapPointsOffset,
981
+ activeSnapPointIndex,
982
+ fadeFromIndex,
983
+ direction,
984
+ shouldScaleBackground,
985
+ setBackgroundColorOnScale,
986
+ noBodyStyles,
987
+ container,
988
+ autoFocus,
989
+ onPositionChangeRef,
990
+ setContentHeight,
991
+ detached,
992
+ detachedOffset: detached ? detachedOffset : 0,
993
+ detachedRadius: detached ? detachedRadius : 0,
994
+ detachedWrapperStyle,
995
+ }}
996
+ >
997
+ {children}
998
+ </DrawerContext.Provider>
999
+ </DialogPrimitive.Root>
1000
+ );
1001
+ }
1002
+
1003
+ export const Overlay = React.forwardRef<
1004
+ HTMLDivElement,
1005
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
1006
+ >(({ style, ...rest }, ref) => {
1007
+ const {
1008
+ overlayRef,
1009
+ snapPoints,
1010
+ onRelease,
1011
+ shouldFade,
1012
+ isOpen,
1013
+ modal,
1014
+ shouldAnimate,
1015
+ activeSnapPointIndex,
1016
+ fadeFromIndex,
1017
+ } = useDrawerContext();
1018
+ const composedRef = useComposedRefs(ref, overlayRef);
1019
+ const hasSnapPoints = snapPoints && snapPoints.length > 0;
1020
+ const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
1021
+ const onMouseUp = React.useCallback(
1022
+ (event: React.PointerEvent<HTMLDivElement>) => onRelease(event),
1023
+ [onRelease]
1024
+ );
1025
+
1026
+ React.useEffect(() => {
1027
+ if (hasSnapPoints) {
1028
+ window.requestAnimationFrame(() => {
1029
+ setDelayedSnapPoints(true);
1030
+ });
1031
+ }
1032
+ }, []);
1033
+
1034
+ // Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
1035
+ if (!modal) {
1036
+ return null;
1037
+ }
1038
+
1039
+ // When the active snap is below fadeFromIndex, the overlay is fully
1040
+ // transparent (CSS opacity: 0). Radix's DialogOverlayImpl sets inline
1041
+ // `pointer-events: auto` which would still catch clicks on the invisible
1042
+ // layer — drive this via React so it stays correct even before
1043
+ // `snapToPoint` runs (Presence defers the drawer/overlay mount, leaving
1044
+ // refs null on the first open effect pass).
1045
+ const isBelowFade =
1046
+ hasSnapPoints &&
1047
+ fadeFromIndex !== undefined &&
1048
+ typeof activeSnapPointIndex === 'number' &&
1049
+ activeSnapPointIndex < fadeFromIndex;
1050
+
1051
+ // Render our own overlay element instead of `DialogPrimitive.Overlay`:
1052
+ // Radix's Overlay returns null when the Dialog is non-modal, and we run
1053
+ // Radix as `modal={false}` to keep it from locking body pointer-events.
1054
+ // `Presence` keeps the node mounted through the closing animation
1055
+ // (`fadeOut`) before unmounting.
1056
+ return (
1057
+ <Presence present={isOpen}>
1058
+ <div
1059
+ onMouseUp={onMouseUp}
1060
+ ref={composedRef}
1061
+ data-state={isOpen ? 'open' : 'closed'}
1062
+ data-vaul-overlay=""
1063
+ data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
1064
+ data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
1065
+ data-vaul-snap-points-overlay={isOpen && shouldFade ? 'true' : 'false'}
1066
+ data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
1067
+ {...rest}
1068
+ style={overlayStyle(style, !!isBelowFade)}
1069
+ />
1070
+ </Presence>
1071
+ );
1072
+ });
1073
+
1074
+ Overlay.displayName = 'Drawer.Overlay';
1075
+
1076
+ const overlayStyle = (
1077
+ style: React.CSSProperties | undefined,
1078
+ isBelowFade: boolean
1079
+ ): React.CSSProperties => ({
1080
+ ...style,
1081
+ pointerEvents: isBelowFade ? 'none' : 'auto',
1082
+ });
1083
+
1084
+ export type ContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
1085
+ /**
1086
+ * Extra nodes rendered inside the detached clip wrapper as siblings of the
1087
+ * drawer. Use for floating elements (e.g. a footer) that should slide with
1088
+ * the wrapper on dismiss and drag-overshoot instead of staying pinned.
1089
+ */
1090
+ detachedSiblings?: React.ReactNode;
1091
+ };
1092
+
1093
+ export const Content = React.forwardRef<HTMLDivElement, ContentProps>(
1094
+ (
1095
+ {
1096
+ onPointerDownOutside,
1097
+ onEscapeKeyDown,
1098
+ style,
1099
+ onOpenAutoFocus,
1100
+ children,
1101
+ detachedSiblings,
1102
+ ...rest
1103
+ },
1104
+ ref
1105
+ ) => {
1106
+ const {
1107
+ drawerRef,
1108
+ onPress,
1109
+ onRelease,
1110
+ onDrag,
1111
+ onTouchDrag,
1112
+ onTouchRelease,
1113
+ keyboardIsOpen,
1114
+ snapPointsOffset,
1115
+ activeSnapPointIndex,
1116
+ fadeFromIndex,
1117
+ modal,
1118
+ isOpen,
1119
+ isDragging,
1120
+ direction,
1121
+ snapPoints,
1122
+ setActiveSnapPoint,
1123
+ dismissible,
1124
+ container,
1125
+ handleOnly,
1126
+ shouldAnimate,
1127
+ autoFocus,
1128
+ onPositionChangeRef,
1129
+ setContentHeight,
1130
+ detached,
1131
+ detachedOffset,
1132
+ detachedRadius,
1133
+ detachedWrapperStyle: detachedWrapperStyleProp,
1134
+ } = useDrawerContext();
1135
+ // Always measure the inner wrapper's natural height. The drawer itself may
1136
+ // be styled to a fixed viewport height, so we measure an inner wrapper
1137
+ // instead. Ref callback starts the observer as soon as the node mounts
1138
+ // (Radix Presence defers the portal mount past useEffect). The measurement
1139
+ // drives the 'auto' snap point and is also exposed via
1140
+ // `onContentHeightChange` for callers that size the surrounding card.
1141
+ const autoRoRef = React.useRef<ResizeObserver | null>(null);
1142
+ const setAutoSizeNode = React.useCallback(
1143
+ (node: HTMLDivElement | null) => {
1144
+ autoRoRef.current?.disconnect();
1145
+ if (!node) {
1146
+ autoRoRef.current = null;
1147
+ return;
1148
+ }
1149
+ const measure = () => setContentHeight(node.offsetHeight);
1150
+ measure();
1151
+ const ro = new ResizeObserver(measure);
1152
+ ro.observe(node);
1153
+ autoRoRef.current = ro;
1154
+ },
1155
+ [setContentHeight]
1156
+ );
1157
+
1158
+ const isBelowFade =
1159
+ snapPoints !== undefined &&
1160
+ snapPoints !== null &&
1161
+ fadeFromIndex !== undefined &&
1162
+ typeof activeSnapPointIndex === 'number' &&
1163
+ activeSnapPointIndex < fadeFromIndex;
1164
+ // Needed to use transition instead of animations
1165
+ const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
1166
+ const composedRef = useComposedRefs(ref, drawerRef);
1167
+ const pointerStartRef = React.useRef<{ x: number; y: number } | null>(null);
1168
+ const lastKnownPointerEventRef = React.useRef<React.PointerEvent<HTMLDivElement> | null>(null);
1169
+ const continuingCanceledTouchRef = React.useRef(false);
1170
+ const wasBeyondThePointRef = React.useRef(false);
1171
+ const hasSnapPoints = snapPoints && snapPoints.length > 0;
1172
+ useScaleBackground();
1173
+
1174
+ const isDeltaInDirection = (
1175
+ delta: { x: number; y: number },
1176
+ dir: DrawerDirection,
1177
+ threshold = 0
1178
+ ) => {
1179
+ if (wasBeyondThePointRef.current) return true;
1180
+
1181
+ const deltaY = Math.abs(delta.y);
1182
+ const deltaX = Math.abs(delta.x);
1183
+ const isDeltaX = deltaX > deltaY;
1184
+ const dFactor = ['bottom', 'right'].includes(dir) ? 1 : -1;
1185
+
1186
+ if (dir === 'left' || dir === 'right') {
1187
+ const isReverseDirection = delta.x * dFactor < 0;
1188
+ if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
1189
+ return isDeltaX;
1190
+ }
1191
+ } else {
1192
+ const isReverseDirection = delta.y * dFactor < 0;
1193
+ if (!isReverseDirection && deltaY >= 0 && deltaY <= threshold) {
1194
+ return !isDeltaX;
1195
+ }
1196
+ }
1197
+
1198
+ wasBeyondThePointRef.current = true;
1199
+ return true;
1200
+ };
1201
+
1202
+ React.useEffect(() => {
1203
+ if (hasSnapPoints) {
1204
+ window.requestAnimationFrame(() => {
1205
+ setDelayedSnapPoints(true);
1206
+ });
1207
+ }
1208
+ }, []);
1209
+
1210
+ // Event-driven position tracking. We only tick RAF while the drawer is
1211
+ // actually moving (drag / CSS transition / CSS animation). When it's idle at
1212
+ // a snap, no frames run at all.
1213
+ const positionTrackingRef = React.useRef<{
1214
+ rafId: number | null;
1215
+ movingCount: number;
1216
+ lastPosition: number;
1217
+ start: () => void;
1218
+ stop: () => void;
1219
+ } | null>(null);
1220
+
1221
+ React.useEffect(() => {
1222
+ const drawer = drawerRef.current;
1223
+ if (!drawer) return;
1224
+
1225
+ const state = {
1226
+ rafId: null as number | null,
1227
+ movingCount: 0,
1228
+ lastPosition: Number.NaN,
1229
+ start: () => {},
1230
+ stop: () => {},
1231
+ };
1232
+
1233
+ const emit = () => {
1234
+ const cb = onPositionChangeRef.current;
1235
+ if (!cb) return;
1236
+ const position = drawer.getBoundingClientRect().top;
1237
+ if (position !== state.lastPosition) {
1238
+ state.lastPosition = position;
1239
+ cb(position);
1240
+ }
1241
+ };
1242
+
1243
+ const tick = () => {
1244
+ emit();
1245
+ state.rafId = state.movingCount > 0 ? window.requestAnimationFrame(tick) : null;
1246
+ };
1247
+
1248
+ state.start = () => {
1249
+ state.movingCount += 1;
1250
+ if (state.rafId === null) {
1251
+ state.rafId = window.requestAnimationFrame(tick);
1252
+ }
1253
+ };
1254
+
1255
+ state.stop = () => {
1256
+ state.movingCount = Math.max(0, state.movingCount - 1);
1257
+ // RAF loop will exit on its next tick; emit the settled position now.
1258
+ if (state.movingCount === 0) emit();
1259
+ };
1260
+
1261
+ const wrapper = drawer.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1262
+
1263
+ // Listen on the wrapper too: drag-overshoot snap-back animates the wrapper
1264
+ // alone when the drawer's target is unchanged (e.g. snapping back to the
1265
+ // same detent). Without this, position goes stale mid-animation because
1266
+ // the drawer's `transitionrun` never fires.
1267
+ const onTransitionRun = (e: TransitionEvent) => {
1268
+ if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1269
+ state.start();
1270
+ };
1271
+ const onTransitionDone = (e: TransitionEvent) => {
1272
+ if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1273
+ state.stop();
1274
+ };
1275
+ const onAnimationStart = (e: AnimationEvent) => {
1276
+ if (e.target === drawer || e.target === wrapper) state.start();
1277
+ };
1278
+ const onAnimationDone = (e: AnimationEvent) => {
1279
+ if (e.target === drawer || e.target === wrapper) state.stop();
1280
+ };
1281
+
1282
+ drawer.addEventListener('transitionrun', onTransitionRun);
1283
+ drawer.addEventListener('transitionend', onTransitionDone);
1284
+ drawer.addEventListener('transitioncancel', onTransitionDone);
1285
+ drawer.addEventListener('animationstart', onAnimationStart);
1286
+ drawer.addEventListener('animationend', onAnimationDone);
1287
+ drawer.addEventListener('animationcancel', onAnimationDone);
1288
+ wrapper?.addEventListener('transitionrun', onTransitionRun);
1289
+ wrapper?.addEventListener('transitionend', onTransitionDone);
1290
+ wrapper?.addEventListener('transitioncancel', onTransitionDone);
1291
+
1292
+ positionTrackingRef.current = state;
1293
+ emit();
1294
+
1295
+ return () => {
1296
+ drawer.removeEventListener('transitionrun', onTransitionRun);
1297
+ drawer.removeEventListener('transitionend', onTransitionDone);
1298
+ drawer.removeEventListener('transitioncancel', onTransitionDone);
1299
+ drawer.removeEventListener('animationstart', onAnimationStart);
1300
+ drawer.removeEventListener('animationend', onAnimationDone);
1301
+ drawer.removeEventListener('animationcancel', onAnimationDone);
1302
+ wrapper?.removeEventListener('transitionrun', onTransitionRun);
1303
+ wrapper?.removeEventListener('transitionend', onTransitionDone);
1304
+ wrapper?.removeEventListener('transitioncancel', onTransitionDone);
1305
+ if (state.rafId !== null) window.cancelAnimationFrame(state.rafId);
1306
+ positionTrackingRef.current = null;
1307
+ };
1308
+ }, []);
1309
+
1310
+ React.useEffect(() => {
1311
+ const state = positionTrackingRef.current;
1312
+ if (!state) return;
1313
+ if (isDragging) state.start();
1314
+ else state.stop();
1315
+ }, [isDragging]);
1316
+
1317
+ function handleOnPointerUp(event: React.PointerEvent<HTMLDivElement> | null) {
1318
+ pointerStartRef.current = null;
1319
+ wasBeyondThePointRef.current = false;
1320
+ onRelease(event);
1321
+ }
1322
+
1323
+ // The drawer always sits inside a fixed clip wrapper. `contain: paint`
1324
+ // establishes the wrapper as the containing block so the drawer's own
1325
+ // `position: fixed` is constrained here, and `overflow: hidden` keeps any
1326
+ // overshoot out of the viewport. When `detached` the wrapper also floats
1327
+ // with a bottom gap and rounded bottom corners; otherwise it sits flush.
1328
+ // Transform/transition are managed imperatively (via drag overshoot and the
1329
+ // dismiss effect) so React doesn't skip DOM writes for values it thinks it
1330
+ // already owns.
1331
+ const wrapperStyle = React.useMemo<React.CSSProperties>(
1332
+ () => ({
1333
+ position: 'fixed',
1334
+ top: 0,
1335
+ left: 0,
1336
+ right: 0,
1337
+ bottom: detached ? detachedOffset : 0,
1338
+ overflow: 'hidden',
1339
+ contain: 'paint',
1340
+ pointerEvents: 'none',
1341
+ borderBottomLeftRadius: detached ? detachedRadius : 0,
1342
+ borderBottomRightRadius: detached ? detachedRadius : 0,
1343
+ ...detachedWrapperStyleProp,
1344
+ }),
1345
+ [detached, detachedOffset, detachedRadius, detachedWrapperStyleProp]
1346
+ );
1347
+
1348
+ // Translate the wrapper off-screen on dismiss so the whole card slides out
1349
+ // as one. The reset-then-target pattern on open forces the browser to
1350
+ // record a starting value so the transition actually animates.
1351
+ // Start at `false` so a mount with `isOpen=true` (autopresent via
1352
+ // `initialDetentIndex`) is detected as a false→true transition and runs
1353
+ // the slide-up animation instead of snapping straight to rest.
1354
+ const wasOpenRef = React.useRef(false);
1355
+ React.useEffect(() => {
1356
+ if (!drawerRef.current) {
1357
+ wasOpenRef.current = isOpen;
1358
+ return;
1359
+ }
1360
+ const wrapper = drawerRef.current.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1361
+ if (wrapper) {
1362
+ const transition = `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
1363
+ const viewportH = typeof window !== 'undefined' ? window.innerHeight : 0;
1364
+ if (!isOpen && wasOpenRef.current) {
1365
+ wrapper.style.transition = transition;
1366
+ wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1367
+ } else if (isOpen && !wasOpenRef.current) {
1368
+ wrapper.style.transition = 'none';
1369
+ wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1370
+ // eslint-disable-next-line no-void
1371
+ void wrapper.offsetHeight;
1372
+ wrapper.style.transition = transition;
1373
+ wrapper.style.transform = 'translate3d(0, 0, 0)';
1374
+ }
1375
+ }
1376
+ wasOpenRef.current = isOpen;
1377
+ }, [isOpen, detached, drawerRef]);
1378
+
1379
+ const contentNode = (
1380
+ <DialogPrimitive.Content
1381
+ data-vaul-drawer-direction={direction}
1382
+ data-vaul-drawer=""
1383
+ data-vaul-detached={detached ? 'true' : 'false'}
1384
+ data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
1385
+ data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
1386
+ data-vaul-custom-container={container ? 'true' : 'false'}
1387
+ data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
1388
+ {...rest}
1389
+ ref={composedRef}
1390
+ style={
1391
+ snapPointsOffset && snapPointsOffset.length > 0
1392
+ ? ({
1393
+ '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]!}px`,
1394
+ ...style,
1395
+ 'pointerEvents': 'auto',
1396
+ } as React.CSSProperties)
1397
+ : ({ ...style, pointerEvents: 'auto' } as React.CSSProperties)
1398
+ }
1399
+ onPointerDown={(event) => {
1400
+ if (handleOnly) return;
1401
+ rest.onPointerDown?.(event);
1402
+ continuingCanceledTouchRef.current = false;
1403
+ pointerStartRef.current = { x: event.pageX, y: event.pageY };
1404
+ onPress(event);
1405
+ }}
1406
+ onOpenAutoFocus={(e) => {
1407
+ onOpenAutoFocus?.(e);
1408
+
1409
+ if (!autoFocus) {
1410
+ e.preventDefault();
1411
+ }
1412
+ }}
1413
+ onPointerDownOutside={(e) => {
1414
+ onPointerDownOutside?.(e);
1415
+
1416
+ if (!modal || e.defaultPrevented || isBelowFade) {
1417
+ e.preventDefault();
1418
+ return;
1419
+ }
1420
+
1421
+ // Non-dismissible + dimmed: collapse to the highest non-dimmed
1422
+ // snap point instead of silently swallowing the dismiss attempt.
1423
+ // Mirrors the native Android dim-tap behavior.
1424
+ if (
1425
+ !dismissible &&
1426
+ hasSnapPoints &&
1427
+ fadeFromIndex !== undefined &&
1428
+ fadeFromIndex > 0 &&
1429
+ typeof activeSnapPointIndex === 'number' &&
1430
+ activeSnapPointIndex >= fadeFromIndex
1431
+ ) {
1432
+ e.preventDefault();
1433
+ setActiveSnapPoint(snapPoints![fadeFromIndex - 1]!);
1434
+ return;
1435
+ }
1436
+
1437
+ if (keyboardIsOpen.current) {
1438
+ keyboardIsOpen.current = false;
1439
+ }
1440
+ }}
1441
+ onEscapeKeyDown={(e) => {
1442
+ onEscapeKeyDown?.(e);
1443
+ if (e.defaultPrevented) return;
1444
+
1445
+ // Non-dismissible: collapse to the first snap point (if above it)
1446
+ // instead of silently swallowing the dismiss attempt. Mirrors the
1447
+ // native Android back-press behavior.
1448
+ if (!dismissible) {
1449
+ e.preventDefault();
1450
+ if (
1451
+ hasSnapPoints &&
1452
+ typeof activeSnapPointIndex === 'number' &&
1453
+ activeSnapPointIndex > 0
1454
+ ) {
1455
+ setActiveSnapPoint(snapPoints![0]!);
1456
+ }
1457
+ }
1458
+ }}
1459
+ onFocusOutside={(e) => {
1460
+ // Never auto-dismiss the sheet on focus shifts. Without Radix's
1461
+ // FocusScope trap (we run modal={false}), this fires whenever
1462
+ // focus naturally leaves the drawer — e.g. React Navigation's
1463
+ // web driver hides the previous screen via display:none, which
1464
+ // moves focus off the trigger and dismisses the sheet.
1465
+ e.preventDefault();
1466
+ }}
1467
+ onPointerMove={(event) => {
1468
+ lastKnownPointerEventRef.current = event;
1469
+ if (handleOnly) return;
1470
+ rest.onPointerMove?.(event);
1471
+ if (!pointerStartRef.current) return;
1472
+ const yPosition = event.pageY - pointerStartRef.current.y;
1473
+ const xPosition = event.pageX - pointerStartRef.current.x;
1474
+
1475
+ const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
1476
+ const delta = { x: xPosition, y: yPosition };
1477
+
1478
+ const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1479
+ if (isAllowedToSwipe) onDrag(event);
1480
+ else if (
1481
+ Math.abs(xPosition) > swipeStartThreshold ||
1482
+ Math.abs(yPosition) > swipeStartThreshold
1483
+ ) {
1484
+ pointerStartRef.current = null;
1485
+ }
1486
+ }}
1487
+ onPointerUp={(event) => {
1488
+ rest.onPointerUp?.(event);
1489
+ continuingCanceledTouchRef.current = false;
1490
+ pointerStartRef.current = null;
1491
+ wasBeyondThePointRef.current = false;
1492
+ onRelease(event);
1493
+ }}
1494
+ onPointerCancel={(event) => {
1495
+ rest.onPointerCancel?.(event);
1496
+ if (
1497
+ event.pointerType === 'touch' &&
1498
+ snapPoints &&
1499
+ activeSnapPointIndex === snapPoints.length - 1
1500
+ ) {
1501
+ continuingCanceledTouchRef.current = true;
1502
+ return;
1503
+ }
1504
+ handleOnPointerUp(null);
1505
+ }}
1506
+ onPointerOut={(event) => {
1507
+ rest.onPointerOut?.(event);
1508
+ if (continuingCanceledTouchRef.current) return;
1509
+ handleOnPointerUp(lastKnownPointerEventRef.current);
1510
+ }}
1511
+ onTouchMove={(event) => {
1512
+ rest.onTouchMove?.(event);
1513
+ if (!continuingCanceledTouchRef.current) return;
1514
+ const touch = event.touches[0];
1515
+ if (!touch) return;
1516
+ onTouchDrag(
1517
+ {
1518
+ target: event.target,
1519
+ pageX: touch.pageX,
1520
+ pageY: touch.pageY,
1521
+ pointerType: 'touch',
1522
+ },
1523
+ lastKnownPointerEventRef.current ?? undefined
1524
+ );
1525
+ }}
1526
+ onTouchEnd={(event) => {
1527
+ rest.onTouchEnd?.(event);
1528
+ if (!continuingCanceledTouchRef.current) return;
1529
+ continuingCanceledTouchRef.current = false;
1530
+ pointerStartRef.current = null;
1531
+ wasBeyondThePointRef.current = false;
1532
+ const touch = event.changedTouches[0];
1533
+ onTouchRelease(
1534
+ touch
1535
+ ? {
1536
+ target: event.target,
1537
+ pageX: touch.pageX,
1538
+ pageY: touch.pageY,
1539
+ pointerType: 'touch',
1540
+ }
1541
+ : null,
1542
+ lastKnownPointerEventRef.current ?? undefined
1543
+ );
1544
+ }}
1545
+ onTouchCancel={(event) => {
1546
+ rest.onTouchCancel?.(event);
1547
+ if (!continuingCanceledTouchRef.current) return;
1548
+ continuingCanceledTouchRef.current = false;
1549
+ handleOnPointerUp(null);
1550
+ }}
1551
+ onContextMenu={(event) => {
1552
+ rest.onContextMenu?.(event);
1553
+ if (lastKnownPointerEventRef.current) {
1554
+ handleOnPointerUp(lastKnownPointerEventRef.current);
1555
+ }
1556
+ }}
1557
+ >
1558
+ <div ref={setAutoSizeNode} data-vaul-auto-size-wrapper="" style={autoSizeWrapperStyle}>
1559
+ {children}
1560
+ </div>
1561
+ </DialogPrimitive.Content>
1562
+ );
1563
+
1564
+ return (
1565
+ <div data-vaul-detached-wrapper="" style={wrapperStyle}>
1566
+ {contentNode}
1567
+ {detachedSiblings}
1568
+ </div>
1569
+ );
1570
+ }
1571
+ );
1572
+
1573
+ Content.displayName = 'Drawer.Content';
1574
+
1575
+ // `flow-root` establishes a new block formatting context so the first child's
1576
+ // margin-top (e.g. a grabber) stays inside the wrapper instead of collapsing
1577
+ // out — otherwise `offsetHeight` under-reports and the drawer positions the
1578
+ // wrapper below where the content actually ends.
1579
+ const autoSizeWrapperStyle: React.CSSProperties = { display: 'flow-root' };
1580
+
1581
+ export type HandleProps = React.ComponentPropsWithoutRef<'div'> & {
1582
+ preventCycle?: boolean;
1583
+ };
1584
+
1585
+ const LONG_HANDLE_PRESS_TIMEOUT = 250;
1586
+ const DOUBLE_TAP_TIMEOUT = 120;
1587
+
1588
+ export const Handle = React.forwardRef<HTMLDivElement, HandleProps>(
1589
+ ({ preventCycle = false, children, ...rest }, ref) => {
1590
+ const {
1591
+ closeDrawer,
1592
+ isDragging,
1593
+ snapPoints,
1594
+ activeSnapPoint,
1595
+ setActiveSnapPoint,
1596
+ dismissible,
1597
+ handleOnly,
1598
+ isOpen,
1599
+ onPress,
1600
+ onDrag,
1601
+ } = useDrawerContext();
1602
+
1603
+ const closeTimeoutIdRef = React.useRef<number | null>(null);
1604
+ const shouldCancelInteractionRef = React.useRef(false);
1605
+
1606
+ function handleStartCycle() {
1607
+ // Stop if this is the second click of a double click
1608
+ if (shouldCancelInteractionRef.current) {
1609
+ handleCancelInteraction();
1610
+ return;
1611
+ }
1612
+ window.setTimeout(() => {
1613
+ handleCycleSnapPoints();
1614
+ }, DOUBLE_TAP_TIMEOUT);
1615
+ }
1616
+
1617
+ function handleCycleSnapPoints() {
1618
+ // Prevent accidental taps while resizing drawer
1619
+ if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
1620
+ handleCancelInteraction();
1621
+ return;
1622
+ }
1623
+ // Make sure to clear the timeout id if the user releases the handle before the cancel timeout
1624
+ handleCancelInteraction();
1625
+
1626
+ if (!snapPoints || snapPoints.length === 0) {
1627
+ if (!dismissible) {
1628
+ closeDrawer();
1629
+ }
1630
+ return;
1631
+ }
1632
+
1633
+ const isLastSnapPoint = activeSnapPoint === snapPoints[snapPoints.length - 1];
1634
+
1635
+ if (isLastSnapPoint && dismissible) {
1636
+ closeDrawer();
1637
+ return;
1638
+ }
1639
+
1640
+ const currentSnapIndex = snapPoints.findIndex((point) => point === activeSnapPoint);
1641
+ if (currentSnapIndex === -1) return; // activeSnapPoint not found in snapPoints
1642
+ const nextSnapPoint = snapPoints[currentSnapIndex + 1];
1643
+ if (nextSnapPoint === undefined) return;
1644
+ setActiveSnapPoint(nextSnapPoint);
1645
+ }
1646
+
1647
+ function handleStartInteraction() {
1648
+ closeTimeoutIdRef.current = window.setTimeout(() => {
1649
+ // Cancel click interaction on a long press
1650
+ shouldCancelInteractionRef.current = true;
1651
+ }, LONG_HANDLE_PRESS_TIMEOUT);
1652
+ }
1653
+
1654
+ function handleCancelInteraction() {
1655
+ if (closeTimeoutIdRef.current) {
1656
+ window.clearTimeout(closeTimeoutIdRef.current);
1657
+ }
1658
+ shouldCancelInteractionRef.current = false;
1659
+ }
1660
+
1661
+ return (
1662
+ <div
1663
+ onClick={handleStartCycle}
1664
+ onPointerCancel={handleCancelInteraction}
1665
+ onPointerDown={(e) => {
1666
+ if (handleOnly) onPress(e);
1667
+ handleStartInteraction();
1668
+ }}
1669
+ onPointerMove={(e) => {
1670
+ if (handleOnly) onDrag(e);
1671
+ }}
1672
+ // onPointerUp is already handled by the content component
1673
+ ref={ref}
1674
+ data-vaul-drawer-visible={isOpen ? 'true' : 'false'}
1675
+ data-vaul-handle=""
1676
+ aria-hidden="true"
1677
+ {...rest}
1678
+ >
1679
+ {/* Expand handle's hit area beyond what's visible to ensure a 44x44 tap target for touch devices */}
1680
+ <span data-vaul-handle-hitarea="" aria-hidden="true">
1681
+ {children}
1682
+ </span>
1683
+ </div>
1684
+ );
1685
+ }
1686
+ );
1687
+
1688
+ Handle.displayName = 'Drawer.Handle';
1689
+
1690
+ export function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }: DialogProps) {
1691
+ const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();
1692
+
1693
+ if (!onNestedDrag) {
1694
+ throw new Error('Drawer.NestedRoot must be placed in another drawer');
1695
+ }
1696
+
1697
+ return (
1698
+ <Root
1699
+ nested
1700
+ open={nestedIsOpen}
1701
+ onClose={() => {
1702
+ onNestedOpenChange(false);
1703
+ }}
1704
+ onDrag={(e, p) => {
1705
+ onNestedDrag(e, p);
1706
+ onDrag?.(e, p);
1707
+ }}
1708
+ onOpenChange={(o) => {
1709
+ if (o) {
1710
+ onNestedOpenChange(o);
1711
+ }
1712
+ onOpenChange?.(o);
1713
+ }}
1714
+ onRelease={onNestedRelease}
1715
+ {...rest}
1716
+ />
1717
+ );
1718
+ }
1719
+
1720
+ type PortalProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Portal>;
1721
+
1722
+ export function Portal(props: PortalProps) {
1723
+ const context = useDrawerContext();
1724
+ const { container = context.container, ...portalProps } = props;
1725
+
1726
+ return <DialogPrimitive.Portal container={container} {...portalProps} />;
1727
+ }
1728
+
1729
+ export const Drawer = {
1730
+ Root,
1731
+ NestedRoot,
1732
+ Content,
1733
+ Overlay,
1734
+ Trigger: DialogPrimitive.Trigger,
1735
+ Portal,
1736
+ Handle,
1737
+ Close: DialogPrimitive.Close,
1738
+ Title: DialogPrimitive.Title,
1739
+ Description: DialogPrimitive.Description,
1740
+ };