@lodev09/react-native-true-sheet 3.11.0-beta.0 → 3.11.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.
@@ -1,28 +1,32 @@
1
1
  'use client';
2
2
 
3
- import * as DialogPrimitive from '@radix-ui/react-dialog';
4
3
  import React from 'react';
4
+
5
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
6
+ import { Presence } from '@radix-ui/react-presence';
7
+
5
8
  import { DrawerContext, useDrawerContext } from './context';
6
9
  import './style.css';
7
- import { usePreventScroll, isInput } from './use-prevent-scroll';
8
- import { useComposedRefs } from './use-composed-refs';
9
- import { useSnapPoints } from './use-snap-points';
10
- import { set, getTranslate, dampenValue, isVertical, reset } from './helpers';
10
+
11
+ import { isIOS, isMobileFirefox } from './browser';
11
12
  import {
12
- TRANSITIONS,
13
- VELOCITY_THRESHOLD,
14
- CLOSE_THRESHOLD,
15
- SCROLL_LOCK_TIMEOUT,
16
13
  BORDER_RADIUS,
14
+ CLOSE_THRESHOLD,
15
+ DRAG_CLASS,
17
16
  NESTED_DISPLACEMENT,
17
+ SCROLL_LOCK_TIMEOUT,
18
+ TRANSITIONS,
19
+ VELOCITY_THRESHOLD,
18
20
  WINDOW_TOP_OFFSET,
19
- DRAG_CLASS,
20
21
  } from './constants';
22
+ import { dampenValue, getTranslate, isVertical, reset, set } from './helpers';
21
23
  import type { DrawerDirection } from './types';
24
+ import { useComposedRefs } from './use-composed-refs';
22
25
  import { useControllableState } from './use-controllable-state';
23
- import { useScaleBackground } from './use-scale-background';
24
26
  import { usePositionFixed } from './use-position-fixed';
25
- import { isIOS, isMobileFirefox } from './browser';
27
+ import { isInput, usePreventScroll } from './use-prevent-scroll';
28
+ import { useScaleBackground } from './use-scale-background';
29
+ import { useSnapPoints } from './use-snap-points';
26
30
 
