@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,258 @@
1
+ "use strict";
2
+
3
+ // This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts
4
+
5
+ import { useEffect, useLayoutEffect } from 'react';
6
+ import { isIOS } from "./browser.js";
7
+ const KEYBOARD_BUFFER = 24;
8
+ export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
9
+ function chain(...callbacks) {
10
+ return (...args) => {
11
+ for (let callback of callbacks) {
12
+ if (typeof callback === 'function') {
13
+ callback(...args);
14
+ }
15
+ }
16
+ };
17
+ }
18
+
19
+ // @ts-ignore
20
+ const visualViewport = typeof document !== 'undefined' && window.visualViewport;
21
+ export function isScrollable(node) {
22
+ let style = window.getComputedStyle(node);
23
+ return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
24
+ }
25
+ export function getScrollParent(node) {
26
+ if (isScrollable(node)) {
27
+ node = node.parentElement;
28
+ }
29
+ while (node && !isScrollable(node)) {
30
+ node = node.parentElement;
31
+ }
32
+ return node || document.scrollingElement || document.documentElement;
33
+ }
34
+
35
+ // HTML input types that do not cause the software keyboard to appear.
36
+ const nonTextInputTypes = new Set(['checkbox', 'radio', 'range', 'color', 'file', 'image', 'button', 'submit', 'reset']);
37
+
38
+ // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
39
+ let preventScrollCount = 0;
40
+ let restore;
41
+
42
+ /**
43
+ * Prevents scrolling on the document body on mount, and
44
+ * restores it on unmount. Also ensures that content does not
45
+ * shift due to the scrollbars disappearing.
46
+ */
47
+ export function usePreventScroll(options = {}) {
48
+ let {
49
+ isDisabled
50
+ } = options;
51
+ useIsomorphicLayoutEffect(() => {
52
+ if (isDisabled) {
53
+ return;
54
+ }
55
+ preventScrollCount++;
56
+ if (preventScrollCount === 1) {
57
+ if (isIOS()) {
58
+ restore = preventScrollMobileSafari();
59
+ }
60
+ }
61
+ return () => {
62
+ preventScrollCount--;
63
+ if (preventScrollCount === 0) {
64
+ restore?.();
65
+ }
66
+ };
67
+ }, [isDisabled]);
68
+ }
69
+
70
+ // Mobile Safari is a whole different beast. Even with overflow: hidden,
71
+ // it still scrolls the page in many situations:
72
+ //
73
+ // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
74
+ // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
75
+ // it, so it becomes scrollable.
76
+ // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
77
+ // This may cause even fixed position elements to scroll off the screen.
78
+ // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
79
+ // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
80
+ //
81
+ // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
82
+ //
83
+ // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
84
+ // on the window.
85
+ // 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the
86
+ // top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.
87
+ // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
88
+ // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
89
+ // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
90
+ // into view ourselves, without scrolling the whole page.
91
+ // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
92
+ // same visually, but makes the actual scroll position always zero. This is required to make all of the
93
+ // above work or Safari will still try to scroll the page when focusing an input.
94
+ // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
95
+ // to navigate to an input with the next/previous buttons that's outside a modal.
96
+ function preventScrollMobileSafari() {
97
+ let scrollable;
98
+ let lastY = 0;
99
+ let onTouchStart = e => {
100
+ // Store the nearest scrollable parent element from the element that the user touched.
101
+ scrollable = getScrollParent(e.target);
102
+ if (scrollable === document.documentElement && scrollable === document.body) {
103
+ return;
104
+ }
105
+ lastY = e.changedTouches[0]?.pageY ?? 0;
106
+ };
107
+ let onTouchMove = e => {
108
+ // Prevent scrolling the window.
109
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
110
+ e.preventDefault();
111
+ return;
112
+ }
113
+
114
+ // Prevent scrolling up when at the top and scrolling down when at the bottom
115
+ // of a nested scrollable area, otherwise mobile Safari will start scrolling
116
+ // the window instead. Unfortunately, this disables bounce scrolling when at
117
+ // the top but it's the best we can do.
118
+ let y = e.changedTouches[0]?.pageY ?? 0;
119
+ let scrollTop = scrollable.scrollTop;
120
+ let bottom = scrollable.scrollHeight - scrollable.clientHeight;
121
+ if (bottom === 0) {
122
+ return;
123
+ }
124
+ if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
125
+ e.preventDefault();
126
+ }
127
+ lastY = y;
128
+ };
129
+ let onTouchEnd = e => {
130
+ let target = e.target;
131
+
132
+ // Apply this change if we're not already focused on the target element
133
+ if (isInput(target) && target !== document.activeElement) {
134
+ e.preventDefault();
135
+
136
+ // Apply a transform to trick Safari into thinking the input is at the top of the page
137
+ // so it doesn't try to scroll it into view. When tapping on an input, this needs to
138
+ // be done before the "focus" event, so we have to focus the element ourselves.
139
+ target.style.transform = 'translateY(-2000px)';
140
+ target.focus();
141
+ requestAnimationFrame(() => {
142
+ target.style.transform = '';
143
+ });
144
+ }
145
+ };
146
+ let onFocus = e => {
147
+ let target = e.target;
148
+ if (isInput(target)) {
149
+ // Transform also needs to be applied in the focus event in cases where focus moves
150
+ // other than tapping on an input directly, e.g. the next/previous buttons in the
151
+ // software keyboard. In these cases, it seems applying the transform in the focus event
152
+ // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
153
+ target.style.transform = 'translateY(-2000px)';
154
+ requestAnimationFrame(() => {
155
+ target.style.transform = '';
156
+
157
+ // This will have prevented the browser from scrolling the focused element into view,
158
+ // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
159
+ if (visualViewport) {
160
+ if (visualViewport.height < window.innerHeight) {
161
+ // If the keyboard is already visible, do this after one additional frame
162
+ // to wait for the transform to be removed.
163
+ requestAnimationFrame(() => {
164
+ scrollIntoView(target);
165
+ });
166
+ } else {
167
+ // Otherwise, wait for the visual viewport to resize before scrolling so we can
168
+ // measure the correct position to scroll to.
169
+ visualViewport.addEventListener('resize', () => scrollIntoView(target), {
170
+ once: true
171
+ });
172
+ }
173
+ }
174
+ });
175
+ }
176
+ };
177
+ let onWindowScroll = () => {
178
+ // Last resort. If the window scrolled, scroll it back to the top.
179
+ // It should always be at the top because the body will have a negative margin (see below).
180
+ window.scrollTo(0, 0);
181
+ };
182
+
183
+ // Record the original scroll position so we can restore it.
184
+ // Then apply a negative margin to the body to offset it by the scroll position. This will
185
+ // enable us to scroll the window to the top, which is required for the rest of this to work.
186
+ let scrollX = window.pageXOffset;
187
+ let scrollY = window.pageYOffset;
188
+ let restoreStyles = chain(setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`)
189
+ // setStyle(document.documentElement, 'overflow', 'hidden'),
190
+ // setStyle(document.body, 'marginTop', `-${scrollY}px`),
191
+ );
192
+
193
+ // Scroll to the top. The negative margin on the body will make this appear the same.
194
+ window.scrollTo(0, 0);
195
+ let removeEvents = chain(addEvent(document, 'touchstart', onTouchStart, {
196
+ passive: false,
197
+ capture: true
198
+ }), addEvent(document, 'touchmove', onTouchMove, {
199
+ passive: false,
200
+ capture: true
201
+ }), addEvent(document, 'touchend', onTouchEnd, {
202
+ passive: false,
203
+ capture: true
204
+ }), addEvent(document, 'focus', onFocus, true), addEvent(window, 'scroll', onWindowScroll));
205
+ return () => {
206
+ // Restore styles and scroll the page back to where it was.
207
+ restoreStyles();
208
+ removeEvents();
209
+ window.scrollTo(scrollX, scrollY);
210
+ };
211
+ }
212
+
213
+ // Sets a CSS property on an element, and returns a function to revert it to the previous value.
214
+ function setStyle(element, style, value) {
215
+ // https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310
216
+ // @ts-ignore
217
+ let cur = element.style[style];
218
+ // @ts-ignore
219
+ element.style[style] = value;
220
+ return () => {
221
+ // @ts-ignore
222
+ element.style[style] = cur;
223
+ };
224
+ }
225
+
226
+ // Adds an event listener to an element, and returns a function to remove it.
227
+ function addEvent(target, event, handler, options) {
228
+ // @ts-ignore
229
+ target.addEventListener(event, handler, options);
230
+ return () => {
231
+ // @ts-ignore
232
+ target.removeEventListener(event, handler, options);
233
+ };
234
+ }
235
+ function scrollIntoView(target) {
236
+ let root = document.scrollingElement || document.documentElement;
237
+ while (target && target !== root) {
238
+ // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
239
+ let scrollable = getScrollParent(target);
240
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
241
+ let scrollableTop = scrollable.getBoundingClientRect().top;
242
+ let targetTop = target.getBoundingClientRect().top;
243
+ let targetBottom = target.getBoundingClientRect().bottom;
244
+ // Buffer is needed for some edge cases
245
+ const keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;
246
+ if (targetBottom > keyboardHeight) {
247
+ scrollable.scrollTop += targetTop - scrollableTop;
248
+ }
249
+ }
250
+
251
+ // @ts-ignore
252
+ target = scrollable.parentElement;
253
+ }
254
+ }
255
+ export function isInput(target) {
256
+ return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
257
+ }
258
+ //# sourceMappingURL=use-prevent-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useLayoutEffect","isIOS","KEYBOARD_BUFFER","useIsomorphicLayoutEffect","window","chain","callbacks","args","callback","visualViewport","document","isScrollable","node","style","getComputedStyle","test","overflow","overflowX","overflowY","getScrollParent","parentElement","scrollingElement","documentElement","nonTextInputTypes","Set","preventScrollCount","restore","usePreventScroll","options","isDisabled","preventScrollMobileSafari","scrollable","lastY","onTouchStart","e","target","body","changedTouches","pageY","onTouchMove","preventDefault","y","scrollTop","bottom","scrollHeight","clientHeight","onTouchEnd","isInput","activeElement","transform","focus","requestAnimationFrame","onFocus","height","innerHeight","scrollIntoView","addEventListener","once","onWindowScroll","scrollTo","scrollX","pageXOffset","scrollY","pageYOffset","restoreStyles","setStyle","innerWidth","clientWidth","removeEvents","addEvent","passive","capture","element","value","cur","event","handler","removeEventListener","root","scrollableTop","getBoundingClientRect","top","targetTop","targetBottom","keyboardHeight","HTMLInputElement","has","type","HTMLTextAreaElement","HTMLElement","isContentEditable"],"sourceRoot":"../../../../src","sources":["web/vaul/use-prevent-scroll.ts"],"mappings":";;AAAA;;AAEA,SAASA,SAAS,EAAEC,eAAe,QAAQ,OAAO;AAClD,SAASC,KAAK,QAAQ,cAAW;AAEjC,MAAMC,eAAe,GAAG,EAAE;AAE1B,OAAO,MAAMC,yBAAyB,GACpC,OAAOC,MAAM,KAAK,WAAW,GAAGJ,eAAe,GAAGD,SAAS;AAQ7D,SAASM,KAAKA,CAAC,GAAGC,SAAgB,EAA4B;EAC5D,OAAO,CAAC,GAAGC,IAAW,KAAK;IACzB,KAAK,IAAIC,QAAQ,IAAIF,SAAS,EAAE;MAC9B,IAAI,OAAOE,QAAQ,KAAK,UAAU,EAAE;QAClCA,QAAQ,CAAC,GAAGD,IAAI,CAAC;MACnB;IACF;EACF,CAAC;AACH;;AAEA;AACA,MAAME,cAAc,GAAG,OAAOC,QAAQ,KAAK,WAAW,IAAIN,MAAM,CAACK,cAAc;AAE/E,OAAO,SAASE,YAAYA,CAACC,IAAa,EAAW;EACnD,IAAIC,KAAK,GAAGT,MAAM,CAACU,gBAAgB,CAACF,IAAI,CAAC;EACzC,OAAO,eAAe,CAACG,IAAI,CAACF,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI,SAAS,GAAGJ,KAAK,CAACK,SAAS,CAAC;AACjF;AAEA,OAAO,SAASC,eAAeA,CAACP,IAAa,EAAW;EACtD,IAAID,YAAY,CAACC,IAAI,CAAC,EAAE;IACtBA,IAAI,GAAGA,IAAI,CAACQ,aAA4B;EAC1C;EAEA,OA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 "use strict";
2
+
3
+ // @ts-nocheck — vendored upstream, incompatible with noImplicitReturns
4
+ import React, { useMemo } from 'react';
5
+ import { useDrawerContext } from "./context.js";
6
+ import { assignStyle, chain, isVertical } from "./helpers.js";
7
+ import { BORDER_RADIUS, TRANSITIONS, WINDOW_TOP_OFFSET } from "./constants.js";
8
+ const noop = () => () => {};
9
+ export function useScaleBackground() {
10
+ const {
11
+ direction,
12
+ isOpen,
13
+ shouldScaleBackground,
14
+ setBackgroundColorOnScale,
15
+ noBodyStyles
16
+ } = useDrawerContext();
17
+ const timeoutIdRef = React.useRef(null);
18
+ const initialBackgroundColor = useMemo(() => document.body.style.backgroundColor, []);
19
+ function getScale() {
20
+ return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
21
+ }
22
+ React.useEffect(() => {
23
+ if (isOpen && shouldScaleBackground) {
24
+ if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);
25
+ const wrapper = document.querySelector('[data-vaul-drawer-wrapper]') || document.querySelector('[vaul-drawer-wrapper]');
26
+ if (!wrapper) return;
27
+ chain(setBackgroundColorOnScale && !noBodyStyles ? assignStyle(document.body, {
28
+ background: 'black'
29
+ }) : noop, assignStyle(wrapper, {
30
+ transformOrigin: isVertical(direction) ? 'top' : 'left',
31
+ transitionProperty: 'transform, border-radius',
32
+ transitionDuration: `${TRANSITIONS.DURATION}s`,
33
+ transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`
34
+ }));
35
+ const wrapperStylesCleanup = assignStyle(wrapper, {
36
+ borderRadius: `${BORDER_RADIUS}px`,
37
+ overflow: 'hidden',
38
+ ...(isVertical(direction) ? {
39
+ transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`
40
+ } : {
41
+ transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`
42
+ })
43
+ });
44
+ return () => {
45
+ wrapperStylesCleanup();
46
+ timeoutIdRef.current = window.setTimeout(() => {
47
+ if (initialBackgroundColor) {
48
+ document.body.style.background = initialBackgroundColor;
49
+ } else {
50
+ document.body.style.removeProperty('background');
51
+ }
52
+ }, TRANSITIONS.DURATION * 1000);
53
+ };
54
+ }
55
+ }, [isOpen, shouldScaleBackground, initialBackgroundColor]);
56
+ }
57
+ //# sourceMappingURL=use-scale-background.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useMemo","useDrawerContext","assignStyle","chain","isVertical","BORDER_RADIUS","TRANSITIONS","WINDOW_TOP_OFFSET","noop","useScaleBackground","direction","isOpen","shouldScaleBackground","setBackgroundColorOnScale","noBodyStyles","timeoutIdRef","useRef","initialBackgroundColor","document","body","style","backgroundColor","getScale","window","innerWidth","useEffect","current","clearTimeout","wrapper","querySelector","background","transformOrigin","transitionProperty","transitionDuration","DURATION","transitionTimingFunction","EASE","join","wrapperStylesCleanup","borderRadius","overflow","transform","setTimeout","removeProperty"],"sourceRoot":"../../../../src","sources":["web/vaul/use-scale-background.ts"],"mappings":";;AAAA;AACA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,gBAAgB,QAAQ,cAAW;AAC5C,SAASC,WAAW,EAAEC,KAAK,EAAEC,UAAU,QAAQ,cAAW;AAC1D,SAASC,aAAa,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,gBAAa;AAE3E,MAAMC,IAAI,GAAGA,CAAA,KAAM,MAAM,CAAC,CAAC;AAE3B,OAAO,SAASC,kBAAkBA,CAAA,EAAG;EACnC,MAAM;IAAEC,SAAS;IAAEC,MAAM;IAAEC,qBAAqB;IAAEC,yBAAyB;IAAEC;EAAa,CAAC,GACzFb,gBAAgB,CAAC,CAAC;EACpB,MAAMc,YAAY,GAAGhB,KAAK,CAACiB,MAAM,CAAgB,IAAI,CAAC;EACtD,MAAMC,sBAAsB,GAAGjB,OAAO,CAAC,MAAMkB,QAAQ,CAACC,IAAI,CAACC,KAAK,CAACC,eAAe,EAAE,EAAE,CAAC;EAErF,SAAS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AAGH,MAAM,CAACmB,UAAU,CAAC,MAAM;UAC7C,IAAIzB,sBAAsB,EAAE;YAC1BC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAACU,UAAU,GAAGb,sBAAsB;UACzD,CAAC,MAAM;YACLC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAACuB,cAAc,CAAC,YAAY,CAAC;UAClD;QACF,CAAC,EAAErC,WAAW,CAAC4B,QAAQ,GAAG,IAAI,CAAC;MACjC,CAAC;IACH;EACF,CAAC,EAAE,CAACvB,MAAM,EAAEC,qBAAqB,EAAEK,sBAAsB,CAAC,CAAC;AAC7D","ignoreList":[]}
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+
3
+ // @ts-nocheck — vendored upstream, incompatible with noUncheckedIndexedAccess
4
+ import React from 'react';
5
+ import { set, isVertical } from "./helpers.js";
6
+ import { DEFAULT_PEEK_HEIGHT, TRANSITIONS, VELOCITY_THRESHOLD } from "./constants.js";
7
+ import { useControllableState } from "./use-controllable-state.js";
8
+ export function useSnapPoints({
9
+ activeSnapPointProp,
10
+ setActiveSnapPointProp,
11
+ snapPoints,
12
+ drawerRef,
13
+ overlayRef,
14
+ fadeFromIndex,
15
+ onSnapPointChange,
16
+ direction = 'bottom',
17
+ container,
18
+ snapToSequentialPoint,
19
+ isOpen,
20
+ contentHeight,
21
+ detachedOffset = 0,
22
+ maxContentHeight,
23
+ peekHeight,
24
+ initialAnimated = true
25
+ }) {
26
+ const [activeSnapPoint, setActiveSnapPoint] = useControllableState({
27
+ prop: activeSnapPointProp,
28
+ defaultProp: snapPoints?.[0],
29
+ onChange: setActiveSnapPointProp
30
+ });
31
+ const [windowDimensions, setWindowDimensions] = React.useState(typeof window !== 'undefined' ? {
32
+ innerWidth: window.innerWidth,
33
+ innerHeight: window.innerHeight
34
+ } : undefined);
35
+ React.useEffect(() => {
36
+ function onResize() {
37
+ setWindowDimensions({
38
+ innerWidth: window.innerWidth,
39
+ innerHeight: window.innerHeight
40
+ });
41
+ }
42
+ window.addEventListener('resize', onResize);
43
+ return () => window.removeEventListener('resize', onResize);
44
+ }, []);
45
+ const isLastSnapPoint = React.useMemo(() => activeSnapPoint === snapPoints?.[snapPoints.length - 1] || null, [snapPoints, activeSnapPoint]);
46
+ const activeSnapPointIndex = React.useMemo(() => snapPoints?.findIndex(snapPoint => snapPoint === activeSnapPoint) ?? null, [snapPoints, activeSnapPoint]);
47
+ const shouldFade = snapPoints && snapPoints.length > 0 && (fadeFromIndex || fadeFromIndex === 0) && !Number.isNaN(fadeFromIndex) && snapPoints[fadeFromIndex] === activeSnapPoint || !snapPoints;
48
+ const snapPointsOffset = React.useMemo(() => {
49
+ const containerSize = container ? {
50
+ width: container.getBoundingClientRect().width,
51
+ height: container.getBoundingClientRect().height
52
+ } : typeof window !== 'undefined' ? {
53
+ width: window.innerWidth,
54
+ height: window.innerHeight
55
+ } : {
56
+ width: 0,
57
+ height: 0
58
+ };
59
+
60
+ // Shrink the effective vertical area by detachedOffset so snap math
61
+ // reserves a fixed gap at the bottom — the floating card stays offset
62
+ // from the viewport edge through drag, snap and resize.
63
+ const effectiveHeight = Math.max(0, containerSize.height - (detachedOffset || 0));
64
+ return snapPoints?.map(snapPoint => {
65
+ // 'auto' resolves to measured content height. Falls back to half the
66
+ // container so the initial snap is close to final before ResizeObserver
67
+ // reports a real measurement. 'peek' resolves to the caller-measured
68
+ // header + footer height.
69
+ const resolved = snapPoint === 'auto' ? `${contentHeight && contentHeight > 0 ? contentHeight : effectiveHeight / 2}px` : snapPoint === 'peek' ? `${peekHeight && peekHeight > 0 ? peekHeight : DEFAULT_PEEK_HEIGHT}px` : snapPoint;
70
+ const isPx = typeof resolved === 'string';
71
+ let snapPointAsNumber = 0;
72
+ if (isPx) {
73
+ snapPointAsNumber = parseInt(resolved, 10);
74
+ }
75
+ if (isVertical(direction)) {
76
+ const rawHeight = isPx ? snapPointAsNumber : windowDimensions ? resolved * effectiveHeight : 0;
77
+ // Cap px/'auto' snap points so a content taller than the viewport
78
+ // doesn't push the drawer past the top edge (offset would go
79
+ // negative). Fractional detents are already ≤ effectiveHeight.
80
+ // `maxContentHeight`, when set, caps the visible sheet further so
81
+ // full/'auto' detents respect the user's ceiling.
82
+ const ceiling = maxContentHeight !== undefined ? Math.min(effectiveHeight, maxContentHeight) : effectiveHeight;
83
+ const height = Math.min(rawHeight, ceiling);
84
+ if (windowDimensions) {
85
+ return direction === 'bottom' ? effectiveHeight - height : -effectiveHeight + height;
86
+ }
87
+ return height;
88
+ }
89
+ const rawWidth = isPx ? snapPointAsNumber : windowDimensions ? resolved * containerSize.width : 0;
90
+ const width = Math.min(rawWidth, containerSize.width);
91
+ if (windowDimensions) {
92
+ return direction === 'right' ? containerSize.width - width : -containerSize.width + width;
93
+ }
94
+ return width;
95
+ }) ?? [];
96
+ }, [snapPoints, windowDimensions, container, contentHeight, detachedOffset, maxContentHeight, peekHeight]);
97
+ const activeSnapPointOffset = React.useMemo(() => activeSnapPointIndex !== null ? snapPointsOffset?.[activeSnapPointIndex] : null, [snapPointsOffset, activeSnapPointIndex]);
98
+
99
+ // Detached-only: the drawer sits inside a clip wrapper. When drag overshoots
100
+ // below the lowest detent we translate the wrapper by the excess so the
101
+ // whole floating card follows the pointer instead of the drawer sliding
102
+ // behind the wrapper's rounded-bottom clip.
103
+ const setDetachedWrapperTransform = (y, animated) => {
104
+ if (!drawerRef.current || !isVertical(direction)) return;
105
+ const wrapper = drawerRef.current.closest('[data-vaul-detached-wrapper]');
106
+ if (!wrapper) return;
107
+ set(wrapper, {
108
+ transition: animated ? `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})` : 'none',
109
+ transform: `translate3d(0, ${y}px, 0)`
110
+ });
111
+ };
112
+
113
+ // Skip the transition on the very first snap when the consumer opts out of
114
+ // the initial presentation animation. All subsequent snaps still animate.
115
+ const hasSnappedRef = React.useRef(false);
116
+ const snapToPoint = React.useCallback(dimension => {
117
+ const newSnapPointIndex = snapPointsOffset?.findIndex(snapPointDim => snapPointDim === dimension) ?? null;
118
+ onSnapPointChange(newSnapPointIndex);
119
+ const animateThisSnap = hasSnappedRef.current || initialAnimated;
120
+ hasSnappedRef.current = true;
121
+ // `--snap-point-height` transitions alongside `transform` (registered via
122
+ // @property) so layouts derived from it (e.g. the scrollable fill) resize
123
+ // in sync with the drawer's slide instead of jumping to the target.
124
+ set(drawerRef.current, {
125
+ 'transition': animateThisSnap ? `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')}), --snap-point-height ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})` : 'none',
126
+ 'transform': isVertical(direction) ? `translate3d(0, ${dimension}px, 0)` : `translate3d(${dimension}px, 0, 0)`,
127
+ '--snap-point-height': `${dimension}px`
128
+ });
129
+
130
+ // Snapping implies drag overshoot (if any) should be undone.
131
+ setDetachedWrapperTransform(0, animateThisSnap);
132
+ if (snapPointsOffset && newSnapPointIndex !== snapPointsOffset.length - 1 && fadeFromIndex !== undefined && newSnapPointIndex !== fadeFromIndex && newSnapPointIndex < fadeFromIndex) {
133
+ set(overlayRef.current, {
134
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
135
+ opacity: '0',
136
+ pointerEvents: 'none'
137
+ });
138
+ } else {
139
+ set(overlayRef.current, {
140
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
141
+ opacity: '1',
142
+ pointerEvents: 'auto'
143
+ });
144
+ }
145
+ setActiveSnapPoint(snapPoints?.[Math.max(newSnapPointIndex, 0)]);
146
+ }, [drawerRef.current, snapPoints, snapPointsOffset, fadeFromIndex, overlayRef, setActiveSnapPoint]);
147
+ React.useEffect(() => {
148
+ if (!isOpen) return;
149
+ if (activeSnapPoint || activeSnapPointProp) {
150
+ const newIndex = snapPoints?.findIndex(snapPoint => snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint) ?? -1;
151
+ if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === 'number') {
152
+ snapToPoint(snapPointsOffset[newIndex]);
153
+ }
154
+ }
155
+ }, [isOpen, activeSnapPoint, activeSnapPointProp, snapPoints, snapPointsOffset, snapToPoint]);
156
+ function onRelease({
157
+ draggedDistance,
158
+ closeDrawer,
159
+ velocity,
160
+ dismissible
161
+ }) {
162
+ if (fadeFromIndex === undefined) return;
163
+ const currentPosition = direction === 'bottom' || direction === 'right' ? (activeSnapPointOffset ?? 0) - draggedDistance : (activeSnapPointOffset ?? 0) + draggedDistance;
164
+ const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
165
+ const isFirst = activeSnapPointIndex === 0;
166
+ const hasDraggedUp = draggedDistance > 0;
167
+ if (isOverlaySnapPoint) {
168
+ set(overlayRef.current, {
169
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
170
+ });
171
+ }
172
+
173
+ // Distance-based dismiss: when overshooting past the lowest detent by more
174
+ // than half of its visible height, commit to dismiss regardless of
175
+ // velocity — lets a slow drag-down still close the sheet.
176
+ if (dismissible && (direction === 'bottom' || direction === 'right') && currentPosition > snapPointsOffset[0]) {
177
+ const viewportDim = isVertical(direction) ? window.innerHeight : window.innerWidth;
178
+ const effectiveDim = Math.max(0, viewportDim - (detachedOffset || 0));
179
+ const visibleAtLowest = Math.max(0, effectiveDim - snapPointsOffset[0]);
180
+ const overshoot = currentPosition - snapPointsOffset[0];
181
+ if (overshoot > visibleAtLowest * 0.5) {
182
+ closeDrawer();
183
+ return;
184
+ }
185
+ }
186
+ if (!snapToSequentialPoint && velocity > 2 && !hasDraggedUp) {
187
+ if (dismissible) closeDrawer();else snapToPoint(snapPointsOffset[0]); // snap to initial point
188
+ return;
189
+ }
190
+ if (!snapToSequentialPoint && velocity > 2 && hasDraggedUp && snapPointsOffset && snapPoints) {
191
+ snapToPoint(snapPointsOffset[snapPoints.length - 1]);
192
+ return;
193
+ }
194
+
195
+ // Find the closest snap point to the current position
196
+ const closestSnapPoint = snapPointsOffset?.reduce((prev, curr) => {
197
+ if (typeof prev !== 'number' || typeof curr !== 'number') return prev;
198
+ return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
199
+ });
200
+ const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
201
+ if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedDistance) < dim * 0.4) {
202
+ const dragDirection = hasDraggedUp ? 1 : -1; // 1 = up, -1 = down
203
+
204
+ // Don't do anything if we swipe upwards while being on the last snap point
205
+ if (dragDirection > 0 && isLastSnapPoint && snapPoints) {
206
+ snapToPoint(snapPointsOffset[snapPoints.length - 1]);
207
+ return;
208
+ }
209
+ if (isFirst && dragDirection < 0 && dismissible) {
210
+ closeDrawer();
211
+ }
212
+ if (activeSnapPointIndex === null) return;
213
+ snapToPoint(snapPointsOffset[activeSnapPointIndex + dragDirection]);
214
+ return;
215
+ }
216
+ snapToPoint(closestSnapPoint);
217
+ }
218
+ function onDrag({
219
+ draggedDistance
220
+ }) {
221
+ if (activeSnapPointOffset === null) return;
222
+ const newValue = direction === 'bottom' || direction === 'right' ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;
223
+
224
+ // Don't do anything if we exceed the last(biggest) snap point
225
+ if ((direction === 'bottom' || direction === 'right') && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {
226
+ return;
227
+ }
228
+ if ((direction === 'top' || direction === 'left') && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {
229
+ return;
230
+ }
231
+
232
+ // Past the lowest detent: cap the drawer and translate the detached
233
+ // wrapper by the excess so the floating card follows the pointer.
234
+ if ((direction === 'bottom' || direction === 'right') && newValue > snapPointsOffset[0]) {
235
+ const excess = newValue - snapPointsOffset[0];
236
+ set(drawerRef.current, {
237
+ 'transform': isVertical(direction) ? `translate3d(0, ${snapPointsOffset[0]}px, 0)` : `translate3d(${snapPointsOffset[0]}px, 0, 0)`,
238
+ '--snap-point-height': `${snapPointsOffset[0]}px`
239
+ });
240
+ setDetachedWrapperTransform(excess, false);
241
+ return;
242
+ }
243
+ setDetachedWrapperTransform(0, false);
244
+ // Keep `--snap-point-height` tracking the live drag position so layouts
245
+ // derived from it (e.g. the scrollable fill) resize with the drawer
246
+ // instead of staying cut off at the last detent's visible height.
247
+ set(drawerRef.current, {
248
+ 'transform': isVertical(direction) ? `translate3d(0, ${newValue}px, 0)` : `translate3d(${newValue}px, 0, 0)`,
249
+ '--snap-point-height': `${newValue}px`
250
+ });
251
+ }
252
+ function getPercentageDragged(absDraggedDistance, isDraggingDown) {
253
+ if (!snapPoints || typeof activeSnapPointIndex !== 'number' || !snapPointsOffset || fadeFromIndex === undefined) return null;
254
+
255
+ // fadeFromIndex === 0 means every snap point is fully dimmed. Only the dismiss drag
256
+ // (toward close from the smallest detent) should fade the overlay out, interpolating
257
+ // opacity by distance from the smallest snap to the fully-dismissed position.
258
+ if (fadeFromIndex === 0) {
259
+ if (activeSnapPointIndex === 0 && !isDraggingDown) {
260
+ const activeOffset = snapPointsOffset[activeSnapPointIndex];
261
+ if (activeOffset === undefined) return 0;
262
+ const windowDim = isVertical(direction) ? window.innerHeight : window.innerWidth;
263
+ const dismissOffset = direction === 'bottom' || direction === 'right' ? windowDim : -windowDim;
264
+ const dismissRange = Math.abs(dismissOffset - activeOffset);
265
+ return dismissRange > 0 ? Math.min(1, absDraggedDistance / dismissRange) : 0;
266
+ }
267
+ return 0;
268
+ }
269
+
270
+ // If this is true we are dragging to a snap point that is supposed to have an overlay
271
+ const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
272
+ const isOverlaySnapPointOrHigher = activeSnapPointIndex >= fadeFromIndex;
273
+ if (isOverlaySnapPointOrHigher && isDraggingDown) {
274
+ return 0;
275
+ }
276
+
277
+ // Don't animate, but still use this one if we are dragging away from the overlaySnapPoint
278
+ if (isOverlaySnapPoint && !isDraggingDown) return 1;
279
+ if (!shouldFade && !isOverlaySnapPoint) return null;
280
+
281
+ // Either fadeFrom index or the one before
282
+ const targetSnapPointIndex = isOverlaySnapPoint ? activeSnapPointIndex + 1 : activeSnapPointIndex - 1;
283
+
284
+ // Get the distance from overlaySnapPoint to the one before or vice-versa to calculate the opacity percentage accordingly
285
+ const snapPointDistance = isOverlaySnapPoint ? snapPointsOffset[targetSnapPointIndex] - snapPointsOffset[targetSnapPointIndex - 1] : snapPointsOffset[targetSnapPointIndex + 1] - snapPointsOffset[targetSnapPointIndex];
286
+ const percentageDragged = absDraggedDistance / Math.abs(snapPointDistance);
287
+ if (isOverlaySnapPoint) {
288
+ return 1 - percentageDragged;
289
+ } else {
290
+ return percentageDragged;
291
+ }
292
+ }
293
+ return {
294
+ isLastSnapPoint,
295
+ activeSnapPoint,
296
+ shouldFade,
297
+ getPercentageDragged,
298
+ setActiveSnapPoint,
299
+ activeSnapPointIndex,
300
+ onRelease,
301
+ onDrag,
302
+ snapPointsOffset
303
+ };
304
+ }
305
+ //# sourceMappingURL=use-snap-points.js.map