@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.
- package/LICENSE +1 -1
- package/README.md +42 -31
- package/RNTrueSheet.podspec +10 -2
- package/android/build.gradle +2 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerView.kt +174 -49
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContainerViewManager.kt +7 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentView.kt +371 -18
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetContentViewManager.kt +14 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterView.kt +150 -21
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetFooterViewManager.kt +14 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderView.kt +38 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetHeaderViewManager.kt +28 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetModule.kt +84 -24
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetPackage.kt +5 -4
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetPeekView.kt +72 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetPeekViewManager.kt +33 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetStateUpdater.kt +45 -0
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +526 -231
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt +1217 -603
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +136 -29
- package/android/src/main/java/com/lodev09/truesheet/core/RNScreensEventObserver.kt +63 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetBehavior.kt +36 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetBottomSheetView.kt +255 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetCoordinatorLayout.kt +303 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDetentCalculator.kt +277 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetDimView.kt +162 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt +180 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetKeyboardObserver.kt +207 -0
- package/android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt +220 -0
- package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetDragEvents.kt +71 -0
- package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetFocusEvents.kt +65 -0
- package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetLifecycleEvents.kt +112 -0
- package/android/src/main/java/com/lodev09/truesheet/events/TrueSheetStateEvents.kt +56 -0
- package/android/src/main/java/com/lodev09/truesheet/utils/KeyboardUtils.kt +84 -0
- package/android/src/main/java/com/lodev09/truesheet/utils/ScreenUtils.kt +93 -67
- package/android/src/main/java/com/lodev09/truesheet/utils/ViewUtils.kt +30 -0
- package/android/src/main/jni/CMakeLists.txt +63 -0
- package/android/src/main/jni/TrueSheetSpec.h +19 -0
- package/android/src/main/jni/TrueSheetStateUpdater.cpp +96 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewComponentDescriptor.h +24 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.cpp +43 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewShadowNode.h +28 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.cpp +11 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetContentViewState.h +37 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewComponentDescriptor.h +24 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.cpp +56 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewShadowNode.h +28 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.cpp +11 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetFooterViewState.h +41 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.cpp +18 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetInsets.h +16 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewComponentDescriptor.h +28 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.cpp +61 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewShadowNode.h +45 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.cpp +23 -0
- package/common/cpp/react/renderer/components/TrueSheetSpec/TrueSheetViewState.h +52 -0
- package/ios/TrueSheetContainerView.h +81 -6
- package/ios/TrueSheetContainerView.mm +275 -21
- package/ios/TrueSheetContentView.h +38 -1
- package/ios/TrueSheetContentView.mm +413 -43
- package/ios/TrueSheetFooterView.h +27 -2
- package/ios/TrueSheetFooterView.mm +141 -35
- package/ios/{events/OnDidDismissEvent.h → TrueSheetHeaderView.h} +10 -7
- package/ios/TrueSheetHeaderView.mm +64 -0
- package/ios/TrueSheetModule.mm +92 -5
- package/ios/TrueSheetPeekView.h +32 -0
- package/ios/TrueSheetPeekView.mm +99 -0
- package/ios/TrueSheetView.h +7 -15
- package/ios/TrueSheetView.mm +633 -215
- package/ios/TrueSheetViewController.h +84 -16
- package/ios/TrueSheetViewController.mm +1136 -333
- package/ios/core/RNScreensEventObserver.h +46 -0
- package/ios/core/RNScreensEventObserver.mm +280 -0
- package/ios/core/TrueSheetBlurView.h +27 -0
- package/ios/core/TrueSheetBlurView.mm +82 -0
- package/ios/core/TrueSheetDetentCalculator.h +107 -0
- package/ios/core/TrueSheetDetentCalculator.mm +197 -0
- package/ios/core/TrueSheetGrabberView.h +72 -0
- package/ios/core/TrueSheetGrabberView.mm +178 -0
- package/ios/core/TrueSheetKeyboardObserver.h +39 -0
- package/ios/core/TrueSheetKeyboardObserver.mm +112 -0
- package/ios/events/TrueSheetDragEvents.h +39 -0
- package/ios/events/TrueSheetDragEvents.mm +62 -0
- package/ios/events/{OnPositionChangeEvent.h → TrueSheetFocusEvents.h} +8 -5
- package/ios/events/TrueSheetFocusEvents.mm +49 -0
- package/ios/events/TrueSheetLifecycleEvents.h +40 -0
- package/ios/events/TrueSheetLifecycleEvents.mm +71 -0
- package/ios/events/TrueSheetStateEvents.h +35 -0
- package/ios/events/TrueSheetStateEvents.mm +49 -0
- package/ios/tvos/TrueSheetStubs.mm +154 -0
- package/ios/{events/OnMountEvent.h → utils/BlurUtil.h} +5 -7
- package/ios/utils/BlurUtil.mm +69 -0
- package/ios/utils/GestureUtil.h +7 -0
- package/ios/utils/GestureUtil.mm +12 -0
- package/ios/utils/PlatformUtil.h +15 -0
- package/ios/utils/UIView+FirstResponder.h +15 -0
- package/ios/utils/UIView+FirstResponder.mm +26 -0
- package/ios/{events/OnWillDismissEvent.h → utils/UIView+ScrollEdgeInteraction.h} +6 -7
- package/ios/utils/UIView+ScrollEdgeInteraction.mm +62 -0
- package/ios/utils/WindowUtil.mm +17 -1
- package/lib/module/TrueSheet.js +224 -64
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.web.js +1201 -0
- package/lib/module/TrueSheet.web.js.map +1 -0
- package/lib/module/TrueSheetPeek.js +15 -0
- package/lib/module/TrueSheetPeek.js.map +1 -0
- package/lib/module/TrueSheetPeek.web.js +55 -0
- package/lib/module/TrueSheetPeek.web.js.map +1 -0
- package/lib/module/TrueSheetProvider.js +28 -0
- package/lib/module/TrueSheetProvider.js.map +1 -0
- package/lib/module/TrueSheetProvider.web.js +157 -0
- package/lib/module/TrueSheetProvider.web.js.map +1 -0
- package/lib/module/fabric/TrueSheetContainerViewNativeComponent.ts +1 -1
- package/lib/module/fabric/TrueSheetContentViewNativeComponent.ts +5 -1
- package/lib/module/fabric/TrueSheetFooterViewNativeComponent.ts +10 -2
- package/lib/module/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
- package/lib/module/fabric/TrueSheetPeekViewNativeComponent.ts +8 -0
- package/lib/module/fabric/TrueSheetViewNativeComponent.ts +105 -18
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks/index.js +93 -0
- package/lib/module/mocks/index.js.map +1 -0
- package/lib/module/mocks/navigation.js +85 -0
- package/lib/module/mocks/navigation.js.map +1 -0
- package/lib/module/mocks/reanimated.js +91 -0
- package/lib/module/mocks/reanimated.js.map +1 -0
- package/lib/module/navigation/TrueSheetRouter.js +170 -0
- package/lib/module/navigation/TrueSheetRouter.js.map +1 -0
- package/lib/module/navigation/TrueSheetView.js +71 -0
- package/lib/module/navigation/TrueSheetView.js.map +1 -0
- package/lib/module/navigation/createTrueSheetNavigator.js +63 -0
- package/lib/module/navigation/createTrueSheetNavigator.js.map +1 -0
- package/lib/module/navigation/index.js +6 -0
- package/lib/module/navigation/index.js.map +1 -0
- package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js +56 -0
- package/lib/module/navigation/screen/ReanimatedTrueSheetScreen.js.map +1 -0
- package/lib/module/navigation/screen/TrueSheetScreen.js +49 -0
- package/lib/module/navigation/screen/TrueSheetScreen.js.map +1 -0
- package/lib/module/navigation/screen/index.js +5 -0
- package/lib/module/navigation/screen/index.js.map +1 -0
- package/lib/module/navigation/screen/types.js +4 -0
- package/lib/module/navigation/screen/types.js.map +1 -0
- package/lib/module/navigation/screen/useSheetScreenState.js +68 -0
- package/lib/module/navigation/screen/useSheetScreenState.js.map +1 -0
- package/lib/module/navigation/types.js +4 -0
- package/lib/module/navigation/types.js.map +1 -0
- package/lib/module/navigation/useTrueSheetNavigation.js +24 -0
- package/lib/module/navigation/useTrueSheetNavigation.js.map +1 -0
- package/lib/module/reanimated/ReanimatedTrueSheet.js +15 -9
- package/lib/module/reanimated/ReanimatedTrueSheet.js.map +1 -1
- package/lib/module/reanimated/ReanimatedTrueSheet.web.js +81 -0
- package/lib/module/reanimated/ReanimatedTrueSheet.web.js.map +1 -0
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js +4 -2
- package/lib/module/reanimated/ReanimatedTrueSheetProvider.js.map +1 -1
- package/lib/module/reanimated/index.js +2 -2
- package/lib/module/reanimated/index.js.map +1 -1
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js +20 -0
- package/lib/module/reanimated/useReanimatedPositionChangeHandler.web.js.map +1 -0
- package/lib/module/specs/NativeTrueSheetModule.js.map +1 -1
- package/lib/module/web/constants.js +16 -0
- package/lib/module/web/constants.js.map +1 -0
- package/lib/module/web/vaul/README.md +9 -0
- package/lib/module/web/vaul/browser.js +30 -0
- package/lib/module/web/vaul/browser.js.map +1 -0
- package/lib/module/web/vaul/constants.js +15 -0
- package/lib/module/web/vaul/constants.js.map +1 -0
- package/lib/module/web/vaul/context.js +59 -0
- package/lib/module/web/vaul/context.js.map +1 -0
- package/lib/module/web/vaul/helpers.js +93 -0
- package/lib/module/web/vaul/helpers.js.map +1 -0
- package/lib/module/web/vaul/index.js +1309 -0
- package/lib/module/web/vaul/index.js.map +1 -0
- package/lib/module/web/vaul/style.css +287 -0
- package/lib/module/web/vaul/style.css.d.js +2 -0
- package/lib/module/web/vaul/style.css.d.js.map +1 -0
- package/lib/module/web/vaul/types.js +2 -0
- package/lib/module/web/vaul/types.js.map +1 -0
- package/lib/module/web/vaul/use-composed-refs.js +34 -0
- package/lib/module/web/vaul/use-composed-refs.js.map +1 -0
- package/lib/module/web/vaul/use-controllable-state.js +54 -0
- package/lib/module/web/vaul/use-controllable-state.js.map +1 -0
- package/lib/module/web/vaul/use-position-fixed.js +123 -0
- package/lib/module/web/vaul/use-position-fixed.js.map +1 -0
- package/lib/module/web/vaul/use-prevent-scroll.js +258 -0
- package/lib/module/web/vaul/use-prevent-scroll.js.map +1 -0
- package/lib/module/web/vaul/use-scale-background.js +57 -0
- package/lib/module/web/vaul/use-scale-background.js.map +1 -0
- package/lib/module/web/vaul/use-snap-points.js +305 -0
- package/lib/module/web/vaul/use-snap-points.js.map +1 -0
- package/lib/typescript/src/TrueSheet.d.ts +51 -14
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.types.d.ts +463 -54
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -1
- package/lib/typescript/src/TrueSheet.web.d.ts +5 -0
- package/lib/typescript/src/TrueSheet.web.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheetPeek.d.ts +9 -0
- package/lib/typescript/src/TrueSheetPeek.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheetPeek.web.d.ts +28 -0
- package/lib/typescript/src/TrueSheetPeek.web.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheetProvider.d.ts +18 -0
- package/lib/typescript/src/TrueSheetProvider.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheetProvider.web.d.ts +27 -0
- package/lib/typescript/src/TrueSheetProvider.web.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetContainerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetContentViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts +2 -0
- package/lib/typescript/src/fabric/TrueSheetFooterViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/TrueSheetHeaderViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetPeekViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/TrueSheetPeekViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts +67 -16
- package/lib/typescript/src/fabric/TrueSheetViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mocks/index.d.ts +43 -0
- package/lib/typescript/src/mocks/index.d.ts.map +1 -0
- package/lib/typescript/src/mocks/navigation.d.ts +66 -0
- package/lib/typescript/src/mocks/navigation.d.ts.map +1 -0
- package/lib/typescript/src/mocks/reanimated.d.ts +48 -0
- package/lib/typescript/src/mocks/reanimated.d.ts.map +1 -0
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts +57 -0
- package/lib/typescript/src/navigation/TrueSheetRouter.d.ts.map +1 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts +10 -0
- package/lib/typescript/src/navigation/TrueSheetView.d.ts.map +1 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts +35 -0
- package/lib/typescript/src/navigation/createTrueSheetNavigator.d.ts.map +1 -0
- package/lib/typescript/src/navigation/index.d.ts +6 -0
- package/lib/typescript/src/navigation/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts +3 -0
- package/lib/typescript/src/navigation/screen/ReanimatedTrueSheetScreen.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts +3 -0
- package/lib/typescript/src/navigation/screen/TrueSheetScreen.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/index.d.ts +4 -0
- package/lib/typescript/src/navigation/screen/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/types.d.ts +15 -0
- package/lib/typescript/src/navigation/screen/types.d.ts.map +1 -0
- package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts +35 -0
- package/lib/typescript/src/navigation/screen/useSheetScreenState.d.ts.map +1 -0
- package/lib/typescript/src/navigation/types.d.ts +153 -0
- package/lib/typescript/src/navigation/types.d.ts.map +1 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts +23 -0
- package/lib/typescript/src/navigation/useTrueSheetNavigation.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts +41 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheet.web.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts +8 -2
- package/lib/typescript/src/reanimated/ReanimatedTrueSheetProvider.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts +15 -0
- package/lib/typescript/src/reanimated/useReanimatedPositionChangeHandler.web.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts +25 -3
- package/lib/typescript/src/specs/NativeTrueSheetModule.d.ts.map +1 -1
- package/lib/typescript/src/web/constants.d.ts +14 -0
- package/lib/typescript/src/web/constants.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/browser.d.ts +8 -0
- package/lib/typescript/src/web/vaul/browser.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/constants.d.ts +13 -0
- package/lib/typescript/src/web/vaul/constants.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/context.d.ts +53 -0
- package/lib/typescript/src/web/vaul/context.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/helpers.d.ts +17 -0
- package/lib/typescript/src/web/vaul/helpers.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/index.d.ts +228 -0
- package/lib/typescript/src/web/vaul/index.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/types.d.ts +7 -0
- package/lib/typescript/src/web/vaul/types.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-composed-refs.d.ts +14 -0
- package/lib/typescript/src/web/vaul/use-composed-refs.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-controllable-state.d.ts +9 -0
- package/lib/typescript/src/web/vaul/use-controllable-state.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-position-fixed.d.ts +19 -0
- package/lib/typescript/src/web/vaul/use-position-fixed.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts +18 -0
- package/lib/typescript/src/web/vaul/use-prevent-scroll.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-scale-background.d.ts +2 -0
- package/lib/typescript/src/web/vaul/use-scale-background.d.ts.map +1 -0
- package/lib/typescript/src/web/vaul/use-snap-points.d.ts +38 -0
- package/lib/typescript/src/web/vaul/use-snap-points.d.ts.map +1 -0
- package/package.json +78 -34
- package/react-native.config.js +9 -2
- package/src/TrueSheet.tsx +276 -60
- package/src/TrueSheet.types.ts +525 -71
- package/src/TrueSheet.web.tsx +1366 -0
- package/src/TrueSheetPeek.tsx +11 -0
- package/src/TrueSheetPeek.web.tsx +63 -0
- package/src/TrueSheetProvider.tsx +33 -0
- package/src/TrueSheetProvider.web.tsx +220 -0
- package/src/fabric/TrueSheetContainerViewNativeComponent.ts +1 -1
- package/src/fabric/TrueSheetContentViewNativeComponent.ts +5 -1
- package/src/fabric/TrueSheetFooterViewNativeComponent.ts +10 -2
- package/src/fabric/TrueSheetHeaderViewNativeComponent.ts +8 -0
- package/src/fabric/TrueSheetPeekViewNativeComponent.ts +8 -0
- package/src/fabric/TrueSheetViewNativeComponent.ts +105 -18
- package/src/index.ts +2 -2
- package/src/mocks/index.ts +89 -0
- package/src/mocks/navigation.ts +72 -0
- package/src/mocks/reanimated.ts +101 -0
- package/src/navigation/TrueSheetRouter.ts +234 -0
- package/src/navigation/TrueSheetView.tsx +99 -0
- package/src/navigation/createTrueSheetNavigator.tsx +93 -0
- package/src/navigation/index.ts +14 -0
- package/src/navigation/screen/ReanimatedTrueSheetScreen.tsx +61 -0
- package/src/navigation/screen/TrueSheetScreen.tsx +54 -0
- package/src/navigation/screen/index.ts +3 -0
- package/src/navigation/screen/types.ts +21 -0
- package/src/navigation/screen/useSheetScreenState.ts +107 -0
- package/src/navigation/types.ts +219 -0
- package/src/navigation/useTrueSheetNavigation.ts +26 -0
- package/src/reanimated/ReanimatedTrueSheet.tsx +12 -7
- package/src/reanimated/ReanimatedTrueSheet.web.tsx +75 -0
- package/src/reanimated/ReanimatedTrueSheetProvider.tsx +12 -8
- package/src/reanimated/useReanimatedPositionChangeHandler.web.ts +31 -0
- package/src/specs/NativeTrueSheetModule.ts +28 -3
- package/src/web/constants.ts +13 -0
- package/src/web/vaul/README.md +9 -0
- package/src/web/vaul/browser.ts +38 -0
- package/src/web/vaul/constants.ts +20 -0
- package/src/web/vaul/context.ts +101 -0
- package/src/web/vaul/helpers.ts +124 -0
- package/src/web/vaul/index.tsx +1740 -0
- package/src/web/vaul/style.css +287 -0
- package/src/web/vaul/style.css.d.ts +1 -0
- package/src/web/vaul/types.ts +7 -0
- package/src/web/vaul/use-composed-refs.ts +35 -0
- package/src/web/vaul/use-controllable-state.ts +66 -0
- package/src/web/vaul/use-position-fixed.ts +147 -0
- package/src/web/vaul/use-prevent-scroll.ts +309 -0
- package/src/web/vaul/use-scale-background.ts +64 -0
- package/src/web/vaul/use-snap-points.ts +455 -0
- package/android/src/main/java/com/lodev09/truesheet/events/DetentChangeEvent.kt +0 -26
- package/android/src/main/java/com/lodev09/truesheet/events/DidDismissEvent.kt +0 -20
- package/android/src/main/java/com/lodev09/truesheet/events/DidPresentEvent.kt +0 -26
- package/android/src/main/java/com/lodev09/truesheet/events/DragBeginEvent.kt +0 -26
- package/android/src/main/java/com/lodev09/truesheet/events/DragChangeEvent.kt +0 -26
- package/android/src/main/java/com/lodev09/truesheet/events/DragEndEvent.kt +0 -26
- package/android/src/main/java/com/lodev09/truesheet/events/MountEvent.kt +0 -20
- package/android/src/main/java/com/lodev09/truesheet/events/PositionChangeEvent.kt +0 -32
- package/android/src/main/java/com/lodev09/truesheet/events/SizeChangeEvent.kt +0 -27
- package/android/src/main/java/com/lodev09/truesheet/events/WillDismissEvent.kt +0 -20
- package/android/src/main/java/com/lodev09/truesheet/events/WillPresentEvent.kt +0 -26
- package/android/src/main/res/values/styles.xml +0 -8
- package/ios/events/OnDetentChangeEvent.h +0 -28
- package/ios/events/OnDetentChangeEvent.mm +0 -30
- package/ios/events/OnDidDismissEvent.mm +0 -25
- package/ios/events/OnDidPresentEvent.h +0 -28
- package/ios/events/OnDidPresentEvent.mm +0 -30
- package/ios/events/OnDragBeginEvent.h +0 -28
- package/ios/events/OnDragBeginEvent.mm +0 -30
- package/ios/events/OnDragChangeEvent.h +0 -28
- package/ios/events/OnDragChangeEvent.mm +0 -30
- package/ios/events/OnDragEndEvent.h +0 -28
- package/ios/events/OnDragEndEvent.mm +0 -30
- package/ios/events/OnMountEvent.mm +0 -25
- package/ios/events/OnPositionChangeEvent.mm +0 -32
- package/ios/events/OnSizeChangeEvent.h +0 -28
- package/ios/events/OnSizeChangeEvent.mm +0 -30
- package/ios/events/OnWillDismissEvent.mm +0 -25
- package/ios/events/OnWillPresentEvent.h +0 -28
- package/ios/events/OnWillPresentEvent.mm +0 -30
- package/ios/utils/LayoutUtil.h +0 -44
- package/ios/utils/LayoutUtil.mm +0 -50
- package/lib/module/TrueSheetGrabber.js +0 -51
- package/lib/module/TrueSheetGrabber.js.map +0 -1
- package/lib/typescript/src/TrueSheetGrabber.d.ts +0 -39
- package/lib/typescript/src/TrueSheetGrabber.d.ts.map +0 -1
- package/src/TrueSheetGrabber.tsx +0 -82
- package/src/__mocks__/index.js +0 -67
|
@@ -0,0 +1,1309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
6
|
+
import { Presence } from '@radix-ui/react-presence';
|
|
7
|
+
import { DrawerContext, useDrawerContext } from "./context.js";
|
|
8
|
+
import './style.css';
|
|
9
|
+
import { isIOS, isMobileFirefox } from "./browser.js";
|
|
10
|
+
import { BORDER_RADIUS, CLOSE_THRESHOLD, DRAG_CLASS, NESTED_DISPLACEMENT, SCROLL_LOCK_TIMEOUT, TRANSITIONS, VELOCITY_THRESHOLD, WINDOW_TOP_OFFSET } from "./constants.js";
|
|
11
|
+
import { dampenValue, getTranslate, isVertical, reset, set } from "./helpers.js";
|
|
12
|
+
import { useComposedRefs } from "./use-composed-refs.js";
|
|
13
|
+
import { useControllableState } from "./use-controllable-state.js";
|
|
14
|
+
import { usePositionFixed } from "./use-position-fixed.js";
|
|
15
|
+
import { isInput, isScrollable, usePreventScroll } from "./use-prevent-scroll.js";
|
|
16
|
+
import { useScaleBackground } from "./use-scale-background.js";
|
|
17
|
+
import { useSnapPoints } from "./use-snap-points.js";
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
export function Root({
|
|
20
|
+
open: openProp,
|
|
21
|
+
onOpenChange,
|
|
22
|
+
children,
|
|
23
|
+
onDrag: onDragProp,
|
|
24
|
+
onRelease: onReleaseProp,
|
|
25
|
+
snapPoints,
|
|
26
|
+
shouldScaleBackground = false,
|
|
27
|
+
setBackgroundColorOnScale = true,
|
|
28
|
+
closeThreshold = CLOSE_THRESHOLD,
|
|
29
|
+
scrollLockTimeout = SCROLL_LOCK_TIMEOUT,
|
|
30
|
+
dismissible = true,
|
|
31
|
+
draggable = true,
|
|
32
|
+
handleOnly = false,
|
|
33
|
+
fadeFromIndex = snapPoints && snapPoints.length - 1,
|
|
34
|
+
activeSnapPoint: activeSnapPointProp,
|
|
35
|
+
setActiveSnapPoint: setActiveSnapPointProp,
|
|
36
|
+
fixed,
|
|
37
|
+
modal = true,
|
|
38
|
+
onClose,
|
|
39
|
+
nested,
|
|
40
|
+
noBodyStyles = false,
|
|
41
|
+
direction = 'bottom',
|
|
42
|
+
defaultOpen = false,
|
|
43
|
+
disablePreventScroll = true,
|
|
44
|
+
snapToSequentialPoint = false,
|
|
45
|
+
preventScrollRestoration = false,
|
|
46
|
+
repositionInputs = true,
|
|
47
|
+
onAnimationEnd,
|
|
48
|
+
onPositionChange,
|
|
49
|
+
container,
|
|
50
|
+
autoFocus = false,
|
|
51
|
+
detached = false,
|
|
52
|
+
detachedOffset = 0,
|
|
53
|
+
detachedRadius = 0,
|
|
54
|
+
detachedWrapperStyle,
|
|
55
|
+
maxContentHeight,
|
|
56
|
+
peekHeight,
|
|
57
|
+
initialAnimated = true,
|
|
58
|
+
onContentHeightChange,
|
|
59
|
+
contentHeight: contentHeightProp
|
|
60
|
+
}) {
|
|
61
|
+
const [isOpen = false, setIsOpen] = useControllableState({
|
|
62
|
+
defaultProp: defaultOpen,
|
|
63
|
+
prop: openProp,
|
|
64
|
+
onChange: o => {
|
|
65
|
+
onOpenChange?.(o);
|
|
66
|
+
if (!o && !nested) {
|
|
67
|
+
restorePositionSetting();
|
|
68
|
+
}
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
onAnimationEnd?.(o);
|
|
71
|
+
}, TRANSITIONS.DURATION * 1000);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const [hasBeenOpened, setHasBeenOpened] = React.useState(false);
|
|
75
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
76
|
+
const [justReleased, setJustReleased] = React.useState(false);
|
|
77
|
+
const overlayRef = React.useRef(null);
|
|
78
|
+
const openTime = React.useRef(null);
|
|
79
|
+
const dragStartTime = React.useRef(null);
|
|
80
|
+
const dragEndTime = React.useRef(null);
|
|
81
|
+
const lastTimeDragPrevented = React.useRef(null);
|
|
82
|
+
const isAllowedToDrag = React.useRef(false);
|
|
83
|
+
const nestedOpenChangeTimer = React.useRef(null);
|
|
84
|
+
const pointerStart = React.useRef(0);
|
|
85
|
+
const keyboardIsOpen = React.useRef(false);
|
|
86
|
+
const shouldAnimate = React.useRef(!defaultOpen);
|
|
87
|
+
const previousDiffFromInitial = React.useRef(0);
|
|
88
|
+
const drawerRef = React.useRef(null);
|
|
89
|
+
const drawerHeightRef = React.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
|
|
90
|
+
const drawerWidthRef = React.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
|
|
91
|
+
const initialDrawerHeight = React.useRef(0);
|
|
92
|
+
const [measuredContentHeight, setContentHeight] = React.useState(0);
|
|
93
|
+
const contentHeight = contentHeightProp ?? measuredContentHeight;
|
|
94
|
+
const onContentHeightChangeRef = React.useRef(onContentHeightChange);
|
|
95
|
+
React.useEffect(() => {
|
|
96
|
+
onContentHeightChangeRef.current = onContentHeightChange;
|
|
97
|
+
});
|
|
98
|
+
React.useEffect(() => {
|
|
99
|
+
onContentHeightChangeRef.current?.(measuredContentHeight);
|
|
100
|
+
}, [measuredContentHeight]);
|
|
101
|
+
const onSnapPointChange = React.useCallback(activeSnapPointIndex => {
|
|
102
|
+
// Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
|
|
103
|
+
if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
|
|
104
|
+
}, []);
|
|
105
|
+
const {
|
|
106
|
+
activeSnapPoint,
|
|
107
|
+
activeSnapPointIndex,
|
|
108
|
+
setActiveSnapPoint,
|
|
109
|
+
onRelease: onReleaseSnapPoints,
|
|
110
|
+
snapPointsOffset,
|
|
111
|
+
onDrag: onDragSnapPoints,
|
|
112
|
+
shouldFade,
|
|
113
|
+
getPercentageDragged: getSnapPointsPercentageDragged
|
|
114
|
+
} = useSnapPoints({
|
|
115
|
+
snapPoints,
|
|
116
|
+
activeSnapPointProp,
|
|
117
|
+
setActiveSnapPointProp,
|
|
118
|
+
drawerRef,
|
|
119
|
+
fadeFromIndex,
|
|
120
|
+
overlayRef,
|
|
121
|
+
onSnapPointChange,
|
|
122
|
+
direction,
|
|
123
|
+
container,
|
|
124
|
+
snapToSequentialPoint,
|
|
125
|
+
isOpen,
|
|
126
|
+
contentHeight,
|
|
127
|
+
detachedOffset: detached ? detachedOffset : 0,
|
|
128
|
+
maxContentHeight,
|
|
129
|
+
peekHeight,
|
|
130
|
+
initialAnimated
|
|
131
|
+
});
|
|
132
|
+
usePreventScroll({
|
|
133
|
+
isDisabled: !isOpen || isDragging || !modal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll
|
|
134
|
+
});
|
|
135
|
+
const {
|
|
136
|
+
restorePositionSetting
|
|
137
|
+
} = usePositionFixed({
|
|
138
|
+
isOpen,
|
|
139
|
+
modal,
|
|
140
|
+
nested: nested ?? false,
|
|
141
|
+
hasBeenOpened,
|
|
142
|
+
preventScrollRestoration,
|
|
143
|
+
noBodyStyles
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// While the sheet itself is being dragged, scrollables in the touched chain
|
|
147
|
+
// are frozen (overflow: hidden). Touch browsers latch the scroll gesture at
|
|
148
|
+
// touchstart and ignore preventDefault once scrolling has started, so making
|
|
149
|
+
// the scroller non-scrollable mid-gesture is the only reliable way to keep
|
|
150
|
+
// the content from panning along with the sheet.
|
|
151
|
+
const frozenScrollablesRef = React.useRef(null);
|
|
152
|
+
function freezeScrollables(target) {
|
|
153
|
+
if (frozenScrollablesRef.current) return;
|
|
154
|
+
const frozen = [];
|
|
155
|
+
let element = target instanceof HTMLElement ? target : null;
|
|
156
|
+
while (element && element !== drawerRef.current) {
|
|
157
|
+
if (isScrollable(element)) {
|
|
158
|
+
frozen.push({
|
|
159
|
+
element,
|
|
160
|
+
overflowX: element.style.overflowX,
|
|
161
|
+
overflowY: element.style.overflowY
|
|
162
|
+
});
|
|
163
|
+
element.style.overflowX = 'hidden';
|
|
164
|
+
element.style.overflowY = 'hidden';
|
|
165
|
+
}
|
|
166
|
+
element = element.parentElement;
|
|
167
|
+
}
|
|
168
|
+
frozenScrollablesRef.current = frozen;
|
|
169
|
+
}
|
|
170
|
+
function unfreezeScrollables() {
|
|
171
|
+
const frozen = frozenScrollablesRef.current;
|
|
172
|
+
if (!frozen) return;
|
|
173
|
+
frozenScrollablesRef.current = null;
|
|
174
|
+
for (const {
|
|
175
|
+
element,
|
|
176
|
+
overflowX,
|
|
177
|
+
overflowY
|
|
178
|
+
} of frozen) {
|
|
179
|
+
element.style.overflowX = overflowX;
|
|
180
|
+
element.style.overflowY = overflowY;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function getScale() {
|
|
184
|
+
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
185
|
+
}
|
|
186
|
+
function onPress(event) {
|
|
187
|
+
if (!draggable) return;
|
|
188
|
+
if (!dismissible && !snapPoints) return;
|
|
189
|
+
if (drawerRef.current && !drawerRef.current.contains(event.target)) return;
|
|
190
|
+
drawerHeightRef.current = drawerRef.current?.getBoundingClientRect().height || 0;
|
|
191
|
+
drawerWidthRef.current = drawerRef.current?.getBoundingClientRect().width || 0;
|
|
192
|
+
setIsDragging(true);
|
|
193
|
+
dragStartTime.current = new Date();
|
|
194
|
+
|
|
195
|
+
// iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging
|
|
196
|
+
if (isIOS()) {
|
|
197
|
+
window.addEventListener('touchend', () => isAllowedToDrag.current = false, {
|
|
198
|
+
once: true
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
// Ensure we maintain correct pointer capture even when going outside of the drawer
|
|
202
|
+
event.target.setPointerCapture(event.pointerId);
|
|
203
|
+
pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
|
|
204
|
+
}
|
|
205
|
+
function shouldDrag(el, isDraggingInDirection) {
|
|
206
|
+
let element = el;
|
|
207
|
+
const highlightedText = window.getSelection()?.toString();
|
|
208
|
+
const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
|
|
209
|
+
const date = new Date();
|
|
210
|
+
|
|
211
|
+
// Fixes https://github.com/emilkowalski/vaul/issues/483
|
|
212
|
+
if (element.tagName === 'SELECT') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (direction === 'right' || direction === 'left') {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Allow scrolling when animating
|
|
223
|
+
if (openTime.current && date.getTime() - openTime.current.getTime() < 500) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (swipeAmount !== null) {
|
|
227
|
+
// Translated past the drag threshold → keep dragging. Below the last
|
|
228
|
+
// snap point the threshold is 0, so the sheet always wins over content
|
|
229
|
+
// scrolling. At the last snap point the threshold is its resting
|
|
230
|
+
// translate — which can still be > 0 when the max detent < 1 — so an
|
|
231
|
+
// at-rest sheet falls through to the scroll checks and content
|
|
232
|
+
// scrolling wins, matching native. Mid-drag/mid-animation the sheet is
|
|
233
|
+
// displaced past rest and still wins.
|
|
234
|
+
const atLastSnapPoint = snapPoints && activeSnapPointIndex === snapPoints.length - 1;
|
|
235
|
+
const restOffset = atLastSnapPoint ? snapPointsOffset?.[activeSnapPointIndex] ?? 0 : 0;
|
|
236
|
+
if (direction === 'bottom' ? swipeAmount > restOffset + 1 : swipeAmount < restOffset - 1) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Don't drag if there's highlighted text
|
|
242
|
+
if (highlightedText && highlightedText.length > 0) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Disallow dragging if drawer was scrolled within `scrollLockTimeout`.
|
|
247
|
+
// Don't re-arm the timestamp here — a prevented drag attempt is not a
|
|
248
|
+
// scroll, and re-arming would keep the lock alive for as long as the
|
|
249
|
+
// finger moves, deadening the whole gesture instead of just the first
|
|
250
|
+
// `scrollLockTimeout` ms after the last real scroll.
|
|
251
|
+
if (lastTimeDragPrevented.current && date.getTime() - lastTimeDragPrevented.current.getTime() < scrollLockTimeout && swipeAmount === 0) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
if (isDraggingInDirection) {
|
|
255
|
+
lastTimeDragPrevented.current = date;
|
|
256
|
+
|
|
257
|
+
// We are dragging down so we should allow scrolling
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Keep climbing up the DOM tree as long as there's a parent
|
|
262
|
+
while (element) {
|
|
263
|
+
// Check if the element is scrollable
|
|
264
|
+
if (element.scrollHeight > element.clientHeight) {
|
|
265
|
+
// `> 0`, not `!== 0`: Safari reports a negative scrollTop during the
|
|
266
|
+
// rubber-band bounce at the top — that's "at the top" for drag
|
|
267
|
+
// purposes, and treating it as scrolled would arm the scroll lock and
|
|
268
|
+
// delay the sheet drag until the bounce fully settles.
|
|
269
|
+
if (element.scrollTop > 0) {
|
|
270
|
+
lastTimeDragPrevented.current = new Date();
|
|
271
|
+
|
|
272
|
+
// The element is scrollable and not scrolled to the top, so don't drag
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
if (element.getAttribute('role') === 'dialog') {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Move up to the parent element
|
|
281
|
+
element = element.parentNode;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// No scrollable parents not scrolled to the top found, so drag
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
function drag(event, pointerEvent) {
|
|
288
|
+
if (!drawerRef.current) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// We need to know how much of the drawer has been dragged in percentages so that we can transform background accordingly
|
|
293
|
+
if (isDragging) {
|
|
294
|
+
const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
|
|
295
|
+
const draggedDistance = (pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX)) * directionMultiplier;
|
|
296
|
+
const isDraggingInDirection = draggedDistance > 0;
|
|
297
|
+
|
|
298
|
+
// Pre condition for disallowing dragging in the close direction.
|
|
299
|
+
const noCloseSnapPointsPreCondition = snapPoints && !dismissible && !isDraggingInDirection;
|
|
300
|
+
|
|
301
|
+
// Disallow dragging down to close when first snap point is the active one and dismissible prop is set to false.
|
|
302
|
+
if (noCloseSnapPointsPreCondition && activeSnapPointIndex === 0) return;
|
|
303
|
+
|
|
304
|
+
// We need to capture last time when drag with scroll was triggered and have a timeout between
|
|
305
|
+
const absDraggedDistance = Math.abs(draggedDistance);
|
|
306
|
+
const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
|
|
307
|
+
const drawerDimension = direction === 'bottom' || direction === 'top' ? drawerHeightRef.current : drawerWidthRef.current;
|
|
308
|
+
|
|
309
|
+
// Calculate the percentage dragged, where 1 is the closed position
|
|
310
|
+
let percentageDragged = absDraggedDistance / drawerDimension;
|
|
311
|
+
const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);
|
|
312
|
+
if (snapPointPercentageDragged !== null) {
|
|
313
|
+
percentageDragged = snapPointPercentageDragged;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Disallow close dragging beyond the smallest snap point.
|
|
317
|
+
if (noCloseSnapPointsPreCondition && percentageDragged >= 1) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (!isAllowedToDrag.current) {
|
|
321
|
+
if (!shouldDrag(event.target, isDraggingInDirection)) return;
|
|
322
|
+
drawerRef.current.classList.add(DRAG_CLASS);
|
|
323
|
+
// 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
|
|
324
|
+
isAllowedToDrag.current = true;
|
|
325
|
+
// Touch pans latched onto a scroller would keep scrolling the content
|
|
326
|
+
// along with the sheet drag — freeze them for the drag's duration.
|
|
327
|
+
if (event.pointerType !== 'mouse') freezeScrollables(event.target);
|
|
328
|
+
// Drag can engage mid-gesture (content scrolled back to its top under
|
|
329
|
+
// the same finger, or the scroll lock expiring). Re-anchor and start
|
|
330
|
+
// moving on the next tick so the sheet tracks the finger from here
|
|
331
|
+
// instead of jumping by the distance the gesture already consumed.
|
|
332
|
+
pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
set(drawerRef.current, {
|
|
336
|
+
transition: 'none'
|
|
337
|
+
});
|
|
338
|
+
set(overlayRef.current, {
|
|
339
|
+
transition: 'none'
|
|
340
|
+
});
|
|
341
|
+
if (pointerEvent) onDragProp?.(pointerEvent, percentageDragged);
|
|
342
|
+
if (snapPoints) {
|
|
343
|
+
onDragSnapPoints({
|
|
344
|
+
draggedDistance
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Run this only if snapPoints are not defined or if we are at the last snap point (highest one)
|
|
349
|
+
if (isDraggingInDirection && !snapPoints) {
|
|
350
|
+
const dampenedDraggedDistance = dampenValue(draggedDistance);
|
|
351
|
+
const translateValue = Math.min(dampenedDraggedDistance * -1, 0) * directionMultiplier;
|
|
352
|
+
set(drawerRef.current, {
|
|
353
|
+
transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
|
|
354
|
+
});
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const opacityValue = 1 - percentageDragged;
|
|
358
|
+
if (shouldFade || fadeFromIndex && activeSnapPointIndex === fadeFromIndex - 1) {
|
|
359
|
+
set(overlayRef.current, {
|
|
360
|
+
opacity: `${opacityValue}`,
|
|
361
|
+
transition: 'none'
|
|
362
|
+
}, true);
|
|
363
|
+
}
|
|
364
|
+
if (wrapper && overlayRef.current && shouldScaleBackground) {
|
|
365
|
+
// Calculate percentageDragged as a fraction (0 to 1)
|
|
366
|
+
const scaleValue = Math.min(getScale() + percentageDragged * (1 - getScale()), 1);
|
|
367
|
+
const borderRadiusValue = 8 - percentageDragged * 8;
|
|
368
|
+
const translateValue = Math.max(0, 14 - percentageDragged * 14);
|
|
369
|
+
set(wrapper, {
|
|
370
|
+
borderRadius: `${borderRadiusValue}px`,
|
|
371
|
+
transform: isVertical(direction) ? `scale(${scaleValue}) translate3d(0, ${translateValue}px, 0)` : `scale(${scaleValue}) translate3d(${translateValue}px, 0, 0)`,
|
|
372
|
+
transition: 'none'
|
|
373
|
+
}, true);
|
|
374
|
+
}
|
|
375
|
+
if (!snapPoints) {
|
|
376
|
+
const translateValue = absDraggedDistance * directionMultiplier;
|
|
377
|
+
set(drawerRef.current, {
|
|
378
|
+
transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
React.useEffect(() => {
|
|
384
|
+
window.requestAnimationFrame(() => {
|
|
385
|
+
shouldAnimate.current = true;
|
|
386
|
+
});
|
|
387
|
+
}, []);
|
|
388
|
+
|
|
389
|
+
// Reset to the first snap point on every open so a prior session's active snap
|
|
390
|
+
// (kept in state by `useControllableState` after dismissal) doesn't leak into
|
|
391
|
+
// the next present. Skipped when `activeSnapPoint` is controlled externally.
|
|
392
|
+
React.useEffect(() => {
|
|
393
|
+
if (isOpen && snapPoints && activeSnapPointProp === undefined) {
|
|
394
|
+
setActiveSnapPoint(snapPoints[0]);
|
|
395
|
+
}
|
|
396
|
+
}, [isOpen]);
|
|
397
|
+
const onPositionChangeRef = React.useRef(onPositionChange);
|
|
398
|
+
React.useEffect(() => {
|
|
399
|
+
onPositionChangeRef.current = onPositionChange;
|
|
400
|
+
});
|
|
401
|
+
React.useEffect(() => {
|
|
402
|
+
function onVisualViewportChange() {
|
|
403
|
+
if (!drawerRef.current || !repositionInputs) return;
|
|
404
|
+
const focusedElement = document.activeElement;
|
|
405
|
+
if (isInput(focusedElement) || keyboardIsOpen.current) {
|
|
406
|
+
const visualViewportHeight = window.visualViewport?.height || 0;
|
|
407
|
+
const totalHeight = window.innerHeight;
|
|
408
|
+
// This is the height of the keyboard
|
|
409
|
+
let diffFromInitial = totalHeight - visualViewportHeight;
|
|
410
|
+
const drawerHeight = drawerRef.current.getBoundingClientRect().height || 0;
|
|
411
|
+
// Adjust drawer height only if it's tall enough
|
|
412
|
+
const isTallEnough = drawerHeight > totalHeight * 0.8;
|
|
413
|
+
if (!initialDrawerHeight.current) {
|
|
414
|
+
initialDrawerHeight.current = drawerHeight;
|
|
415
|
+
}
|
|
416
|
+
const offsetFromTop = drawerRef.current.getBoundingClientRect().top;
|
|
417
|
+
|
|
418
|
+
// 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.
|
|
419
|
+
if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 60) {
|
|
420
|
+
keyboardIsOpen.current = !keyboardIsOpen.current;
|
|
421
|
+
}
|
|
422
|
+
if (snapPoints && snapPoints.length > 0 && snapPointsOffset && activeSnapPointIndex) {
|
|
423
|
+
const activeSnapPointHeight = snapPointsOffset[activeSnapPointIndex] || 0;
|
|
424
|
+
diffFromInitial += activeSnapPointHeight;
|
|
425
|
+
}
|
|
426
|
+
previousDiffFromInitial.current = diffFromInitial;
|
|
427
|
+
// 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
|
|
428
|
+
if (drawerHeight > visualViewportHeight || keyboardIsOpen.current) {
|
|
429
|
+
const height = drawerRef.current.getBoundingClientRect().height;
|
|
430
|
+
let newDrawerHeight = height;
|
|
431
|
+
if (height > visualViewportHeight) {
|
|
432
|
+
newDrawerHeight = visualViewportHeight - (isTallEnough ? offsetFromTop : WINDOW_TOP_OFFSET);
|
|
433
|
+
}
|
|
434
|
+
// 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
|
|
435
|
+
if (fixed) {
|
|
436
|
+
drawerRef.current.style.height = `${height - Math.max(diffFromInitial, 0)}px`;
|
|
437
|
+
} else {
|
|
438
|
+
drawerRef.current.style.height = `${Math.max(newDrawerHeight, visualViewportHeight - offsetFromTop)}px`;
|
|
439
|
+
}
|
|
440
|
+
} else if (!isMobileFirefox()) {
|
|
441
|
+
drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
|
|
442
|
+
}
|
|
443
|
+
if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
|
|
444
|
+
drawerRef.current.style.bottom = '0px';
|
|
445
|
+
} else {
|
|
446
|
+
// Negative bottom value would never make sense
|
|
447
|
+
drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
window.visualViewport?.addEventListener('resize', onVisualViewportChange);
|
|
452
|
+
return () => window.visualViewport?.removeEventListener('resize', onVisualViewportChange);
|
|
453
|
+
}, [activeSnapPointIndex, snapPoints, snapPointsOffset]);
|
|
454
|
+
function closeDrawer(fromWithin) {
|
|
455
|
+
cancelDrag();
|
|
456
|
+
onClose?.();
|
|
457
|
+
if (!fromWithin) {
|
|
458
|
+
setIsOpen(false);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function resetDrawer() {
|
|
462
|
+
if (!drawerRef.current) return;
|
|
463
|
+
const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
|
|
464
|
+
const currentSwipeAmount = getTranslate(drawerRef.current, direction);
|
|
465
|
+
set(drawerRef.current, {
|
|
466
|
+
transform: 'translate3d(0, 0, 0)',
|
|
467
|
+
transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
|
|
468
|
+
});
|
|
469
|
+
set(overlayRef.current, {
|
|
470
|
+
transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
|
|
471
|
+
opacity: '1'
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Don't reset background if swiped upwards
|
|
475
|
+
if (shouldScaleBackground && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) {
|
|
476
|
+
set(wrapper, {
|
|
477
|
+
borderRadius: `${BORDER_RADIUS}px`,
|
|
478
|
+
overflow: 'hidden',
|
|
479
|
+
...(isVertical(direction) ? {
|
|
480
|
+
transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
|
|
481
|
+
transformOrigin: 'top'
|
|
482
|
+
} : {
|
|
483
|
+
transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
|
|
484
|
+
transformOrigin: 'left'
|
|
485
|
+
}),
|
|
486
|
+
transitionProperty: 'transform, border-radius',
|
|
487
|
+
transitionDuration: `${TRANSITIONS.DURATION}s`,
|
|
488
|
+
transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`
|
|
489
|
+
}, true);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function cancelDrag() {
|
|
493
|
+
if (!isDragging || !drawerRef.current) return;
|
|
494
|
+
drawerRef.current.classList.remove(DRAG_CLASS);
|
|
495
|
+
isAllowedToDrag.current = false;
|
|
496
|
+
unfreezeScrollables();
|
|
497
|
+
setIsDragging(false);
|
|
498
|
+
dragEndTime.current = new Date();
|
|
499
|
+
}
|
|
500
|
+
function release(event, pointerEvent) {
|
|
501
|
+
if (!isDragging || !drawerRef.current) return;
|
|
502
|
+
drawerRef.current.classList.remove(DRAG_CLASS);
|
|
503
|
+
isAllowedToDrag.current = false;
|
|
504
|
+
unfreezeScrollables();
|
|
505
|
+
setIsDragging(false);
|
|
506
|
+
dragEndTime.current = new Date();
|
|
507
|
+
const swipeAmount = getTranslate(drawerRef.current, direction);
|
|
508
|
+
|
|
509
|
+
// Drag overshoot below the lowest snap point translates the detached
|
|
510
|
+
// wrapper while the drawer stays pinned (see onDrag in use-snap-points) —
|
|
511
|
+
// common when a clamped 'auto' puts the lowest snap point at 0. Count the
|
|
512
|
+
// wrapper's translation as movement, or the release is swallowed and the
|
|
513
|
+
// sheet is left stuck at the overshoot position.
|
|
514
|
+
const wrapper = drawerRef.current.closest('[data-vaul-detached-wrapper]');
|
|
515
|
+
const wrapperSwipeAmount = wrapper ? getTranslate(wrapper, direction) : null;
|
|
516
|
+
const hasMoved = Boolean(swipeAmount) || Boolean(wrapperSwipeAmount);
|
|
517
|
+
if (!event || !shouldDrag(event.target, false) || !hasMoved || Number.isNaN(swipeAmount)) return;
|
|
518
|
+
if (dragStartTime.current === null) return;
|
|
519
|
+
const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
|
|
520
|
+
const distMoved = pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX);
|
|
521
|
+
const velocity = Math.abs(distMoved) / timeTaken;
|
|
522
|
+
if (velocity > 0.05) {
|
|
523
|
+
// `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.
|
|
524
|
+
setJustReleased(true);
|
|
525
|
+
setTimeout(() => {
|
|
526
|
+
setJustReleased(false);
|
|
527
|
+
}, 200);
|
|
528
|
+
}
|
|
529
|
+
if (snapPoints) {
|
|
530
|
+
const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
|
|
531
|
+
onReleaseSnapPoints({
|
|
532
|
+
draggedDistance: distMoved * directionMultiplier,
|
|
533
|
+
closeDrawer,
|
|
534
|
+
velocity,
|
|
535
|
+
dismissible
|
|
536
|
+
});
|
|
537
|
+
if (pointerEvent) onReleaseProp?.(pointerEvent, true);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Moved upwards, don't do anything
|
|
542
|
+
if (direction === 'bottom' || direction === 'right' ? distMoved > 0 : distMoved < 0) {
|
|
543
|
+
resetDrawer();
|
|
544
|
+
if (pointerEvent) onReleaseProp?.(pointerEvent, true);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (velocity > VELOCITY_THRESHOLD) {
|
|
548
|
+
closeDrawer();
|
|
549
|
+
if (pointerEvent) onReleaseProp?.(pointerEvent, false);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const visibleDrawerHeight = Math.min(drawerRef.current.getBoundingClientRect().height ?? 0, window.innerHeight);
|
|
553
|
+
const visibleDrawerWidth = Math.min(drawerRef.current.getBoundingClientRect().width ?? 0, window.innerWidth);
|
|
554
|
+
const isHorizontalSwipe = direction === 'left' || direction === 'right';
|
|
555
|
+
if (Math.abs(swipeAmount ?? 0) >= (isHorizontalSwipe ? visibleDrawerWidth : visibleDrawerHeight) * closeThreshold) {
|
|
556
|
+
closeDrawer();
|
|
557
|
+
if (pointerEvent) onReleaseProp?.(pointerEvent, false);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (pointerEvent) onReleaseProp?.(pointerEvent, true);
|
|
561
|
+
resetDrawer();
|
|
562
|
+
}
|
|
563
|
+
React.useEffect(() => {
|
|
564
|
+
// Trigger enter animation without using CSS animation
|
|
565
|
+
if (isOpen) {
|
|
566
|
+
set(document.documentElement, {
|
|
567
|
+
scrollBehavior: 'auto'
|
|
568
|
+
});
|
|
569
|
+
openTime.current = new Date();
|
|
570
|
+
}
|
|
571
|
+
return () => {
|
|
572
|
+
reset(document.documentElement, 'scrollBehavior');
|
|
573
|
+
};
|
|
574
|
+
}, [isOpen]);
|
|
575
|
+
function onNestedOpenChange(o) {
|
|
576
|
+
const scale = o ? (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth : 1;
|
|
577
|
+
const initialTranslate = o ? -NESTED_DISPLACEMENT : 0;
|
|
578
|
+
if (nestedOpenChangeTimer.current) {
|
|
579
|
+
window.clearTimeout(nestedOpenChangeTimer.current);
|
|
580
|
+
}
|
|
581
|
+
set(drawerRef.current, {
|
|
582
|
+
transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
|
|
583
|
+
transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)` : `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`
|
|
584
|
+
});
|
|
585
|
+
if (!o && drawerRef.current) {
|
|
586
|
+
nestedOpenChangeTimer.current = setTimeout(() => {
|
|
587
|
+
const translateValue = getTranslate(drawerRef.current, direction);
|
|
588
|
+
set(drawerRef.current, {
|
|
589
|
+
transition: 'none',
|
|
590
|
+
transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
|
|
591
|
+
});
|
|
592
|
+
}, 500);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function onNestedDrag(_event, percentageDragged) {
|
|
596
|
+
if (percentageDragged < 0) return;
|
|
597
|
+
const initialScale = (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth;
|
|
598
|
+
const newScale = initialScale + percentageDragged * (1 - initialScale);
|
|
599
|
+
const newTranslate = -NESTED_DISPLACEMENT + percentageDragged * NESTED_DISPLACEMENT;
|
|
600
|
+
set(drawerRef.current, {
|
|
601
|
+
transform: isVertical(direction) ? `scale(${newScale}) translate3d(0, ${newTranslate}px, 0)` : `scale(${newScale}) translate3d(${newTranslate}px, 0, 0)`,
|
|
602
|
+
transition: 'none'
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function onNestedRelease(_event, o) {
|
|
606
|
+
const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
|
|
607
|
+
const scale = o ? (dim - NESTED_DISPLACEMENT) / dim : 1;
|
|
608
|
+
const translate = o ? -NESTED_DISPLACEMENT : 0;
|
|
609
|
+
if (o) {
|
|
610
|
+
set(drawerRef.current, {
|
|
611
|
+
transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
|
|
612
|
+
transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${translate}px, 0)` : `scale(${scale}) translate3d(${translate}px, 0, 0)`
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return /*#__PURE__*/_jsx(DialogPrimitive.Root, {
|
|
617
|
+
defaultOpen: defaultOpen,
|
|
618
|
+
onOpenChange: open => {
|
|
619
|
+
if (!dismissible && !open) return;
|
|
620
|
+
if (open) {
|
|
621
|
+
setHasBeenOpened(true);
|
|
622
|
+
} else {
|
|
623
|
+
closeDrawer(true);
|
|
624
|
+
}
|
|
625
|
+
setIsOpen(open);
|
|
626
|
+
},
|
|
627
|
+
open: isOpen
|
|
628
|
+
// Always non-modal at the Radix level — Radix's modal mode locks
|
|
629
|
+
// body.style.pointerEvents and its restore on layer unmount is buggy
|
|
630
|
+
// (see git history). Vaul's own overlay handles click-trapping; the
|
|
631
|
+
// overlay sets pointer-events: none below fadeFromIndex so clicks
|
|
632
|
+
// pass through to the page (matches native dimmedDetentIndex). Vaul's
|
|
633
|
+
// own `modal` prop still drives overlay rendering and click-outside
|
|
634
|
+
// behavior below.
|
|
635
|
+
,
|
|
636
|
+
modal: false,
|
|
637
|
+
children: /*#__PURE__*/_jsx(DrawerContext.Provider, {
|
|
638
|
+
value: {
|
|
639
|
+
activeSnapPoint,
|
|
640
|
+
snapPoints,
|
|
641
|
+
setActiveSnapPoint,
|
|
642
|
+
drawerRef,
|
|
643
|
+
overlayRef,
|
|
644
|
+
onOpenChange,
|
|
645
|
+
onPress,
|
|
646
|
+
onRelease: event => release(event, event ?? undefined),
|
|
647
|
+
onDrag: event => drag(event, event),
|
|
648
|
+
onTouchDrag: (event, pointerEvent) => drag(event, pointerEvent),
|
|
649
|
+
onTouchRelease: (event, pointerEvent) => release(event, pointerEvent),
|
|
650
|
+
dismissible,
|
|
651
|
+
shouldAnimate,
|
|
652
|
+
handleOnly,
|
|
653
|
+
isOpen,
|
|
654
|
+
isDragging,
|
|
655
|
+
shouldFade,
|
|
656
|
+
closeDrawer,
|
|
657
|
+
onNestedDrag,
|
|
658
|
+
onNestedOpenChange,
|
|
659
|
+
onNestedRelease,
|
|
660
|
+
keyboardIsOpen,
|
|
661
|
+
modal,
|
|
662
|
+
snapPointsOffset,
|
|
663
|
+
activeSnapPointIndex,
|
|
664
|
+
fadeFromIndex,
|
|
665
|
+
direction,
|
|
666
|
+
shouldScaleBackground,
|
|
667
|
+
setBackgroundColorOnScale,
|
|
668
|
+
noBodyStyles,
|
|
669
|
+
container,
|
|
670
|
+
autoFocus,
|
|
671
|
+
onPositionChangeRef,
|
|
672
|
+
setContentHeight,
|
|
673
|
+
detached,
|
|
674
|
+
detachedOffset: detached ? detachedOffset : 0,
|
|
675
|
+
detachedRadius: detached ? detachedRadius : 0,
|
|
676
|
+
detachedWrapperStyle
|
|
677
|
+
},
|
|
678
|
+
children: children
|
|
679
|
+
})
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
export const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
683
|
+
style,
|
|
684
|
+
...rest
|
|
685
|
+
}, ref) => {
|
|
686
|
+
const {
|
|
687
|
+
overlayRef,
|
|
688
|
+
snapPoints,
|
|
689
|
+
onRelease,
|
|
690
|
+
shouldFade,
|
|
691
|
+
isOpen,
|
|
692
|
+
modal,
|
|
693
|
+
shouldAnimate,
|
|
694
|
+
activeSnapPointIndex,
|
|
695
|
+
fadeFromIndex
|
|
696
|
+
} = useDrawerContext();
|
|
697
|
+
const composedRef = useComposedRefs(ref, overlayRef);
|
|
698
|
+
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
699
|
+
const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
|
|
700
|
+
const onMouseUp = React.useCallback(event => onRelease(event), [onRelease]);
|
|
701
|
+
React.useEffect(() => {
|
|
702
|
+
if (hasSnapPoints) {
|
|
703
|
+
window.requestAnimationFrame(() => {
|
|
704
|
+
setDelayedSnapPoints(true);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}, []);
|
|
708
|
+
|
|
709
|
+
// Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
|
|
710
|
+
if (!modal) {
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// When the active snap is below fadeFromIndex, the overlay is fully
|
|
715
|
+
// transparent (CSS opacity: 0). Radix's DialogOverlayImpl sets inline
|
|
716
|
+
// `pointer-events: auto` which would still catch clicks on the invisible
|
|
717
|
+
// layer — drive this via React so it stays correct even before
|
|
718
|
+
// `snapToPoint` runs (Presence defers the drawer/overlay mount, leaving
|
|
719
|
+
// refs null on the first open effect pass).
|
|
720
|
+
const isBelowFade = hasSnapPoints && fadeFromIndex !== undefined && typeof activeSnapPointIndex === 'number' && activeSnapPointIndex < fadeFromIndex;
|
|
721
|
+
|
|
722
|
+
// Render our own overlay element instead of `DialogPrimitive.Overlay`:
|
|
723
|
+
// Radix's Overlay returns null when the Dialog is non-modal, and we run
|
|
724
|
+
// Radix as `modal={false}` to keep it from locking body pointer-events.
|
|
725
|
+
// `Presence` keeps the node mounted through the closing animation
|
|
726
|
+
// (`fadeOut`) before unmounting.
|
|
727
|
+
return /*#__PURE__*/_jsx(Presence, {
|
|
728
|
+
present: isOpen,
|
|
729
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
730
|
+
onMouseUp: onMouseUp,
|
|
731
|
+
ref: composedRef,
|
|
732
|
+
"data-state": isOpen ? 'open' : 'closed',
|
|
733
|
+
"data-vaul-overlay": "",
|
|
734
|
+
"data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
|
|
735
|
+
"data-vaul-delayed-snap-points": delayedSnapPoints ? 'true' : 'false',
|
|
736
|
+
"data-vaul-snap-points-overlay": isOpen && shouldFade ? 'true' : 'false',
|
|
737
|
+
"data-vaul-animate": shouldAnimate?.current ? 'true' : 'false',
|
|
738
|
+
...rest,
|
|
739
|
+
style: overlayStyle(style, !!isBelowFade)
|
|
740
|
+
})
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
Overlay.displayName = 'Drawer.Overlay';
|
|
744
|
+
const overlayStyle = (style, isBelowFade) => ({
|
|
745
|
+
...style,
|
|
746
|
+
pointerEvents: isBelowFade ? 'none' : 'auto'
|
|
747
|
+
});
|
|
748
|
+
export const Content = /*#__PURE__*/React.forwardRef(({
|
|
749
|
+
onPointerDownOutside,
|
|
750
|
+
onEscapeKeyDown,
|
|
751
|
+
style,
|
|
752
|
+
onOpenAutoFocus,
|
|
753
|
+
children,
|
|
754
|
+
detachedSiblings,
|
|
755
|
+
...rest
|
|
756
|
+
}, ref) => {
|
|
757
|
+
const {
|
|
758
|
+
drawerRef,
|
|
759
|
+
onPress,
|
|
760
|
+
onRelease,
|
|
761
|
+
onDrag,
|
|
762
|
+
onTouchDrag,
|
|
763
|
+
onTouchRelease,
|
|
764
|
+
keyboardIsOpen,
|
|
765
|
+
snapPointsOffset,
|
|
766
|
+
activeSnapPointIndex,
|
|
767
|
+
fadeFromIndex,
|
|
768
|
+
modal,
|
|
769
|
+
isOpen,
|
|
770
|
+
isDragging,
|
|
771
|
+
direction,
|
|
772
|
+
snapPoints,
|
|
773
|
+
setActiveSnapPoint,
|
|
774
|
+
dismissible,
|
|
775
|
+
container,
|
|
776
|
+
handleOnly,
|
|
777
|
+
shouldAnimate,
|
|
778
|
+
autoFocus,
|
|
779
|
+
onPositionChangeRef,
|
|
780
|
+
setContentHeight,
|
|
781
|
+
detached,
|
|
782
|
+
detachedOffset,
|
|
783
|
+
detachedRadius,
|
|
784
|
+
detachedWrapperStyle: detachedWrapperStyleProp
|
|
785
|
+
} = useDrawerContext();
|
|
786
|
+
// Always measure the inner wrapper's natural height. The drawer itself may
|
|
787
|
+
// be styled to a fixed viewport height, so we measure an inner wrapper
|
|
788
|
+
// instead. Ref callback starts the observer as soon as the node mounts
|
|
789
|
+
// (Radix Presence defers the portal mount past useEffect). The measurement
|
|
790
|
+
// drives the 'auto' snap point and is also exposed via
|
|
791
|
+
// `onContentHeightChange` for callers that size the surrounding card.
|
|
792
|
+
const autoRoRef = React.useRef(null);
|
|
793
|
+
const setAutoSizeNode = React.useCallback(node => {
|
|
794
|
+
autoRoRef.current?.disconnect();
|
|
795
|
+
if (!node) {
|
|
796
|
+
autoRoRef.current = null;
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
const measure = () => setContentHeight(node.offsetHeight);
|
|
800
|
+
measure();
|
|
801
|
+
const ro = new ResizeObserver(measure);
|
|
802
|
+
ro.observe(node);
|
|
803
|
+
autoRoRef.current = ro;
|
|
804
|
+
}, [setContentHeight]);
|
|
805
|
+
const isBelowFade = snapPoints !== undefined && snapPoints !== null && fadeFromIndex !== undefined && typeof activeSnapPointIndex === 'number' && activeSnapPointIndex < fadeFromIndex;
|
|
806
|
+
// Needed to use transition instead of animations
|
|
807
|
+
const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
|
|
808
|
+
const composedRef = useComposedRefs(ref, drawerRef);
|
|
809
|
+
const pointerStartRef = React.useRef(null);
|
|
810
|
+
const lastKnownPointerEventRef = React.useRef(null);
|
|
811
|
+
const continuingCanceledTouchRef = React.useRef(false);
|
|
812
|
+
const wasBeyondThePointRef = React.useRef(false);
|
|
813
|
+
const hasSnapPoints = snapPoints && snapPoints.length > 0;
|
|
814
|
+
useScaleBackground();
|
|
815
|
+
const isDeltaInDirection = (delta, dir, threshold = 0) => {
|
|
816
|
+
if (wasBeyondThePointRef.current) return true;
|
|
817
|
+
const deltaY = Math.abs(delta.y);
|
|
818
|
+
const deltaX = Math.abs(delta.x);
|
|
819
|
+
const isDeltaX = deltaX > deltaY;
|
|
820
|
+
const dFactor = ['bottom', 'right'].includes(dir) ? 1 : -1;
|
|
821
|
+
if (dir === 'left' || dir === 'right') {
|
|
822
|
+
const isReverseDirection = delta.x * dFactor < 0;
|
|
823
|
+
if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
|
|
824
|
+
return isDeltaX;
|
|
825
|
+
}
|
|
826
|
+
} else {
|
|
827
|
+
const isReverseDirection = delta.y * dFactor < 0;
|
|
828
|
+
if (!isReverseDirection && deltaY >= 0 && deltaY <= threshold) {
|
|
829
|
+
return !isDeltaX;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
wasBeyondThePointRef.current = true;
|
|
833
|
+
return true;
|
|
834
|
+
};
|
|
835
|
+
React.useEffect(() => {
|
|
836
|
+
if (hasSnapPoints) {
|
|
837
|
+
window.requestAnimationFrame(() => {
|
|
838
|
+
setDelayedSnapPoints(true);
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
}, []);
|
|
842
|
+
|
|
843
|
+
// Event-driven position tracking. We only tick RAF while the drawer is
|
|
844
|
+
// actually moving (drag / CSS transition / CSS animation). When it's idle at
|
|
845
|
+
// a snap, no frames run at all.
|
|
846
|
+
const positionTrackingRef = React.useRef(null);
|
|
847
|
+
React.useEffect(() => {
|
|
848
|
+
const drawer = drawerRef.current;
|
|
849
|
+
if (!drawer) return;
|
|
850
|
+
const state = {
|
|
851
|
+
rafId: null,
|
|
852
|
+
movingCount: 0,
|
|
853
|
+
lastPosition: Number.NaN,
|
|
854
|
+
start: () => {},
|
|
855
|
+
stop: () => {}
|
|
856
|
+
};
|
|
857
|
+
const emit = () => {
|
|
858
|
+
const cb = onPositionChangeRef.current;
|
|
859
|
+
if (!cb) return;
|
|
860
|
+
const position = drawer.getBoundingClientRect().top;
|
|
861
|
+
if (position !== state.lastPosition) {
|
|
862
|
+
state.lastPosition = position;
|
|
863
|
+
cb(position);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
const tick = () => {
|
|
867
|
+
emit();
|
|
868
|
+
state.rafId = state.movingCount > 0 ? window.requestAnimationFrame(tick) : null;
|
|
869
|
+
};
|
|
870
|
+
state.start = () => {
|
|
871
|
+
state.movingCount += 1;
|
|
872
|
+
if (state.rafId === null) {
|
|
873
|
+
state.rafId = window.requestAnimationFrame(tick);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
state.stop = () => {
|
|
877
|
+
state.movingCount = Math.max(0, state.movingCount - 1);
|
|
878
|
+
// RAF loop will exit on its next tick; emit the settled position now.
|
|
879
|
+
if (state.movingCount === 0) emit();
|
|
880
|
+
};
|
|
881
|
+
const wrapper = drawer.closest('[data-vaul-detached-wrapper]');
|
|
882
|
+
|
|
883
|
+
// Listen on the wrapper too: drag-overshoot snap-back animates the wrapper
|
|
884
|
+
// alone when the drawer's target is unchanged (e.g. snapping back to the
|
|
885
|
+
// same detent). Without this, position goes stale mid-animation because
|
|
886
|
+
// the drawer's `transitionrun` never fires.
|
|
887
|
+
const onTransitionRun = e => {
|
|
888
|
+
if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform') state.start();
|
|
889
|
+
};
|
|
890
|
+
const onTransitionDone = e => {
|
|
891
|
+
if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform') state.stop();
|
|
892
|
+
};
|
|
893
|
+
const onAnimationStart = e => {
|
|
894
|
+
if (e.target === drawer || e.target === wrapper) state.start();
|
|
895
|
+
};
|
|
896
|
+
const onAnimationDone = e => {
|
|
897
|
+
if (e.target === drawer || e.target === wrapper) state.stop();
|
|
898
|
+
};
|
|
899
|
+
drawer.addEventListener('transitionrun', onTransitionRun);
|
|
900
|
+
drawer.addEventListener('transitionend', onTransitionDone);
|
|
901
|
+
drawer.addEventListener('transitioncancel', onTransitionDone);
|
|
902
|
+
drawer.addEventListener('animationstart', onAnimationStart);
|
|
903
|
+
drawer.addEventListener('animationend', onAnimationDone);
|
|
904
|
+
drawer.addEventListener('animationcancel', onAnimationDone);
|
|
905
|
+
wrapper?.addEventListener('transitionrun', onTransitionRun);
|
|
906
|
+
wrapper?.addEventListener('transitionend', onTransitionDone);
|
|
907
|
+
wrapper?.addEventListener('transitioncancel', onTransitionDone);
|
|
908
|
+
positionTrackingRef.current = state;
|
|
909
|
+
emit();
|
|
910
|
+
return () => {
|
|
911
|
+
drawer.removeEventListener('transitionrun', onTransitionRun);
|
|
912
|
+
drawer.removeEventListener('transitionend', onTransitionDone);
|
|
913
|
+
drawer.removeEventListener('transitioncancel', onTransitionDone);
|
|
914
|
+
drawer.removeEventListener('animationstart', onAnimationStart);
|
|
915
|
+
drawer.removeEventListener('animationend', onAnimationDone);
|
|
916
|
+
drawer.removeEventListener('animationcancel', onAnimationDone);
|
|
917
|
+
wrapper?.removeEventListener('transitionrun', onTransitionRun);
|
|
918
|
+
wrapper?.removeEventListener('transitionend', onTransitionDone);
|
|
919
|
+
wrapper?.removeEventListener('transitioncancel', onTransitionDone);
|
|
920
|
+
if (state.rafId !== null) window.cancelAnimationFrame(state.rafId);
|
|
921
|
+
positionTrackingRef.current = null;
|
|
922
|
+
};
|
|
923
|
+
}, []);
|
|
924
|
+
React.useEffect(() => {
|
|
925
|
+
const state = positionTrackingRef.current;
|
|
926
|
+
if (!state) return;
|
|
927
|
+
if (isDragging) state.start();else state.stop();
|
|
928
|
+
}, [isDragging]);
|
|
929
|
+
function handleOnPointerUp(event) {
|
|
930
|
+
pointerStartRef.current = null;
|
|
931
|
+
wasBeyondThePointRef.current = false;
|
|
932
|
+
onRelease(event);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// The drawer always sits inside a fixed clip wrapper. `contain: paint`
|
|
936
|
+
// establishes the wrapper as the containing block so the drawer's own
|
|
937
|
+
// `position: fixed` is constrained here, and `overflow: hidden` keeps any
|
|
938
|
+
// overshoot out of the viewport. When `detached` the wrapper also floats
|
|
939
|
+
// with a bottom gap and rounded bottom corners; otherwise it sits flush.
|
|
940
|
+
// Transform/transition are managed imperatively (via drag overshoot and the
|
|
941
|
+
// dismiss effect) so React doesn't skip DOM writes for values it thinks it
|
|
942
|
+
// already owns.
|
|
943
|
+
const wrapperStyle = React.useMemo(() => ({
|
|
944
|
+
position: 'fixed',
|
|
945
|
+
top: 0,
|
|
946
|
+
left: 0,
|
|
947
|
+
right: 0,
|
|
948
|
+
bottom: detached ? detachedOffset : 0,
|
|
949
|
+
overflow: 'hidden',
|
|
950
|
+
contain: 'paint',
|
|
951
|
+
pointerEvents: 'none',
|
|
952
|
+
borderBottomLeftRadius: detached ? detachedRadius : 0,
|
|
953
|
+
borderBottomRightRadius: detached ? detachedRadius : 0,
|
|
954
|
+
...detachedWrapperStyleProp
|
|
955
|
+
}), [detached, detachedOffset, detachedRadius, detachedWrapperStyleProp]);
|
|
956
|
+
|
|
957
|
+
// Translate the wrapper off-screen on dismiss so the whole card slides out
|
|
958
|
+
// as one. The reset-then-target pattern on open forces the browser to
|
|
959
|
+
// record a starting value so the transition actually animates.
|
|
960
|
+
// Start at `false` so a mount with `isOpen=true` (autopresent via
|
|
961
|
+
// `initialDetentIndex`) is detected as a false→true transition and runs
|
|
962
|
+
// the slide-up animation instead of snapping straight to rest.
|
|
963
|
+
const wasOpenRef = React.useRef(false);
|
|
964
|
+
React.useEffect(() => {
|
|
965
|
+
if (!drawerRef.current) {
|
|
966
|
+
wasOpenRef.current = isOpen;
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const wrapper = drawerRef.current.closest('[data-vaul-detached-wrapper]');
|
|
970
|
+
if (wrapper) {
|
|
971
|
+
const transition = `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
|
|
972
|
+
const viewportH = typeof window !== 'undefined' ? window.innerHeight : 0;
|
|
973
|
+
if (!isOpen && wasOpenRef.current) {
|
|
974
|
+
wrapper.style.transition = transition;
|
|
975
|
+
wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
|
|
976
|
+
} else if (isOpen && !wasOpenRef.current) {
|
|
977
|
+
wrapper.style.transition = 'none';
|
|
978
|
+
wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
|
|
979
|
+
// eslint-disable-next-line no-void
|
|
980
|
+
void wrapper.offsetHeight;
|
|
981
|
+
wrapper.style.transition = transition;
|
|
982
|
+
wrapper.style.transform = 'translate3d(0, 0, 0)';
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
wasOpenRef.current = isOpen;
|
|
986
|
+
}, [isOpen, detached, drawerRef]);
|
|
987
|
+
const contentNode = /*#__PURE__*/_jsx(DialogPrimitive.Content, {
|
|
988
|
+
"data-vaul-drawer-direction": direction,
|
|
989
|
+
"data-vaul-drawer": "",
|
|
990
|
+
"data-vaul-detached": detached ? 'true' : 'false',
|
|
991
|
+
"data-vaul-delayed-snap-points": delayedSnapPoints ? 'true' : 'false',
|
|
992
|
+
"data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
|
|
993
|
+
"data-vaul-custom-container": container ? 'true' : 'false',
|
|
994
|
+
"data-vaul-animate": shouldAnimate?.current ? 'true' : 'false',
|
|
995
|
+
...rest,
|
|
996
|
+
ref: composedRef,
|
|
997
|
+
style: snapPointsOffset && snapPointsOffset.length > 0 ? {
|
|
998
|
+
'--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]}px`,
|
|
999
|
+
...style,
|
|
1000
|
+
'pointerEvents': 'auto'
|
|
1001
|
+
} : {
|
|
1002
|
+
...style,
|
|
1003
|
+
pointerEvents: 'auto'
|
|
1004
|
+
},
|
|
1005
|
+
onPointerDown: event => {
|
|
1006
|
+
if (handleOnly) return;
|
|
1007
|
+
rest.onPointerDown?.(event);
|
|
1008
|
+
continuingCanceledTouchRef.current = false;
|
|
1009
|
+
pointerStartRef.current = {
|
|
1010
|
+
x: event.pageX,
|
|
1011
|
+
y: event.pageY
|
|
1012
|
+
};
|
|
1013
|
+
onPress(event);
|
|
1014
|
+
},
|
|
1015
|
+
onOpenAutoFocus: e => {
|
|
1016
|
+
onOpenAutoFocus?.(e);
|
|
1017
|
+
if (!autoFocus) {
|
|
1018
|
+
e.preventDefault();
|
|
1019
|
+
}
|
|
1020
|
+
},
|
|
1021
|
+
onPointerDownOutside: e => {
|
|
1022
|
+
onPointerDownOutside?.(e);
|
|
1023
|
+
if (!modal || e.defaultPrevented || isBelowFade) {
|
|
1024
|
+
e.preventDefault();
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// Non-dismissible + dimmed: collapse to the highest non-dimmed
|
|
1029
|
+
// snap point instead of silently swallowing the dismiss attempt.
|
|
1030
|
+
// Mirrors the native Android dim-tap behavior.
|
|
1031
|
+
if (!dismissible && hasSnapPoints && fadeFromIndex !== undefined && fadeFromIndex > 0 && typeof activeSnapPointIndex === 'number' && activeSnapPointIndex >= fadeFromIndex) {
|
|
1032
|
+
e.preventDefault();
|
|
1033
|
+
setActiveSnapPoint(snapPoints[fadeFromIndex - 1]);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
if (keyboardIsOpen.current) {
|
|
1037
|
+
keyboardIsOpen.current = false;
|
|
1038
|
+
}
|
|
1039
|
+
},
|
|
1040
|
+
onEscapeKeyDown: e => {
|
|
1041
|
+
onEscapeKeyDown?.(e);
|
|
1042
|
+
if (e.defaultPrevented) return;
|
|
1043
|
+
|
|
1044
|
+
// Non-dismissible: collapse to the first snap point (if above it)
|
|
1045
|
+
// instead of silently swallowing the dismiss attempt. Mirrors the
|
|
1046
|
+
// native Android back-press behavior.
|
|
1047
|
+
if (!dismissible) {
|
|
1048
|
+
e.preventDefault();
|
|
1049
|
+
if (hasSnapPoints && typeof activeSnapPointIndex === 'number' && activeSnapPointIndex > 0) {
|
|
1050
|
+
setActiveSnapPoint(snapPoints[0]);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
},
|
|
1054
|
+
onFocusOutside: e => {
|
|
1055
|
+
// Never auto-dismiss the sheet on focus shifts. Without Radix's
|
|
1056
|
+
// FocusScope trap (we run modal={false}), this fires whenever
|
|
1057
|
+
// focus naturally leaves the drawer — e.g. React Navigation's
|
|
1058
|
+
// web driver hides the previous screen via display:none, which
|
|
1059
|
+
// moves focus off the trigger and dismisses the sheet.
|
|
1060
|
+
e.preventDefault();
|
|
1061
|
+
},
|
|
1062
|
+
onPointerMove: event => {
|
|
1063
|
+
lastKnownPointerEventRef.current = event;
|
|
1064
|
+
if (handleOnly) return;
|
|
1065
|
+
rest.onPointerMove?.(event);
|
|
1066
|
+
if (!pointerStartRef.current) return;
|
|
1067
|
+
const yPosition = event.pageY - pointerStartRef.current.y;
|
|
1068
|
+
const xPosition = event.pageX - pointerStartRef.current.x;
|
|
1069
|
+
const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
|
|
1070
|
+
const delta = {
|
|
1071
|
+
x: xPosition,
|
|
1072
|
+
y: yPosition
|
|
1073
|
+
};
|
|
1074
|
+
const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
|
|
1075
|
+
if (isAllowedToSwipe) onDrag(event);else if (Math.abs(xPosition) > swipeStartThreshold || Math.abs(yPosition) > swipeStartThreshold) {
|
|
1076
|
+
pointerStartRef.current = null;
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
onPointerUp: event => {
|
|
1080
|
+
rest.onPointerUp?.(event);
|
|
1081
|
+
continuingCanceledTouchRef.current = false;
|
|
1082
|
+
pointerStartRef.current = null;
|
|
1083
|
+
wasBeyondThePointRef.current = false;
|
|
1084
|
+
onRelease(event);
|
|
1085
|
+
},
|
|
1086
|
+
onPointerCancel: event => {
|
|
1087
|
+
rest.onPointerCancel?.(event);
|
|
1088
|
+
if (event.pointerType === 'touch' && snapPoints && activeSnapPointIndex === snapPoints.length - 1) {
|
|
1089
|
+
continuingCanceledTouchRef.current = true;
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
handleOnPointerUp(null);
|
|
1093
|
+
},
|
|
1094
|
+
onPointerOut: event => {
|
|
1095
|
+
rest.onPointerOut?.(event);
|
|
1096
|
+
if (continuingCanceledTouchRef.current) return;
|
|
1097
|
+
handleOnPointerUp(lastKnownPointerEventRef.current);
|
|
1098
|
+
},
|
|
1099
|
+
onTouchMove: event => {
|
|
1100
|
+
rest.onTouchMove?.(event);
|
|
1101
|
+
if (!continuingCanceledTouchRef.current) return;
|
|
1102
|
+
const touch = event.touches[0];
|
|
1103
|
+
if (!touch) return;
|
|
1104
|
+
onTouchDrag({
|
|
1105
|
+
target: event.target,
|
|
1106
|
+
pageX: touch.pageX,
|
|
1107
|
+
pageY: touch.pageY,
|
|
1108
|
+
pointerType: 'touch'
|
|
1109
|
+
}, lastKnownPointerEventRef.current ?? undefined);
|
|
1110
|
+
},
|
|
1111
|
+
onTouchEnd: event => {
|
|
1112
|
+
rest.onTouchEnd?.(event);
|
|
1113
|
+
if (!continuingCanceledTouchRef.current) return;
|
|
1114
|
+
continuingCanceledTouchRef.current = false;
|
|
1115
|
+
pointerStartRef.current = null;
|
|
1116
|
+
wasBeyondThePointRef.current = false;
|
|
1117
|
+
const touch = event.changedTouches[0];
|
|
1118
|
+
onTouchRelease(touch ? {
|
|
1119
|
+
target: event.target,
|
|
1120
|
+
pageX: touch.pageX,
|
|
1121
|
+
pageY: touch.pageY,
|
|
1122
|
+
pointerType: 'touch'
|
|
1123
|
+
} : null, lastKnownPointerEventRef.current ?? undefined);
|
|
1124
|
+
},
|
|
1125
|
+
onTouchCancel: event => {
|
|
1126
|
+
rest.onTouchCancel?.(event);
|
|
1127
|
+
if (!continuingCanceledTouchRef.current) return;
|
|
1128
|
+
continuingCanceledTouchRef.current = false;
|
|
1129
|
+
handleOnPointerUp(null);
|
|
1130
|
+
},
|
|
1131
|
+
onContextMenu: event => {
|
|
1132
|
+
rest.onContextMenu?.(event);
|
|
1133
|
+
if (lastKnownPointerEventRef.current) {
|
|
1134
|
+
handleOnPointerUp(lastKnownPointerEventRef.current);
|
|
1135
|
+
}
|
|
1136
|
+
},
|
|
1137
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
1138
|
+
ref: setAutoSizeNode,
|
|
1139
|
+
"data-vaul-auto-size-wrapper": "",
|
|
1140
|
+
style: autoSizeWrapperStyle,
|
|
1141
|
+
children: children
|
|
1142
|
+
})
|
|
1143
|
+
});
|
|
1144
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
1145
|
+
"data-vaul-detached-wrapper": "",
|
|
1146
|
+
style: wrapperStyle,
|
|
1147
|
+
children: [contentNode, detachedSiblings]
|
|
1148
|
+
});
|
|
1149
|
+
});
|
|
1150
|
+
Content.displayName = 'Drawer.Content';
|
|
1151
|
+
|
|
1152
|
+
// `flow-root` establishes a new block formatting context so the first child's
|
|
1153
|
+
// margin-top (e.g. a grabber) stays inside the wrapper instead of collapsing
|
|
1154
|
+
// out — otherwise `offsetHeight` under-reports and the drawer positions the
|
|
1155
|
+
// wrapper below where the content actually ends.
|
|
1156
|
+
const autoSizeWrapperStyle = {
|
|
1157
|
+
display: 'flow-root'
|
|
1158
|
+
};
|
|
1159
|
+
const LONG_HANDLE_PRESS_TIMEOUT = 250;
|
|
1160
|
+
const DOUBLE_TAP_TIMEOUT = 120;
|
|
1161
|
+
export const Handle = /*#__PURE__*/React.forwardRef(({
|
|
1162
|
+
preventCycle = false,
|
|
1163
|
+
children,
|
|
1164
|
+
...rest
|
|
1165
|
+
}, ref) => {
|
|
1166
|
+
const {
|
|
1167
|
+
closeDrawer,
|
|
1168
|
+
isDragging,
|
|
1169
|
+
snapPoints,
|
|
1170
|
+
activeSnapPoint,
|
|
1171
|
+
setActiveSnapPoint,
|
|
1172
|
+
dismissible,
|
|
1173
|
+
handleOnly,
|
|
1174
|
+
isOpen,
|
|
1175
|
+
onPress,
|
|
1176
|
+
onDrag
|
|
1177
|
+
} = useDrawerContext();
|
|
1178
|
+
const closeTimeoutIdRef = React.useRef(null);
|
|
1179
|
+
const shouldCancelInteractionRef = React.useRef(false);
|
|
1180
|
+
function handleStartCycle() {
|
|
1181
|
+
// Stop if this is the second click of a double click
|
|
1182
|
+
if (shouldCancelInteractionRef.current) {
|
|
1183
|
+
handleCancelInteraction();
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
window.setTimeout(() => {
|
|
1187
|
+
handleCycleSnapPoints();
|
|
1188
|
+
}, DOUBLE_TAP_TIMEOUT);
|
|
1189
|
+
}
|
|
1190
|
+
function handleCycleSnapPoints() {
|
|
1191
|
+
// Prevent accidental taps while resizing drawer
|
|
1192
|
+
if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
|
|
1193
|
+
handleCancelInteraction();
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
// Make sure to clear the timeout id if the user releases the handle before the cancel timeout
|
|
1197
|
+
handleCancelInteraction();
|
|
1198
|
+
if (!snapPoints || snapPoints.length === 0) {
|
|
1199
|
+
if (!dismissible) {
|
|
1200
|
+
closeDrawer();
|
|
1201
|
+
}
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
const isLastSnapPoint = activeSnapPoint === snapPoints[snapPoints.length - 1];
|
|
1205
|
+
if (isLastSnapPoint && dismissible) {
|
|
1206
|
+
closeDrawer();
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
const currentSnapIndex = snapPoints.findIndex(point => point === activeSnapPoint);
|
|
1210
|
+
if (currentSnapIndex === -1) return; // activeSnapPoint not found in snapPoints
|
|
1211
|
+
const nextSnapPoint = snapPoints[currentSnapIndex + 1];
|
|
1212
|
+
if (nextSnapPoint === undefined) return;
|
|
1213
|
+
setActiveSnapPoint(nextSnapPoint);
|
|
1214
|
+
}
|
|
1215
|
+
function handleStartInteraction() {
|
|
1216
|
+
closeTimeoutIdRef.current = window.setTimeout(() => {
|
|
1217
|
+
// Cancel click interaction on a long press
|
|
1218
|
+
shouldCancelInteractionRef.current = true;
|
|
1219
|
+
}, LONG_HANDLE_PRESS_TIMEOUT);
|
|
1220
|
+
}
|
|
1221
|
+
function handleCancelInteraction() {
|
|
1222
|
+
if (closeTimeoutIdRef.current) {
|
|
1223
|
+
window.clearTimeout(closeTimeoutIdRef.current);
|
|
1224
|
+
}
|
|
1225
|
+
shouldCancelInteractionRef.current = false;
|
|
1226
|
+
}
|
|
1227
|
+
return /*#__PURE__*/_jsx("div", {
|
|
1228
|
+
onClick: handleStartCycle,
|
|
1229
|
+
onPointerCancel: handleCancelInteraction,
|
|
1230
|
+
onPointerDown: e => {
|
|
1231
|
+
if (handleOnly) onPress(e);
|
|
1232
|
+
handleStartInteraction();
|
|
1233
|
+
},
|
|
1234
|
+
onPointerMove: e => {
|
|
1235
|
+
if (handleOnly) onDrag(e);
|
|
1236
|
+
}
|
|
1237
|
+
// onPointerUp is already handled by the content component
|
|
1238
|
+
,
|
|
1239
|
+
ref: ref,
|
|
1240
|
+
"data-vaul-drawer-visible": isOpen ? 'true' : 'false',
|
|
1241
|
+
"data-vaul-handle": "",
|
|
1242
|
+
"aria-hidden": "true",
|
|
1243
|
+
...rest,
|
|
1244
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
1245
|
+
"data-vaul-handle-hitarea": "",
|
|
1246
|
+
"aria-hidden": "true",
|
|
1247
|
+
children: children
|
|
1248
|
+
})
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
Handle.displayName = 'Drawer.Handle';
|
|
1252
|
+
export function NestedRoot({
|
|
1253
|
+
onDrag,
|
|
1254
|
+
onOpenChange,
|
|
1255
|
+
open: nestedIsOpen,
|
|
1256
|
+
...rest
|
|
1257
|
+
}) {
|
|
1258
|
+
const {
|
|
1259
|
+
onNestedDrag,
|
|
1260
|
+
onNestedOpenChange,
|
|
1261
|
+
onNestedRelease
|
|
1262
|
+
} = useDrawerContext();
|
|
1263
|
+
if (!onNestedDrag) {
|
|
1264
|
+
throw new Error('Drawer.NestedRoot must be placed in another drawer');
|
|
1265
|
+
}
|
|
1266
|
+
return /*#__PURE__*/_jsx(Root, {
|
|
1267
|
+
nested: true,
|
|
1268
|
+
open: nestedIsOpen,
|
|
1269
|
+
onClose: () => {
|
|
1270
|
+
onNestedOpenChange(false);
|
|
1271
|
+
},
|
|
1272
|
+
onDrag: (e, p) => {
|
|
1273
|
+
onNestedDrag(e, p);
|
|
1274
|
+
onDrag?.(e, p);
|
|
1275
|
+
},
|
|
1276
|
+
onOpenChange: o => {
|
|
1277
|
+
if (o) {
|
|
1278
|
+
onNestedOpenChange(o);
|
|
1279
|
+
}
|
|
1280
|
+
onOpenChange?.(o);
|
|
1281
|
+
},
|
|
1282
|
+
onRelease: onNestedRelease,
|
|
1283
|
+
...rest
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
export function Portal(props) {
|
|
1287
|
+
const context = useDrawerContext();
|
|
1288
|
+
const {
|
|
1289
|
+
container = context.container,
|
|
1290
|
+
...portalProps
|
|
1291
|
+
} = props;
|
|
1292
|
+
return /*#__PURE__*/_jsx(DialogPrimitive.Portal, {
|
|
1293
|
+
container: container,
|
|
1294
|
+
...portalProps
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
export const Drawer = {
|
|
1298
|
+
Root,
|
|
1299
|
+
NestedRoot,
|
|
1300
|
+
Content,
|
|
1301
|
+
Overlay,
|
|
1302
|
+
Trigger: DialogPrimitive.Trigger,
|
|
1303
|
+
Portal,
|
|
1304
|
+
Handle,
|
|
1305
|
+
Close: DialogPrimitive.Close,
|
|
1306
|
+
Title: DialogPrimitive.Title,
|
|
1307
|
+
Description: DialogPrimitive.Description
|
|
1308
|
+
};
|
|
1309
|
+
//# sourceMappingURL=index.js.map
|