27
31
  export interface WithFadeFromProps {
28
32
  /**
@@ -236,19 +240,6 @@ export function Root({
236
240
  setTimeout(() => {
237
241
  onAnimationEnd?.(o);
238
242
  }, TRANSITIONS.DURATION * 1000);
239
-
240
- if (o && !modal) {
241
- if (typeof window !== 'undefined') {
242
- window.requestAnimationFrame(() => {
243
- document.body.style.pointerEvents = 'auto';
244
- });
245
- }
246
- }
247
-
248
- if (!o) {
249
- // This will be removed when the exit animation ends (`500ms`)
250
- document.body.style.pointerEvents = 'auto';
251
- }
252
243
  },
253
244
  });
254
245
  const [hasBeenOpened, setHasBeenOpened] = React.useState<boolean>(false);
@@ -563,63 +554,6 @@ export function Root({
563
554
  onPositionChangeRef.current = onPositionChange;
564
555
  });
565
556
 
566
- // Radix's DismissableLayer (modal) sets body pointer-events to "none" so the
567
- // overlay traps clicks. When the active snap is below fadeFromIndex the
568
- // overlay is fully transparent, and we want clicks to reach the content
569
- // behind the drawer — so we restore body interactivity. DismissableLayer
570
- // captures its DOM node via a ref-callback `setNode`, so its body write
571
- // runs one render later than ours on initial open — re-assert on rAF so
572
- // the final write is ours.
573
- React.useEffect(() => {
574
- if (!modal || !snapPoints || fadeFromIndex === undefined) return;
575
- // On close, restore body interactivity. `useControllableState.onChange`
576
- // only fires for internal `setIsOpen` calls — when the parent flips the
577
- // `open` prop imperatively, the reset at line ~201 never runs.
578
- if (!isOpen) {
579
- document.body.style.pointerEvents = 'auto';
580
- return;
581
- }
582
- if (typeof activeSnapPointIndex !== 'number') return;
583
- const isBelowFade = activeSnapPointIndex < fadeFromIndex;
584
- const value = isBelowFade ? 'auto' : 'none';
585
- document.body.style.pointerEvents = value;
586
- const id = window.requestAnimationFrame(() => {
587
- document.body.style.pointerEvents = value;
588
- });
589
-
590
- // React Navigation keeps unfocused screens mounted with `display: none` on
591
- // web, so the drawer never unmounts and neither `isOpen` nor this effect's
592
- // deps change — a lingering `none` body style would then leak to whichever
593
- // screen becomes visible. Observe the drawer: when an ancestor hides it,
594
- // restore `auto`; when it returns, re-apply the desired value.
595
- let observer: IntersectionObserver | null = null;
596
- let rafId = 0;
597
- const startObserving = () => {
598
- const node = drawerRef.current;
599
- if (!node) {
600
- rafId = window.requestAnimationFrame(startObserving);
601
- return;
602
- }
603
- observer = new IntersectionObserver((entries) => {
604
- const entry = entries[entries.length - 1];
605
- if (!entry) return;
606
- document.body.style.pointerEvents = entry.isIntersecting ? value : 'auto';
607
- });
608
- observer.observe(node);
609
- };
610
- rafId = window.requestAnimationFrame(startObserving);
611
-
612
- // Always restore on cleanup so an unmount while the sheet is still open
613
- // doesn't leave the page uninteractive. If the effect re-runs for a
614
- // normal state change, it re-applies the correct value.
615
- return () => {
616
- window.cancelAnimationFrame(id);
617
- window.cancelAnimationFrame(rafId);
618
- observer?.disconnect();
619
- document.body.style.pointerEvents = 'auto';
620
- };
621
- }, [isOpen, modal, snapPoints, fadeFromIndex, activeSnapPointIndex]);
622
-
623
557
  React.useEffect(() => {
624
558
  function onVisualViewportChange() {
625
559
  if (!drawerRef.current || !repositionInputs) return;
@@ -669,7 +603,7 @@ export function Root({
669
603
  }
670
604
 
671
605
  if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
672
- drawerRef.current.style.bottom = `0px`;
606
+ drawerRef.current.style.bottom = '0px';
673
607
  } else {
674
608
  // Negative bottom value would never make sense
675
609
  drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
@@ -888,15 +822,6 @@ export function Root({
888
822
  }
889
823
  }
890
824
 
891
- React.useEffect(() => {
892
- if (!modal) {
893
- // Need to do this manually unfortunately
894
- window.requestAnimationFrame(() => {
895
- document.body.style.pointerEvents = 'auto';
896
- });
897
- }
898
- }, [modal]);
899
-
900
825
  return (
901
826
  <DialogPrimitive.Root
902
827
  defaultOpen={defaultOpen}
@@ -911,7 +836,14 @@ export function Root({
911
836
  setIsOpen(open);
912
837
  }}
913
838
  open={isOpen}
914
- modal={modal}
839
+ // Always non-modal at the Radix level — Radix's modal mode locks
840
+ // body.style.pointerEvents and its restore on layer unmount is buggy
841
+ // (see git history). Vaul's own overlay handles click-trapping; the
842
+ // overlay sets pointer-events: none below fadeFromIndex so clicks
843
+ // pass through to the page (matches native dimmedDetentIndex). Vaul's
844
+ // own `modal` prop still drives overlay rendering and click-outside
845
+ // behavior below.
846
+ modal={false}
915
847
  >
916
848
  <DrawerContext.Provider
917
849
  value={{
@@ -962,7 +894,7 @@ export function Root({
962
894
  export const Overlay = React.forwardRef<
963
895
  HTMLDivElement,
964
896
  React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
965
- >(function ({ style, ...rest }, ref) {
897
+ >(({ style, ...rest }, ref) => {
966
898
  const {
967
899
  overlayRef,
968
900
  snapPoints,
@@ -1007,26 +939,38 @@ export const Overlay = React.forwardRef<
1007
939
  typeof activeSnapPointIndex === 'number' &&
1008
940
  activeSnapPointIndex < fadeFromIndex;
1009
941
 
942
+ // Render our own overlay element instead of `DialogPrimitive.Overlay`:
943
+ // Radix's Overlay returns null when the Dialog is non-modal, and we run
944
+ // Radix as `modal={false}` to keep it from locking body pointer-events.
945
+ // `Presence` keeps the node mounted through the closing animation
946
+ // (`fadeOut`) before unmounting.
1010
947
  return (
1011
- <DialogPrimitive.Overlay
1012
- onMouseUp={onMouseUp}
1013
- ref={composedRef}
1014
- data-vaul-overlay=""
1015
- data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
1016
- data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
1017
- data-vaul-snap-points-overlay={isOpen && shouldFade ? 'true' : 'false'}
1018
- data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
1019
- {...rest}
1020
- style={isBelowFade ? overlayBelowFadeStyle(style) : style}
1021
- />
948
+ <Presence present={isOpen}>
949
+ <div
950
+ onMouseUp={onMouseUp}
951
+ ref={composedRef}
952
+ data-state={isOpen ? 'open' : 'closed'}
953
+ data-vaul-overlay=""
954
+ data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
955
+ data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
956
+ data-vaul-snap-points-overlay={isOpen && shouldFade ? 'true' : 'false'}
957
+ data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
958
+ {...rest}
959
+ style={overlayStyle(style, !!isBelowFade)}
960
+ />
961
+ </Presence>
1022
962
  );
1023
963
  });
1024
964
 
1025
965
  Overlay.displayName = 'Drawer.Overlay';
1026
966
 
1027
- const overlayPointerEventsNone: React.CSSProperties = { pointerEvents: 'none' };
1028
- const overlayBelowFadeStyle = (style: React.CSSProperties | undefined): React.CSSProperties =>
1029
- style ? { ...style, ...overlayPointerEventsNone } : overlayPointerEventsNone;
967
+ const overlayStyle = (
968
+ style: React.CSSProperties | undefined,
969
+ isBelowFade: boolean
970
+ ): React.CSSProperties => ({
971
+ ...style,
972
+ pointerEvents: isBelowFade ? 'none' : 'auto',
973
+ });
1030
974
 
1031
975
  export type ContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
1032
976
  /**
@@ -1037,387 +981,388 @@ export type ContentProps = React.ComponentPropsWithoutRef<typeof DialogPrimitive
1037
981
  detachedSiblings?: React.ReactNode;
1038
982
  };
1039
983
 
1040
- export const Content = React.forwardRef<HTMLDivElement, ContentProps>(function (
1041
- { onPointerDownOutside, style, onOpenAutoFocus, children, detachedSiblings, ...rest },
1042
- ref
1043
- ) {
1044
- const {
1045
- drawerRef,
1046
- onPress,
1047
- onRelease,
1048
- onDrag,
1049
- keyboardIsOpen,
1050
- snapPointsOffset,
1051
- activeSnapPointIndex,
1052
- fadeFromIndex,
1053
- modal,
1054
- isOpen,
1055
- isDragging,
1056
- direction,
1057
- snapPoints,
1058
- container,
1059
- handleOnly,
1060
- shouldAnimate,
1061
- autoFocus,
1062
- onPositionChangeRef,
1063
- setContentHeight,
1064
- detached,
1065
- detachedOffset,
1066
- detachedRadius,
1067
- detachedWrapperStyle: detachedWrapperStyleProp,
1068
- } = useDrawerContext();
1069
- const hasAutoSnapPoint = React.useMemo(
1070
- () => !!snapPoints?.some((p) => p === 'auto'),
1071
- [snapPoints]
1072
- );
1073
-
1074
- // When 'auto' is used as a snap point, we need the natural content height.
1075
- // The drawer itself may be styled to a fixed viewport height, so we measure
1076
- // an inner wrapper instead. Ref callback starts the observer as soon as the
1077
- // node mounts (Radix Presence defers the portal mount past useEffect).
1078
- const autoRoRef = React.useRef<ResizeObserver | null>(null);
1079
- const setAutoSizeNode = React.useCallback(
1080
- (node: HTMLDivElement | null) => {
1081
- autoRoRef.current?.disconnect();
1082
- if (!node || !hasAutoSnapPoint) {
1083
- autoRoRef.current = null;
1084
- return;
1085
- }
1086
- const measure = () => setContentHeight(node.offsetHeight);
1087
- measure();
1088
- const ro = new ResizeObserver(measure);
1089
- ro.observe(node);
1090
- autoRoRef.current = ro;
1091
- },
1092
- [hasAutoSnapPoint, setContentHeight]
1093
- );
1094
-
1095
- const isBelowFade =
1096
- snapPoints !== undefined &&
1097
- snapPoints !== null &&
1098
- fadeFromIndex !== undefined &&
1099
- typeof activeSnapPointIndex === 'number' &&
1100
- activeSnapPointIndex < fadeFromIndex;
1101
- // Needed to use transition instead of animations
1102
- const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
1103
- const composedRef = useComposedRefs(ref, drawerRef);
1104
- const pointerStartRef = React.useRef<{ x: number; y: number } | null>(null);
1105
- const lastKnownPointerEventRef = React.useRef<React.PointerEvent<HTMLDivElement> | null>(null);
1106
- const wasBeyondThePointRef = React.useRef(false);
1107
- const hasSnapPoints = snapPoints && snapPoints.length > 0;
1108
- useScaleBackground();
1109
-
1110
- const isDeltaInDirection = (
1111
- delta: { x: number; y: number },
1112
- dir: DrawerDirection,
1113
- threshold = 0
1114
- ) => {
1115
- if (wasBeyondThePointRef.current) return true;
1116
-
1117
- const deltaY = Math.abs(delta.y);
1118
- const deltaX = Math.abs(delta.x);
1119
- const isDeltaX = deltaX > deltaY;
1120
- const dFactor = ['bottom', 'right'].includes(dir) ? 1 : -1;
1121
-
1122
- if (dir === 'left' || dir === 'right') {
1123
- const isReverseDirection = delta.x * dFactor < 0;
1124
- if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
1125
- return isDeltaX;
1126
- }
1127
- } else {
1128
- const isReverseDirection = delta.y * dFactor < 0;
1129
- if (!isReverseDirection && deltaY >= 0 && deltaY <= threshold) {
1130
- return !isDeltaX;
1131
- }
1132
- }
1133
-
1134
- wasBeyondThePointRef.current = true;
1135
- return true;
1136
- };
1137
-
1138
- React.useEffect(() => {
1139
- if (hasSnapPoints) {
1140
- window.requestAnimationFrame(() => {
1141
- setDelayedSnapPoints(true);
1142
- });
1143
- }
1144
- }, []);
1145
-
1146
- // Event-driven position tracking. We only tick RAF while the drawer is
1147
- // actually moving (drag / CSS transition / CSS animation). When it's idle at
1148
- // a snap, no frames run at all.
1149
- const positionTrackingRef = React.useRef<{
1150
- rafId: number | null;
1151
- movingCount: number;
1152
- lastPosition: number;
1153
- start: () => void;
1154
- stop: () => void;
1155
- } | null>(null);
984
+ export const Content = React.forwardRef<HTMLDivElement, ContentProps>(
985
+ ({ onPointerDownOutside, style, onOpenAutoFocus, children, detachedSiblings, ...rest }, ref) => {
986
+ const {
987
+ drawerRef,
988
+ onPress,
989
+ onRelease,
990
+ onDrag,
991
+ keyboardIsOpen,
992
+ snapPointsOffset,
993
+ activeSnapPointIndex,
994
+ fadeFromIndex,
995
+ modal,
996
+ isOpen,
997
+ isDragging,
998
+ direction,
999
+ snapPoints,
1000
+ container,
1001
+ handleOnly,
1002
+ shouldAnimate,
1003
+ autoFocus,
1004
+ onPositionChangeRef,
1005
+ setContentHeight,
1006
+ detached,
1007
+ detachedOffset,
1008
+ detachedRadius,
1009
+ detachedWrapperStyle: detachedWrapperStyleProp,
1010
+ } = useDrawerContext();
1011
+ const hasAutoSnapPoint = React.useMemo(
1012
+ () => !!snapPoints?.some((p) => p === 'auto'),
1013
+ [snapPoints]
1014
+ );
1156
1015
 
1157
- React.useEffect(() => {
1158
- const drawer = drawerRef.current;
1159
- if (!drawer) return;
1160
-
1161
- const state = {
1162
- rafId: null as number | null,
1163
- movingCount: 0,
1164
- lastPosition: Number.NaN,
1165
- start: () => {},
1166
- stop: () => {},
1167
- };
1016
+ // When 'auto' is used as a snap point, we need the natural content height.
1017
+ // The drawer itself may be styled to a fixed viewport height, so we measure
1018
+ // an inner wrapper instead. Ref callback starts the observer as soon as the
1019
+ // node mounts (Radix Presence defers the portal mount past useEffect).
1020
+ const autoRoRef = React.useRef<ResizeObserver | null>(null);
1021
+ const setAutoSizeNode = React.useCallback(
1022
+ (node: HTMLDivElement | null) => {
1023
+ autoRoRef.current?.disconnect();
1024
+ if (!node || !hasAutoSnapPoint) {
1025
+ autoRoRef.current = null;
1026
+ return;
1027
+ }
1028
+ const measure = () => setContentHeight(node.offsetHeight);
1029
+ measure();
1030
+ const ro = new ResizeObserver(measure);
1031
+ ro.observe(node);
1032
+ autoRoRef.current = ro;
1033
+ },
1034
+ [hasAutoSnapPoint, setContentHeight]
1035
+ );
1168
1036
 
1169
- const emit = () => {
1170
- const cb = onPositionChangeRef.current;
1171
- if (!cb) return;
1172
- const position = drawer.getBoundingClientRect().top;
1173
- if (position !== state.lastPosition) {
1174
- state.lastPosition = position;
1175
- cb(position);
1037
+ const isBelowFade =
1038
+ snapPoints !== undefined &&
1039
+ snapPoints !== null &&
1040
+ fadeFromIndex !== undefined &&
1041
+ typeof activeSnapPointIndex === 'number' &&
1042
+ activeSnapPointIndex < fadeFromIndex;
1043
+ // Needed to use transition instead of animations
1044
+ const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
1045
+ const composedRef = useComposedRefs(ref, drawerRef);
1046
+ const pointerStartRef = React.useRef<{ x: number; y: number } | null>(null);
1047
+ const lastKnownPointerEventRef = React.useRef<React.PointerEvent<HTMLDivElement> | null>(null);
1048
+ const wasBeyondThePointRef = React.useRef(false);
1049
+ const hasSnapPoints = snapPoints && snapPoints.length > 0;
1050
+ useScaleBackground();
1051
+
1052
+ const isDeltaInDirection = (
1053
+ delta: { x: number; y: number },
1054
+ dir: DrawerDirection,
1055
+ threshold = 0
1056
+ ) => {
1057
+ if (wasBeyondThePointRef.current) return true;
1058
+
1059
+ const deltaY = Math.abs(delta.y);
1060
+ const deltaX = Math.abs(delta.x);
1061
+ const isDeltaX = deltaX > deltaY;
1062
+ const dFactor = ['bottom', 'right'].includes(dir) ? 1 : -1;
1063
+
1064
+ if (dir === 'left' || dir === 'right') {
1065
+ const isReverseDirection = delta.x * dFactor < 0;
1066
+ if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
1067
+ return isDeltaX;
1068
+ }
1069
+ } else {
1070
+ const isReverseDirection = delta.y * dFactor < 0;
1071
+ if (!isReverseDirection && deltaY >= 0 && deltaY <= threshold) {
1072
+ return !isDeltaX;
1073
+ }
1176
1074
  }
1177
- };
1178
1075
 
1179
- const tick = () => {
1180
- emit();
1181
- state.rafId = state.movingCount > 0 ? window.requestAnimationFrame(tick) : null;
1076
+ wasBeyondThePointRef.current = true;
1077
+ return true;
1182
1078
  };
1183
1079
 
1184
- state.start = () => {
1185
- state.movingCount += 1;
1186
- if (state.rafId === null) {
1187
- state.rafId = window.requestAnimationFrame(tick);
1080
+ React.useEffect(() => {
1081
+ if (hasSnapPoints) {
1082
+ window.requestAnimationFrame(() => {
1083
+ setDelayedSnapPoints(true);
1084
+ });
1188
1085
  }
1189
- };
1190
-
1191
- state.stop = () => {
1192
- state.movingCount = Math.max(0, state.movingCount - 1);
1193
- // RAF loop will exit on its next tick; emit the settled position now.
1194
- if (state.movingCount === 0) emit();
1195
- };
1196
-
1197
- const wrapper = drawer.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1198
-
1199
- // Listen on the wrapper too: drag-overshoot snap-back animates the wrapper
1200
- // alone when the drawer's target is unchanged (e.g. snapping back to the
1201
- // same detent). Without this, position goes stale mid-animation because
1202
- // the drawer's `transitionrun` never fires.
1203
- const onTransitionRun = (e: TransitionEvent) => {
1204
- if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1205
- state.start();
1206
- };
1207
- const onTransitionDone = (e: TransitionEvent) => {
1208
- if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1209
- state.stop();
1210
- };
1211
- const onAnimationStart = (e: AnimationEvent) => {
1212
- if (e.target === drawer || e.target === wrapper) state.start();
1213
- };
1214
- const onAnimationDone = (e: AnimationEvent) => {
1215
- if (e.target === drawer || e.target === wrapper) state.stop();
1216
- };
1217
-
1218
- drawer.addEventListener('transitionrun', onTransitionRun);
1219
- drawer.addEventListener('transitionend', onTransitionDone);
1220
- drawer.addEventListener('transitioncancel', onTransitionDone);
1221
- drawer.addEventListener('animationstart', onAnimationStart);
1222
- drawer.addEventListener('animationend', onAnimationDone);
1223
- drawer.addEventListener('animationcancel', onAnimationDone);
1224
- wrapper?.addEventListener('transitionrun', onTransitionRun);
1225
- wrapper?.addEventListener('transitionend', onTransitionDone);
1226
- wrapper?.addEventListener('transitioncancel', onTransitionDone);
1086
+ }, []);
1087
+
1088
+ // Event-driven position tracking. We only tick RAF while the drawer is
1089
+ // actually moving (drag / CSS transition / CSS animation). When it's idle at
1090
+ // a snap, no frames run at all.
1091
+ const positionTrackingRef = React.useRef<{
1092
+ rafId: number | null;
1093
+ movingCount: number;
1094
+ lastPosition: number;
1095
+ start: () => void;
1096
+ stop: () => void;
1097
+ } | null>(null);
1098
+
1099
+ React.useEffect(() => {
1100
+ const drawer = drawerRef.current;
1101
+ if (!drawer) return;
1102
+
1103
+ const state = {
1104
+ rafId: null as number | null,
1105
+ movingCount: 0,
1106
+ lastPosition: Number.NaN,
1107
+ start: () => {},
1108
+ stop: () => {},
1109
+ };
1110
+
1111
+ const emit = () => {
1112
+ const cb = onPositionChangeRef.current;
1113
+ if (!cb) return;
1114
+ const position = drawer.getBoundingClientRect().top;
1115
+ if (position !== state.lastPosition) {
1116
+ state.lastPosition = position;
1117
+ cb(position);
1118
+ }
1119
+ };
1227
1120
 
1228
- positionTrackingRef.current = state;
1229
- emit();
1121
+ const tick = () => {
1122
+ emit();
1123
+ state.rafId = state.movingCount > 0 ? window.requestAnimationFrame(tick) : null;
1124
+ };
1230
1125
 
1231
- return () => {
1232
- drawer.removeEventListener('transitionrun', onTransitionRun);
1233
- drawer.removeEventListener('transitionend', onTransitionDone);
1234
- drawer.removeEventListener('transitioncancel', onTransitionDone);
1235
- drawer.removeEventListener('animationstart', onAnimationStart);
1236
- drawer.removeEventListener('animationend', onAnimationDone);
1237
- drawer.removeEventListener('animationcancel', onAnimationDone);
1238
- wrapper?.removeEventListener('transitionrun', onTransitionRun);
1239
- wrapper?.removeEventListener('transitionend', onTransitionDone);
1240
- wrapper?.removeEventListener('transitioncancel', onTransitionDone);
1241
- if (state.rafId !== null) window.cancelAnimationFrame(state.rafId);
1242
- positionTrackingRef.current = null;
1243
- };
1244
- }, []);
1126
+ state.start = () => {
1127
+ state.movingCount += 1;
1128
+ if (state.rafId === null) {
1129
+ state.rafId = window.requestAnimationFrame(tick);
1130
+ }
1131
+ };
1132
+
1133
+ state.stop = () => {
1134
+ state.movingCount = Math.max(0, state.movingCount - 1);
1135
+ // RAF loop will exit on its next tick; emit the settled position now.
1136
+ if (state.movingCount === 0) emit();
1137
+ };
1138
+
1139
+ const wrapper = drawer.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1140
+
1141
+ // Listen on the wrapper too: drag-overshoot snap-back animates the wrapper
1142
+ // alone when the drawer's target is unchanged (e.g. snapping back to the
1143
+ // same detent). Without this, position goes stale mid-animation because
1144
+ // the drawer's `transitionrun` never fires.
1145
+ const onTransitionRun = (e: TransitionEvent) => {
1146
+ if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1147
+ state.start();
1148
+ };
1149
+ const onTransitionDone = (e: TransitionEvent) => {
1150
+ if ((e.target === drawer || e.target === wrapper) && e.propertyName === 'transform')
1151
+ state.stop();
1152
+ };
1153
+ const onAnimationStart = (e: AnimationEvent) => {
1154
+ if (e.target === drawer || e.target === wrapper) state.start();
1155
+ };
1156
+ const onAnimationDone = (e: AnimationEvent) => {
1157
+ if (e.target === drawer || e.target === wrapper) state.stop();
1158
+ };
1159
+
1160
+ drawer.addEventListener('transitionrun', onTransitionRun);
1161
+ drawer.addEventListener('transitionend', onTransitionDone);
1162
+ drawer.addEventListener('transitioncancel', onTransitionDone);
1163
+ drawer.addEventListener('animationstart', onAnimationStart);
1164
+ drawer.addEventListener('animationend', onAnimationDone);
1165
+ drawer.addEventListener('animationcancel', onAnimationDone);
1166
+ wrapper?.addEventListener('transitionrun', onTransitionRun);
1167
+ wrapper?.addEventListener('transitionend', onTransitionDone);
1168
+ wrapper?.addEventListener('transitioncancel', onTransitionDone);
1169
+
1170
+ positionTrackingRef.current = state;
1171
+ emit();
1245
1172
 
1246
- React.useEffect(() => {
1247
- const state = positionTrackingRef.current;
1248
- if (!state) return;
1249
- if (isDragging) state.start();
1250
- else state.stop();
1251
- }, [isDragging]);
1252
-
1253
- function handleOnPointerUp(event: React.PointerEvent<HTMLDivElement> | null) {
1254
- pointerStartRef.current = null;
1255
- wasBeyondThePointRef.current = false;
1256
- onRelease(event);
1257
- }
1173
+ return () => {
1174
+ drawer.removeEventListener('transitionrun', onTransitionRun);
1175
+ drawer.removeEventListener('transitionend', onTransitionDone);
1176
+ drawer.removeEventListener('transitioncancel', onTransitionDone);
1177
+ drawer.removeEventListener('animationstart', onAnimationStart);
1178
+ drawer.removeEventListener('animationend', onAnimationDone);
1179
+ drawer.removeEventListener('animationcancel', onAnimationDone);
1180
+ wrapper?.removeEventListener('transitionrun', onTransitionRun);
1181
+ wrapper?.removeEventListener('transitionend', onTransitionDone);
1182
+ wrapper?.removeEventListener('transitioncancel', onTransitionDone);
1183
+ if (state.rafId !== null) window.cancelAnimationFrame(state.rafId);
1184
+ positionTrackingRef.current = null;
1185
+ };
1186
+ }, []);
1187
+
1188
+ React.useEffect(() => {
1189
+ const state = positionTrackingRef.current;
1190
+ if (!state) return;
1191
+ if (isDragging) state.start();
1192
+ else state.stop();
1193
+ }, [isDragging]);
1194
+
1195
+ function handleOnPointerUp(event: React.PointerEvent<HTMLDivElement> | null) {
1196
+ pointerStartRef.current = null;
1197
+ wasBeyondThePointRef.current = false;
1198
+ onRelease(event);
1199
+ }
1258
1200
 
1259
- // The drawer always sits inside a fixed clip wrapper. `contain: paint`
1260
- // establishes the wrapper as the containing block so the drawer's own
1261
- // `position: fixed` is constrained here, and `overflow: hidden` keeps any
1262
- // overshoot out of the viewport. When `detached` the wrapper also floats
1263
- // with a bottom gap and rounded bottom corners; otherwise it sits flush.
1264
- // Transform/transition are managed imperatively (via drag overshoot and the
1265
- // dismiss effect) so React doesn't skip DOM writes for values it thinks it
1266
- // already owns.
1267
- const wrapperStyle = React.useMemo<React.CSSProperties>(
1268
- () => ({
1269
- position: 'fixed',
1270
- top: 0,
1271
- left: 0,
1272
- right: 0,
1273
- bottom: detached ? detachedOffset : 0,
1274
- overflow: 'hidden',
1275
- contain: 'paint',
1276
- pointerEvents: 'none',
1277
- borderBottomLeftRadius: detached ? detachedRadius : 0,
1278
- borderBottomRightRadius: detached ? detachedRadius : 0,
1279
- ...detachedWrapperStyleProp,
1280
- }),
1281
- [detached, detachedOffset, detachedRadius, detachedWrapperStyleProp]
1282
- );
1201
+ // The drawer always sits inside a fixed clip wrapper. `contain: paint`
1202
+ // establishes the wrapper as the containing block so the drawer's own
1203
+ // `position: fixed` is constrained here, and `overflow: hidden` keeps any
1204
+ // overshoot out of the viewport. When `detached` the wrapper also floats
1205
+ // with a bottom gap and rounded bottom corners; otherwise it sits flush.
1206
+ // Transform/transition are managed imperatively (via drag overshoot and the
1207
+ // dismiss effect) so React doesn't skip DOM writes for values it thinks it
1208
+ // already owns.
1209
+ const wrapperStyle = React.useMemo<React.CSSProperties>(
1210
+ () => ({
1211
+ position: 'fixed',
1212
+ top: 0,
1213
+ left: 0,
1214
+ right: 0,
1215
+ bottom: detached ? detachedOffset : 0,
1216
+ overflow: 'hidden',
1217
+ contain: 'paint',
1218
+ pointerEvents: 'none',
1219
+ borderBottomLeftRadius: detached ? detachedRadius : 0,
1220
+ borderBottomRightRadius: detached ? detachedRadius : 0,
1221
+ ...detachedWrapperStyleProp,
1222
+ }),
1223
+ [detached, detachedOffset, detachedRadius, detachedWrapperStyleProp]
1224
+ );
1283
1225
 
1284
- // Translate the wrapper off-screen on dismiss so the whole card slides out
1285
- // as one. The reset-then-target pattern on open forces the browser to
1286
- // record a starting value so the transition actually animates.
1287
- const wasOpenRef = React.useRef(isOpen);
1288
- React.useEffect(() => {
1289
- if (!drawerRef.current) {
1290
- wasOpenRef.current = isOpen;
1291
- return;
1292
- }
1293
- const wrapper = drawerRef.current.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1294
- if (wrapper) {
1295
- const transition = `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
1296
- const viewportH = typeof window !== 'undefined' ? window.innerHeight : 0;
1297
- if (!isOpen && wasOpenRef.current) {
1298
- wrapper.style.transition = transition;
1299
- wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1300
- } else if (isOpen && !wasOpenRef.current) {
1301
- wrapper.style.transition = 'none';
1302
- wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1303
- // eslint-disable-next-line no-void
1304
- void wrapper.offsetHeight;
1305
- wrapper.style.transition = transition;
1306
- wrapper.style.transform = 'translate3d(0, 0, 0)';
1307
- } else if (isOpen && !wrapper.style.transform) {
1308
- // Fresh mount with open=true — ensure the wrapper starts at rest.
1309
- wrapper.style.transition = transition;
1310
- wrapper.style.transform = 'translate3d(0, 0, 0)';
1226
+ // Translate the wrapper off-screen on dismiss so the whole card slides out
1227
+ // as one. The reset-then-target pattern on open forces the browser to
1228
+ // record a starting value so the transition actually animates.
1229
+ const wasOpenRef = React.useRef(isOpen);
1230
+ React.useEffect(() => {
1231
+ if (!drawerRef.current) {
1232
+ wasOpenRef.current = isOpen;
1233
+ return;
1311
1234
  }
1312
- }
1313
- wasOpenRef.current = isOpen;
1314
- }, [isOpen, detached, drawerRef]);
1315
-
1316
- const contentNode = (
1317
- <DialogPrimitive.Content
1318
- data-vaul-drawer-direction={direction}
1319
- data-vaul-drawer=""
1320
- data-vaul-detached={detached ? 'true' : 'false'}
1321
- data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
1322
- data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
1323
- data-vaul-custom-container={container ? 'true' : 'false'}
1324
- data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
1325
- {...rest}
1326
- ref={composedRef}
1327
- style={
1328
- snapPointsOffset && snapPointsOffset.length > 0
1329
- ? ({
1330
- '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]!}px`,
1331
- ...style,
1332
- 'pointerEvents': 'auto',
1333
- } as React.CSSProperties)
1334
- : ({ ...style, pointerEvents: 'auto' } as React.CSSProperties)
1235
+ const wrapper = drawerRef.current.closest<HTMLElement>('[data-vaul-detached-wrapper]');
1236
+ if (wrapper) {
1237
+ const transition = `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`;
1238
+ const viewportH = typeof window !== 'undefined' ? window.innerHeight : 0;
1239
+ if (!isOpen && wasOpenRef.current) {
1240
+ wrapper.style.transition = transition;
1241
+ wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1242
+ } else if (isOpen && !wasOpenRef.current) {
1243
+ wrapper.style.transition = 'none';
1244
+ wrapper.style.transform = `translate3d(0, ${viewportH}px, 0)`;
1245
+ // eslint-disable-next-line no-void
1246
+ void wrapper.offsetHeight;
1247
+ wrapper.style.transition = transition;
1248
+ wrapper.style.transform = 'translate3d(0, 0, 0)';
1249
+ } else if (isOpen && !wrapper.style.transform) {
1250
+ // Fresh mount with open=true — ensure the wrapper starts at rest.
1251
+ wrapper.style.transition = transition;
1252
+ wrapper.style.transform = 'translate3d(0, 0, 0)';
1253
+ }
1335
1254
  }
1336
- onPointerDown={(event) => {
1337
- if (handleOnly) return;
1338
- rest.onPointerDown?.(event);
1339
- pointerStartRef.current = { x: event.pageX, y: event.pageY };
1340
- onPress(event);
1341
- }}
1342
- onOpenAutoFocus={(e) => {
1343
- onOpenAutoFocus?.(e);
1344
-
1345
- if (!autoFocus) {
1346
- e.preventDefault();
1255
+ wasOpenRef.current = isOpen;
1256
+ }, [isOpen, detached, drawerRef]);
1257
+
1258
+ const contentNode = (
1259
+ <DialogPrimitive.Content
1260
+ data-vaul-drawer-direction={direction}
1261
+ data-vaul-drawer=""
1262
+ data-vaul-detached={detached ? 'true' : 'false'}
1263
+ data-vaul-delayed-snap-points={delayedSnapPoints ? 'true' : 'false'}
1264
+ data-vaul-snap-points={isOpen && hasSnapPoints ? 'true' : 'false'}
1265
+ data-vaul-custom-container={container ? 'true' : 'false'}
1266
+ data-vaul-animate={shouldAnimate?.current ? 'true' : 'false'}
1267
+ {...rest}
1268
+ ref={composedRef}
1269
+ style={
1270
+ snapPointsOffset && snapPointsOffset.length > 0
1271
+ ? ({
1272
+ '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex ?? 0]!}px`,
1273
+ ...style,
1274
+ 'pointerEvents': 'auto',
1275
+ } as React.CSSProperties)
1276
+ : ({ ...style, pointerEvents: 'auto' } as React.CSSProperties)
1347
1277
  }
1348
- }}
1349
- onPointerDownOutside={(e) => {
1350
- onPointerDownOutside?.(e);
1278
+ onPointerDown={(event) => {
1279
+ if (handleOnly) return;
1280
+ rest.onPointerDown?.(event);
1281
+ pointerStartRef.current = { x: event.pageX, y: event.pageY };
1282
+ onPress(event);
1283
+ }}
1284
+ onOpenAutoFocus={(e) => {
1285
+ onOpenAutoFocus?.(e);
1351
1286
 
1352
- if (!modal || e.defaultPrevented || isBelowFade) {
1353
- e.preventDefault();
1354
- return;
1355
- }
1287
+ if (!autoFocus) {
1288
+ e.preventDefault();
1289
+ }
1290
+ }}
1291
+ onPointerDownOutside={(e) => {
1292
+ onPointerDownOutside?.(e);
1356
1293
 
1357
- if (keyboardIsOpen.current) {
1358
- keyboardIsOpen.current = false;
1359
- }
1360
- }}
1361
- onFocusOutside={(e) => {
1362
- if (!modal || isBelowFade) {
1294
+ if (!modal || e.defaultPrevented || isBelowFade) {
1295
+ e.preventDefault();
1296
+ return;
1297
+ }
1298
+
1299
+ if (keyboardIsOpen.current) {
1300
+ keyboardIsOpen.current = false;
1301
+ }
1302
+ }}
1303
+ onFocusOutside={(e) => {
1304
+ // Never auto-dismiss the sheet on focus shifts. Without Radix's
1305
+ // FocusScope trap (we run modal={false}), this fires whenever
1306
+ // focus naturally leaves the drawer — e.g. React Navigation's
1307
+ // web driver hides the previous screen via display:none, which
1308
+ // moves focus off the trigger and dismisses the sheet.
1363
1309
  e.preventDefault();
1364
- return;
1365
- }
1366
- }}
1367
- onPointerMove={(event) => {
1368
- lastKnownPointerEventRef.current = event;
1369
- if (handleOnly) return;
1370
- rest.onPointerMove?.(event);
1371
- if (!pointerStartRef.current) return;
1372
- const yPosition = event.pageY - pointerStartRef.current.y;
1373
- const xPosition = event.pageX - pointerStartRef.current.x;
1374
-
1375
- const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
1376
- const delta = { x: xPosition, y: yPosition };
1377
-
1378
- const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1379
- if (isAllowedToSwipe) onDrag(event);
1380
- else if (
1381
- Math.abs(xPosition) > swipeStartThreshold ||
1382
- Math.abs(yPosition) > swipeStartThreshold
1383
- ) {
1310
+ }}
1311
+ onPointerMove={(event) => {
1312
+ lastKnownPointerEventRef.current = event;
1313
+ if (handleOnly) return;
1314
+ rest.onPointerMove?.(event);
1315
+ if (!pointerStartRef.current) return;
1316
+ const yPosition = event.pageY - pointerStartRef.current.y;
1317
+ const xPosition = event.pageX - pointerStartRef.current.x;
1318
+
1319
+ const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
1320
+ const delta = { x: xPosition, y: yPosition };
1321
+
1322
+ const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1323
+ if (isAllowedToSwipe) onDrag(event);
1324
+ else if (
1325
+ Math.abs(xPosition) > swipeStartThreshold ||
1326
+ Math.abs(yPosition) > swipeStartThreshold
1327
+ ) {
1328
+ pointerStartRef.current = null;
1329
+ }
1330
+ }}
1331
+ onPointerUp={(event) => {
1332
+ rest.onPointerUp?.(event);
1384
1333
  pointerStartRef.current = null;
1385
- }
1386
- }}
1387
- onPointerUp={(event) => {
1388
- rest.onPointerUp?.(event);
1389
- pointerStartRef.current = null;
1390
- wasBeyondThePointRef.current = false;
1391
- onRelease(event);
1392
- }}
1393
- onPointerOut={(event) => {
1394
- rest.onPointerOut?.(event);
1395
- handleOnPointerUp(lastKnownPointerEventRef.current);
1396
- }}
1397
- onContextMenu={(event) => {
1398
- rest.onContextMenu?.(event);
1399
- if (lastKnownPointerEventRef.current) {
1334
+ wasBeyondThePointRef.current = false;
1335
+ onRelease(event);
1336
+ }}
1337
+ onPointerOut={(event) => {
1338
+ rest.onPointerOut?.(event);
1400
1339
  handleOnPointerUp(lastKnownPointerEventRef.current);
1401
- }
1402
- }}
1403
- >
1404
- {hasAutoSnapPoint ? (
1405
- <div ref={setAutoSizeNode} data-vaul-auto-size-wrapper="" style={autoSizeWrapperStyle}>
1406
- {children}
1407
- </div>
1408
- ) : (
1409
- children
1410
- )}
1411
- </DialogPrimitive.Content>
1412
- );
1340
+ }}
1341
+ onContextMenu={(event) => {
1342
+ rest.onContextMenu?.(event);
1343
+ if (lastKnownPointerEventRef.current) {
1344
+ handleOnPointerUp(lastKnownPointerEventRef.current);
1345
+ }
1346
+ }}
1347
+ >
1348
+ {hasAutoSnapPoint ? (
1349
+ <div ref={setAutoSizeNode} data-vaul-auto-size-wrapper="" style={autoSizeWrapperStyle}>
1350
+ {children}
1351
+ </div>
1352
+ ) : (
1353
+ children
1354
+ )}
1355
+ </DialogPrimitive.Content>
1356
+ );
1413
1357
 
1414
- return (
1415
- <div data-vaul-detached-wrapper="" style={wrapperStyle}>
1416
- {contentNode}
1417
- {detachedSiblings}
1418
- </div>
1419
- );
1420
- });
1358
+ return (
1359
+ <div data-vaul-detached-wrapper="" style={wrapperStyle}>
1360
+ {contentNode}
1361
+ {detachedSiblings}
1362
+ </div>
1363
+ );
1364
+ }
1365
+ );
1421
1366
 
1422
1367
  Content.displayName = 'Drawer.Content';
1423
1368
 
@@ -1434,106 +1379,105 @@ export type HandleProps = React.ComponentPropsWithoutRef<'div'> & {
1434
1379
  const LONG_HANDLE_PRESS_TIMEOUT = 250;
1435
1380
  const DOUBLE_TAP_TIMEOUT = 120;
1436
1381
 
1437
- export const Handle = React.forwardRef<HTMLDivElement, HandleProps>(function (
1438
- { preventCycle = false, children, ...rest },
1439
- ref
1440
- ) {
1441
- const {
1442
- closeDrawer,
1443
- isDragging,
1444
- snapPoints,
1445
- activeSnapPoint,
1446
- setActiveSnapPoint,
1447
- dismissible,
1448
- handleOnly,
1449
- isOpen,
1450
- onPress,
1451
- onDrag,
1452
- } = useDrawerContext();
1453
-
1454
- const closeTimeoutIdRef = React.useRef<number | null>(null);
1455
- const shouldCancelInteractionRef = React.useRef(false);
1456
-
1457
- function handleStartCycle() {
1458
- // Stop if this is the second click of a double click
1459
- if (shouldCancelInteractionRef.current) {
1460
- handleCancelInteraction();
1461
- return;
1382
+ export const Handle = React.forwardRef<HTMLDivElement, HandleProps>(
1383
+ ({ preventCycle = false, children, ...rest }, ref) => {
1384
+ const {
1385
+ closeDrawer,
1386
+ isDragging,
1387
+ snapPoints,
1388
+ activeSnapPoint,
1389
+ setActiveSnapPoint,
1390
+ dismissible,
1391
+ handleOnly,
1392
+ isOpen,
1393
+ onPress,
1394
+ onDrag,
1395
+ } = useDrawerContext();
1396
+
1397
+ const closeTimeoutIdRef = React.useRef<number | null>(null);
1398
+ const shouldCancelInteractionRef = React.useRef(false);
1399
+
1400
+ function handleStartCycle() {
1401
+ // Stop if this is the second click of a double click
1402
+ if (shouldCancelInteractionRef.current) {
1403
+ handleCancelInteraction();
1404
+ return;
1405
+ }
1406
+ window.setTimeout(() => {
1407
+ handleCycleSnapPoints();
1408
+ }, DOUBLE_TAP_TIMEOUT);
1462
1409
  }
1463
- window.setTimeout(() => {
1464
- handleCycleSnapPoints();
1465
- }, DOUBLE_TAP_TIMEOUT);
1466
- }
1467
1410
 
1468
- function handleCycleSnapPoints() {
1469
- // Prevent accidental taps while resizing drawer
1470
- if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
1411
+ function handleCycleSnapPoints() {
1412
+ // Prevent accidental taps while resizing drawer
1413
+ if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
1414
+ handleCancelInteraction();
1415
+ return;
1416
+ }
1417
+ // Make sure to clear the timeout id if the user releases the handle before the cancel timeout
1471
1418
  handleCancelInteraction();
1472
- return;
1473
- }
1474
- // Make sure to clear the timeout id if the user releases the handle before the cancel timeout
1475
- handleCancelInteraction();
1476
1419
 
1477
- if (!snapPoints || snapPoints.length === 0) {
1478
- if (!dismissible) {
1479
- closeDrawer();
1420
+ if (!snapPoints || snapPoints.length === 0) {
1421
+ if (!dismissible) {
1422
+ closeDrawer();
1423
+ }
1424
+ return;
1480
1425
  }
1481
- return;
1482
- }
1483
1426
 
1484
- const isLastSnapPoint = activeSnapPoint === snapPoints[snapPoints.length - 1];
1427
+ const isLastSnapPoint = activeSnapPoint === snapPoints[snapPoints.length - 1];
1485
1428
 
1486
- if (isLastSnapPoint && dismissible) {
1487
- closeDrawer();
1488
- return;
1489
- }
1429
+ if (isLastSnapPoint && dismissible) {
1430
+ closeDrawer();
1431
+ return;
1432
+ }
1490
1433
 
1491
- const currentSnapIndex = snapPoints.findIndex((point) => point === activeSnapPoint);
1492
- if (currentSnapIndex === -1) return; // activeSnapPoint not found in snapPoints
1493
- const nextSnapPoint = snapPoints[currentSnapIndex + 1];
1494
- if (nextSnapPoint === undefined) return;
1495
- setActiveSnapPoint(nextSnapPoint);
1496
- }
1434
+ const currentSnapIndex = snapPoints.findIndex((point) => point === activeSnapPoint);
1435
+ if (currentSnapIndex === -1) return; // activeSnapPoint not found in snapPoints
1436
+ const nextSnapPoint = snapPoints[currentSnapIndex + 1];
1437
+ if (nextSnapPoint === undefined) return;
1438
+ setActiveSnapPoint(nextSnapPoint);
1439
+ }
1497
1440
 
1498
- function handleStartInteraction() {
1499
- closeTimeoutIdRef.current = window.setTimeout(() => {
1500
- // Cancel click interaction on a long press
1501
- shouldCancelInteractionRef.current = true;
1502
- }, LONG_HANDLE_PRESS_TIMEOUT);
1503
- }
1441
+ function handleStartInteraction() {
1442
+ closeTimeoutIdRef.current = window.setTimeout(() => {
1443
+ // Cancel click interaction on a long press
1444
+ shouldCancelInteractionRef.current = true;
1445
+ }, LONG_HANDLE_PRESS_TIMEOUT);
1446
+ }
1504
1447
 
1505
- function handleCancelInteraction() {
1506
- if (closeTimeoutIdRef.current) {
1507
- window.clearTimeout(closeTimeoutIdRef.current);
1448
+ function handleCancelInteraction() {
1449
+ if (closeTimeoutIdRef.current) {
1450
+ window.clearTimeout(closeTimeoutIdRef.current);
1451
+ }
1452
+ shouldCancelInteractionRef.current = false;
1508
1453
  }
1509
- shouldCancelInteractionRef.current = false;
1510
- }
1511
1454
 
1512
- return (
1513
- <div
1514
- onClick={handleStartCycle}
1515
- onPointerCancel={handleCancelInteraction}
1516
- onPointerDown={(e) => {
1517
- if (handleOnly) onPress(e);
1518
- handleStartInteraction();
1519
- }}
1520
- onPointerMove={(e) => {
1521
- if (handleOnly) onDrag(e);
1522
- }}
1523
- // onPointerUp is already handled by the content component
1524
- ref={ref}
1525
- data-vaul-drawer-visible={isOpen ? 'true' : 'false'}
1526
- data-vaul-handle=""
1527
- aria-hidden="true"
1528
- {...rest}
1529
- >
1530
- {/* Expand handle's hit area beyond what's visible to ensure a 44x44 tap target for touch devices */}
1531
- <span data-vaul-handle-hitarea="" aria-hidden="true">
1532
- {children}
1533
- </span>
1534
- </div>
1535
- );
1536
- });
1455
+ return (
1456
+ <div
1457
+ onClick={handleStartCycle}
1458
+ onPointerCancel={handleCancelInteraction}
1459
+ onPointerDown={(e) => {
1460
+ if (handleOnly) onPress(e);
1461
+ handleStartInteraction();
1462
+ }}
1463
+ onPointerMove={(e) => {
1464
+ if (handleOnly) onDrag(e);
1465
+ }}
1466
+ // onPointerUp is already handled by the content component
1467
+ ref={ref}
1468
+ data-vaul-drawer-visible={isOpen ? 'true' : 'false'}
1469
+ data-vaul-handle=""
1470
+ aria-hidden="true"
1471
+ {...rest}
1472
+ >
1473
+ {/* Expand handle's hit area beyond what's visible to ensure a 44x44 tap target for touch devices */}
1474
+ <span data-vaul-handle-hitarea="" aria-hidden="true">
1475
+ {children}
1476
+ </span>
1477
+ </div>
1478
+ );
1479
+ }
1480
+ );
1537
1481
 
1538
1482
  Handle.displayName = 'Drawer.Handle';
1539
1483