@rific/drawer 0.8.4 → 0.9.0

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/README.md CHANGED
@@ -75,6 +75,7 @@ A few more options, settable at `createDrawer()` (a fixed default) and overridab
75
75
  - **`blockingBackdrop`** (default `true`): whether the backdrop intercepts touches while the panel is open. The dimming/blur visual is unaffected either way; setting it to `false` only stops the backdrop from swallowing touches, so sibling content behind/around the panel stays reachable while it's open (tap-to-dismiss via the backdrop stops working in that mode: `dismissible`'s handle or your own close button take over).
76
76
  - **`backdropOpacity`** (default `0.45`): peak backdrop opacity once the panel is fully open, scaled down as it slides toward closed. `0` renders no dimming at all, leaving whatever's behind the panel fully visible. Independent of `blockingBackdrop`: a panel can stay undimmed and still block touches, or vice versa.
77
77
  - **`contentSize`** (default `false`): see [Content-driven sizing](#content-driven-sizing) below.
78
+ - **`peek`** (default `0`): see [Resting peek](#resting-peek) below.
78
79
  - **`closeOnBackPress`** (default `true`): whether the Android hardware back button closes the drawer while it's open, instead of falling through to whatever's behind it (a screen, a navigator). No-op on iOS/web, where that back-press event never fires.
79
80
  - **`zIndex`** (default `50`): see [Stacking multiple drawers](#stacking-multiple-drawers) below.
80
81
 
@@ -117,6 +118,18 @@ const style = useAnimatedStyle(() => ({ paddingTop: expandProgress.value * inset
117
118
 
118
119
  Always a flat `1` while open when there's no `maxHeight`/`maxWidth` (rest already is the full extent, same as the handle-drag behavior above).
119
120
 
121
+ ## Resting peek
122
+
123
+ Pass `peek` (px) to keep part of the panel on screen while it's closed, like a maps app's bottom sheet showing a summary bar until it's pulled up:
124
+
125
+ ```tsx
126
+ const { DrawerInstanceProvider: SheetProvider, useDrawer: useSheet } = createDrawer({ side: 'bottom', height: 320, peek: 88 })
127
+ ```
128
+
129
+ Closed, this sheet rests with its top 88px showing instead of sliding off screen. While it peeks there's no dimming and the backdrop doesn't catch touches, so whatever's behind the sheet stays fully usable; the peeking part of `content` (the edge nearest the open side: a bottom sheet's top, a left drawer's right edge) takes touches as usual, so a summary there can call `open()` on a tap. The drag handle stays live at the peek, and the panel's content drags it too, open or peeking, since what peeks is what people reach for: dragging open past a third of the way, or flinging, opens the drawer, and anything short of that springs back. The content's drag only takes over once a finger has moved 10px along the axis, so taps still reach it (a summary that calls `open()`, a button). Without a peek, content stays free of the panel's gestures as always. Closing, by `close()`, the backdrop or the handle, comes back to the peek rather than off screen, and the handle can't drag it shut past the peek either.
130
+
131
+ A drawer with a peek is never off screen, so `isVisible` is always `true` for it. Its edge swipe is off too: the peeking panel is the way in. Lay out `content` with what should show at rest nearest the open side, since that's the part that peeks. Settable at `createDrawer()` and overridable per mount, like the options above; on a standalone `Drawer`, pass `peek` along with `onOpen`, which the handle calls when a drag commits open (the parent owns `open`, so it flips it).
132
+
120
133
  ## Safe area
121
134
 
122
135
  The panel renders edge-to-edge, behind the status bar/notch and home indicator, on purpose. This package doesn't take a position on how you handle that. Pad your `content` yourself, however fits your app: `useSafeAreaInsets()` from `react-native-safe-area-context` directly, or a safe-area-aware header like `@rific/scroll-view`'s. Baking a fixed strategy into the panel itself would double up with whichever one you're already using for the rest of your app.
package/dist/index.d.mts CHANGED
@@ -25,6 +25,7 @@ type CreateDrawerOptions = {
25
25
  height?: DrawerDimension;
26
26
  maxHeight?: DrawerDimension;
27
27
  maxWidth?: DrawerDimension;
28
+ peek?: number;
28
29
  showHandle?: boolean;
29
30
  side?: DrawerSide;
30
31
  width?: DrawerDimension;
@@ -40,6 +41,7 @@ type DrawerInstanceProviderProps = {
40
41
  contentSize?: boolean;
41
42
  dismissible?: boolean;
42
43
  enabled?: boolean;
44
+ peek?: number;
43
45
  showHandle?: boolean;
44
46
  zIndex?: number;
45
47
  };
@@ -47,7 +49,7 @@ type CreateDrawerResult = {
47
49
  DrawerInstanceProvider: (props: DrawerInstanceProviderProps) => JSX.Element;
48
50
  useDrawer: () => DrawerActions;
49
51
  };
50
- declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
52
+ declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, peek: factoryPeek, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
51
53
  type DrawerInstanceProviderComponent = (props: DrawerInstanceProviderProps) => JSX.Element;
52
54
  declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderComponent, Omit<DrawerInstanceProviderProps, "children">?][]) => ({ children }: {
53
55
  children?: ReactNode;
@@ -71,18 +73,20 @@ type DrawerProps = {
71
73
  maxHeight?: DrawerDimension;
72
74
  maxWidth?: DrawerDimension;
73
75
  onClose: () => void;
76
+ onOpen?: () => void;
74
77
  onClosed?: () => void;
75
78
  onMeasure?: (size: number) => void;
76
79
  onOpened?: () => void;
77
80
  open: boolean;
78
81
  panelShadow?: boolean | DrawerPanelShadow;
82
+ peek?: number;
79
83
  side?: DrawerSide;
80
84
  showHandle?: boolean;
81
85
  translateOffset?: SharedValue<number>;
82
86
  width?: DrawerDimension;
83
87
  zIndex?: number;
84
88
  };
85
- declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, panelShadow, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
89
+ declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpen, onOpened, open, panelShadow, peek, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
86
90
 
87
91
  type AutoPaperModule = {
88
92
  BlurView: ComponentType<{
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ type CreateDrawerOptions = {
25
25
  height?: DrawerDimension;
26
26
  maxHeight?: DrawerDimension;
27
27
  maxWidth?: DrawerDimension;
28
+ peek?: number;
28
29
  showHandle?: boolean;
29
30
  side?: DrawerSide;
30
31
  width?: DrawerDimension;
@@ -40,6 +41,7 @@ type DrawerInstanceProviderProps = {
40
41
  contentSize?: boolean;
41
42
  dismissible?: boolean;
42
43
  enabled?: boolean;
44
+ peek?: number;
43
45
  showHandle?: boolean;
44
46
  zIndex?: number;
45
47
  };
@@ -47,7 +49,7 @@ type CreateDrawerResult = {
47
49
  DrawerInstanceProvider: (props: DrawerInstanceProviderProps) => JSX.Element;
48
50
  useDrawer: () => DrawerActions;
49
51
  };
50
- declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
52
+ declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, peek: factoryPeek, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
51
53
  type DrawerInstanceProviderComponent = (props: DrawerInstanceProviderProps) => JSX.Element;
52
54
  declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderComponent, Omit<DrawerInstanceProviderProps, "children">?][]) => ({ children }: {
53
55
  children?: ReactNode;
@@ -71,18 +73,20 @@ type DrawerProps = {
71
73
  maxHeight?: DrawerDimension;
72
74
  maxWidth?: DrawerDimension;
73
75
  onClose: () => void;
76
+ onOpen?: () => void;
74
77
  onClosed?: () => void;
75
78
  onMeasure?: (size: number) => void;
76
79
  onOpened?: () => void;
77
80
  open: boolean;
78
81
  panelShadow?: boolean | DrawerPanelShadow;
82
+ peek?: number;
79
83
  side?: DrawerSide;
80
84
  showHandle?: boolean;
81
85
  translateOffset?: SharedValue<number>;
82
86
  width?: DrawerDimension;
83
87
  zIndex?: number;
84
88
  };
85
- declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, panelShadow, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
89
+ declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpen, onOpened, open, panelShadow, peek, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
86
90
 
87
91
  type AutoPaperModule = {
88
92
  BlurView: ComponentType<{
package/dist/index.js CHANGED
@@ -69,6 +69,9 @@ function isVerticalSide(side) {
69
69
  function getClosedOffset(side, size) {
70
70
  return size === 0 ? 0 : side === "left" || side === "top" ? -size : size;
71
71
  }
72
+ function getPeekOffset(side, size, peek) {
73
+ return getClosedOffset(side, Math.max(0, size - Math.max(0, peek)));
74
+ }
72
75
  function getOpenDirection(side) {
73
76
  return side === "left" || side === "top" ? 1 : -1;
74
77
  }
@@ -97,9 +100,12 @@ var import_jsx_runtime = require("react/jsx-runtime");
97
100
  var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
98
101
  var VELOCITY_THRESHOLD = 500;
99
102
  var useBlurFallback = (override) => override ?? false;
100
- var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, panelShadow, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
103
+ var noop = () => {
104
+ };
105
+ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpen, onOpened, open, panelShadow, peek = 0, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
101
106
  const { colors } = (0, import_react_native_paper.useTheme)();
102
107
  const closeKey = (0, import_core2.useWorkletCallback)(onClose);
108
+ const openKey = (0, import_core2.useWorkletCallback)(onOpen ?? noop);
103
109
  const vertical = isVerticalSide(side);
104
110
  const openDirection = getOpenDirection(side);
105
111
  const closeDirection = -openDirection;
@@ -115,7 +121,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
115
121
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
116
122
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
117
123
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
118
- const internalTranslateOffset = (0, import_react_native_reanimated.useSharedValue)(closedOffset);
124
+ const peekOffset = getPeekOffset(side, maxEffectiveSize, peek);
125
+ const peeks = peekOffset !== closedOffset;
126
+ const internalTranslateOffset = (0, import_react_native_reanimated.useSharedValue)(peekOffset);
119
127
  const translateOffset = externalTranslateOffset ?? internalTranslateOffset;
120
128
  const { autoPaper } = getDrawerConfig();
121
129
  const resolvedBlur = (autoPaper?.useBlur ?? useBlurFallback)(blur);
@@ -131,21 +139,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
131
139
  return;
132
140
  }
133
141
  if (!openChanged) {
134
- translateOffset.value = closedOffset;
142
+ translateOffset.value = peekOffset;
135
143
  onClosed?.();
136
144
  return;
137
145
  }
138
- translateOffset.value = (0, import_react_native_reanimated.withSpring)(closedOffset, SPRING, (finished) => {
146
+ translateOffset.value = (0, import_react_native_reanimated.withSpring)(peekOffset, SPRING, (finished) => {
139
147
  if (finished && onClosed) (0, import_react_native_worklets.scheduleOnRN)(onClosed);
140
148
  });
141
- }, [open, closedOffset, restOffset, translateOffset]);
149
+ }, [open, peekOffset, restOffset, translateOffset]);
142
150
  (0, import_react.useEffect)(() => {
143
151
  if (contentSize) {
144
152
  animatedSize.value = (0, import_react_native_reanimated.withTiming)(effectiveSize);
145
153
  }
146
154
  }, [contentSize, effectiveSize, animatedSize]);
147
155
  const drawerStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => ({ transform: [vertical ? { translateY: translateOffset.value } : { translateX: translateOffset.value }] }));
148
- const backdropStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }));
156
+ const backdropStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
157
+ const dimmingRange = maxEffectiveSize - peek;
158
+ if (dimmingRange <= 0) return { opacity: 0 };
159
+ const visibleSize = maxEffectiveSize - Math.abs(translateOffset.value);
160
+ return { opacity: Math.min(1, Math.max(0, (visibleSize - peek) / dimmingRange)) * backdropOpacity };
161
+ });
149
162
  const animatedSizeStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => vertical ? { height: animatedSize.value } : { width: animatedSize.value });
150
163
  const backdropPointerEvents = open && blockingBackdrop ? "box-none" : "none";
151
164
  const backdropTapAreaStyle = side === "left" ? { left: maxEffectiveSize } : side === "right" ? { right: maxEffectiveSize } : side === "top" ? { top: maxEffectiveSize } : { bottom: maxEffectiveSize };
@@ -169,14 +182,15 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
169
182
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [fillStyle, { backgroundColor: colors.surface }], children });
170
183
  const drawerOuterStyle = contentSize ? [styles.drawer, positionStyle, drawerStyle, animatedSizeStyle, { zIndex: zIndex + 1 }] : [styles.drawer, positionStyle, sizeStyle, drawerStyle, { zIndex: zIndex + 1 }];
171
184
  const contentClipStyle = [fillStyle, clipOverflowStyle, { flexDirection: vertical ? "column" : "row" }];
172
- const clampMin = Math.min(0, closedOffset);
173
- const clampMax = Math.max(0, closedOffset);
174
- const handleAxisGesture = vertical ? import_react_native_gesture_handler.Gesture.Pan().activeOffsetY(restOffset !== 0 ? [-10, 10] : closeDirection * 10).failOffsetX([-15, 15]) : import_react_native_gesture_handler.Gesture.Pan().activeOffsetX(restOffset !== 0 ? [-10, 10] : closeDirection * 10).failOffsetY([-15, 15]);
185
+ const clampMin = Math.min(0, peekOffset);
186
+ const clampMax = Math.max(0, peekOffset);
187
+ const twoWay = restOffset !== 0 || peeks;
188
+ const makeAxisGesture = () => vertical ? import_react_native_gesture_handler.Gesture.Pan().activeOffsetY(twoWay ? [-10, 10] : closeDirection * 10).failOffsetX([-15, 15]) : import_react_native_gesture_handler.Gesture.Pan().activeOffsetX(twoWay ? [-10, 10] : closeDirection * 10).failOffsetY([-15, 15]);
175
189
  const gestureStartOffset = (0, import_react_native_reanimated.useSharedValue)(closedOffset);
176
190
  const backdropTapGesture = import_react_native_gesture_handler.Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
177
191
  if (success) (0, import_react_native_worklets.scheduleOnRN)(import_core2.callWorkletCallback, closeKey);
178
192
  });
179
- const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
193
+ const withDragHandlers = (axisGesture) => axisGesture.enabled(open || peeks).onStart(() => {
180
194
  "worklet";
181
195
  gestureStartOffset.value = translateOffset.value;
182
196
  }).onUpdate((event) => {
@@ -195,13 +209,18 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
195
209
  const progress = restD > 0 ? (restD - currentD) / restD : 1;
196
210
  target = progress > 1 / 3 || velocityD < -VELOCITY_THRESHOLD ? 0 : restOffset;
197
211
  } else {
198
- const progress = effectiveSize > 0 ? (currentD - restD) / effectiveSize : 1;
199
- closing = progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD;
200
- target = closing ? closedOffset : restOffset;
212
+ const segment = effectiveSize - peek;
213
+ const progress = segment > 0 ? (currentD - restD) / segment : 1;
214
+ closing = open ? progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD : !(progress < 2 / 3 || velocityD < -VELOCITY_THRESHOLD);
215
+ target = closing ? peekOffset : restOffset;
201
216
  }
217
+ if (!open && !closing) target = restOffset;
202
218
  translateOffset.value = (0, import_react_native_reanimated.withSpring)(target, SPRING);
203
- if (closing) (0, import_react_native_worklets.scheduleOnRN)(import_core2.callWorkletCallback, closeKey);
219
+ if (closing && open) (0, import_react_native_worklets.scheduleOnRN)(import_core2.callWorkletCallback, closeKey);
220
+ if (!closing && !open) (0, import_react_native_worklets.scheduleOnRN)(import_core2.callWorkletCallback, openKey);
204
221
  });
222
+ const handleGesture = withDragHandlers(makeAxisGesture());
223
+ const contentGesture = withDragHandlers(makeAxisGesture()).enabled(peeks);
205
224
  const HANDLE_STRIP_THICKNESS = 28;
206
225
  const HANDLE_HIT_SLOP = 20;
207
226
  const HANDLE_STRIP_TOTAL_THICKNESS = HANDLE_STRIP_THICKNESS + HANDLE_HIT_SLOP;
@@ -210,7 +229,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
210
229
  const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
211
230
  const handleStripPaddingStyle = side === "left" ? { paddingLeft: HANDLE_HIT_SLOP } : side === "right" ? { paddingRight: HANDLE_HIT_SLOP } : side === "top" ? { paddingTop: HANDLE_HIT_SLOP } : { paddingBottom: HANDLE_HIT_SLOP };
212
231
  const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
213
- const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
232
+ const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open || peeks ? "auto" : "none" };
214
233
  const webCursorStyle2 = { cursor: import_react_native2.Platform.OS === "web" ? "pointer" : void 0 };
215
234
  const handleVisibilityStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
216
235
  const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
@@ -228,7 +247,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
228
247
  ] }),
229
248
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { pointerEvents: "box-none", style: [styles.panelClip, clipOverflowStyle, { zIndex: zIndex + 1 }], children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native_reanimated.default.View, { style: drawerOuterStyle, children: [
230
249
  resolvedPanelShadow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_reanimated.default.View, { pointerEvents: "none", style: [import_react_native2.StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle] }),
231
- contentSize ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill,
250
+ peeks ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_gesture_handler.GestureDetector, { gesture: contentGesture, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { collapsable: false, style: import_react_native2.StyleSheet.absoluteFill, children: contentSize ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill }) }) : contentSize ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill,
232
251
  dismissible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_gesture_handler.GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native_reanimated.default.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle2, handleVisibilityStyle, handleStripInteractionStyle], children: showHandle && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
233
252
  ] }) })
234
253
  ] });
@@ -357,18 +376,19 @@ var styles2 = import_react_native3.StyleSheet.create({
357
376
 
358
377
  // src/createDrawer.tsx
359
378
  var import_jsx_runtime3 = require("react/jsx-runtime");
360
- var noop = () => {
379
+ var noop2 = () => {
361
380
  };
362
- var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, showHandle: factoryShowHandle, side = "left", width = 300, zIndex: factoryZIndex } = {}) => {
381
+ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, peek: factoryPeek, showHandle: factoryShowHandle, side = "left", width = 300, zIndex: factoryZIndex } = {}) => {
363
382
  const defaultExpandProgress = { value: 1 };
364
- const DrawerActionsContext = (0, import_react2.createContext)({ close: noop, expandProgress: defaultExpandProgress, isOpen: false, isVisible: false, open: noop });
383
+ const DrawerActionsContext = (0, import_react2.createContext)({ close: noop2, expandProgress: defaultExpandProgress, isOpen: false, isVisible: false, open: noop2 });
365
384
  const vertical = isVerticalSide(side);
366
385
  const size = vertical ? height : width;
367
386
  const maxSize = vertical ? maxHeight : maxWidth;
368
387
  const closeDirection = -getOpenDirection(side);
369
- const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, showHandle: showHandleOverride, zIndex: zIndexOverride }) => {
388
+ const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, peek: peekOverride, showHandle: showHandleOverride, zIndex: zIndexOverride }) => {
389
+ const peek = peekOverride ?? factoryPeek ?? 0;
370
390
  const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
371
- const [isVisible, setIsVisible] = (0, import_react2.useState)(false);
391
+ const [isVisible, setIsVisible] = (0, import_react2.useState)(peek > 0);
372
392
  const [measuredSize, setMeasuredSize] = (0, import_react2.useState)(null);
373
393
  const backdropOpacity = backdropOpacityOverride ?? factoryBackdropOpacity ?? 0.45;
374
394
  const blur = blurOverride ?? factoryBlur;
@@ -379,8 +399,8 @@ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop:
379
399
  const showHandle = showHandleOverride ?? factoryShowHandle ?? true;
380
400
  const zIndex = zIndexOverride ?? factoryZIndex ?? 50;
381
401
  const effectiveSize = contentSize ? measuredSize ?? size : size;
382
- const { closedOffset, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? void 0 : maxSize, edgeInset);
383
- const translateOffset = (0, import_react_native_reanimated3.useSharedValue)(closedOffset);
402
+ const { maxEffectiveSize, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? void 0 : maxSize, edgeInset);
403
+ const translateOffset = (0, import_react_native_reanimated3.useSharedValue)(getPeekOffset(side, maxEffectiveSize, peek));
384
404
  const expandProgress = (0, import_react_native_reanimated3.useDerivedValue)(() => {
385
405
  const currentD = translateOffset.value * closeDirection;
386
406
  const restD = restOffset * closeDirection;
@@ -411,8 +431,8 @@ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop:
411
431
  }, [isOpen, closeOnBackPress]);
412
432
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(DrawerActionsContext.Provider, { value: actions, children: [
413
433
  children,
414
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DrawerEdgeSwipe, { edgeInset, enabled: enabled && !isOpen, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onOpen: open, side, translateOffset, width: vertical ? width : effectiveSize }),
415
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Drawer, { backdropOpacity, blockingBackdrop, blur, contentSize, dismissible, edgeInset, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onClose: () => setIsOpen(false), onClosed: () => setIsVisible(false), onMeasure: setMeasuredSize, open: isOpen, showHandle, side, translateOffset, width: vertical ? width : effectiveSize, zIndex, children: content })
434
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DrawerEdgeSwipe, { edgeInset, enabled: enabled && !isOpen && peek <= 0, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onOpen: open, side, translateOffset, width: vertical ? width : effectiveSize }),
435
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Drawer, { backdropOpacity, blockingBackdrop, blur, contentSize, dismissible, edgeInset, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onClose: () => setIsOpen(false), onClosed: () => setIsVisible(peek > 0), onMeasure: setMeasuredSize, onOpen: open, open: isOpen, peek, showHandle, side, translateOffset, width: vertical ? width : effectiveSize, zIndex, children: content })
416
436
  ] });
417
437
  };
418
438
  const useDrawer = () => (0, import_react2.useContext)(DrawerActionsContext);
package/dist/index.mjs CHANGED
@@ -26,6 +26,9 @@ function isVerticalSide(side) {
26
26
  function getClosedOffset(side, size) {
27
27
  return size === 0 ? 0 : side === "left" || side === "top" ? -size : size;
28
28
  }
29
+ function getPeekOffset(side, size, peek) {
30
+ return getClosedOffset(side, Math.max(0, size - Math.max(0, peek)));
31
+ }
29
32
  function getOpenDirection(side) {
30
33
  return side === "left" || side === "top" ? 1 : -1;
31
34
  }
@@ -54,9 +57,12 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
54
57
  var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
55
58
  var VELOCITY_THRESHOLD = 500;
56
59
  var useBlurFallback = (override) => override ?? false;
57
- var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, panelShadow, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
60
+ var noop = () => {
61
+ };
62
+ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpen, onOpened, open, panelShadow, peek = 0, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
58
63
  const { colors } = useTheme();
59
64
  const closeKey = useWorkletCallback(onClose);
65
+ const openKey = useWorkletCallback(onOpen ?? noop);
60
66
  const vertical = isVerticalSide(side);
61
67
  const openDirection = getOpenDirection(side);
62
68
  const closeDirection = -openDirection;
@@ -72,7 +78,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
72
78
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
73
79
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
74
80
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
75
- const internalTranslateOffset = useSharedValue(closedOffset);
81
+ const peekOffset = getPeekOffset(side, maxEffectiveSize, peek);
82
+ const peeks = peekOffset !== closedOffset;
83
+ const internalTranslateOffset = useSharedValue(peekOffset);
76
84
  const translateOffset = externalTranslateOffset ?? internalTranslateOffset;
77
85
  const { autoPaper } = getDrawerConfig();
78
86
  const resolvedBlur = (autoPaper?.useBlur ?? useBlurFallback)(blur);
@@ -88,21 +96,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
88
96
  return;
89
97
  }
90
98
  if (!openChanged) {
91
- translateOffset.value = closedOffset;
99
+ translateOffset.value = peekOffset;
92
100
  onClosed?.();
93
101
  return;
94
102
  }
95
- translateOffset.value = withSpring(closedOffset, SPRING, (finished) => {
103
+ translateOffset.value = withSpring(peekOffset, SPRING, (finished) => {
96
104
  if (finished && onClosed) scheduleOnRN(onClosed);
97
105
  });
98
- }, [open, closedOffset, restOffset, translateOffset]);
106
+ }, [open, peekOffset, restOffset, translateOffset]);
99
107
  useEffect(() => {
100
108
  if (contentSize) {
101
109
  animatedSize.value = withTiming(effectiveSize);
102
110
  }
103
111
  }, [contentSize, effectiveSize, animatedSize]);
104
112
  const drawerStyle = useAnimatedStyle(() => ({ transform: [vertical ? { translateY: translateOffset.value } : { translateX: translateOffset.value }] }));
105
- const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }));
113
+ const backdropStyle = useAnimatedStyle(() => {
114
+ const dimmingRange = maxEffectiveSize - peek;
115
+ if (dimmingRange <= 0) return { opacity: 0 };
116
+ const visibleSize = maxEffectiveSize - Math.abs(translateOffset.value);
117
+ return { opacity: Math.min(1, Math.max(0, (visibleSize - peek) / dimmingRange)) * backdropOpacity };
118
+ });
106
119
  const animatedSizeStyle = useAnimatedStyle(() => vertical ? { height: animatedSize.value } : { width: animatedSize.value });
107
120
  const backdropPointerEvents = open && blockingBackdrop ? "box-none" : "none";
108
121
  const backdropTapAreaStyle = side === "left" ? { left: maxEffectiveSize } : side === "right" ? { right: maxEffectiveSize } : side === "top" ? { top: maxEffectiveSize } : { bottom: maxEffectiveSize };
@@ -126,14 +139,15 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
126
139
  ] }) : /* @__PURE__ */ jsx(View, { style: [fillStyle, { backgroundColor: colors.surface }], children });
127
140
  const drawerOuterStyle = contentSize ? [styles.drawer, positionStyle, drawerStyle, animatedSizeStyle, { zIndex: zIndex + 1 }] : [styles.drawer, positionStyle, sizeStyle, drawerStyle, { zIndex: zIndex + 1 }];
128
141
  const contentClipStyle = [fillStyle, clipOverflowStyle, { flexDirection: vertical ? "column" : "row" }];
129
- const clampMin = Math.min(0, closedOffset);
130
- const clampMax = Math.max(0, closedOffset);
131
- const handleAxisGesture = vertical ? Gesture.Pan().activeOffsetY(restOffset !== 0 ? [-10, 10] : closeDirection * 10).failOffsetX([-15, 15]) : Gesture.Pan().activeOffsetX(restOffset !== 0 ? [-10, 10] : closeDirection * 10).failOffsetY([-15, 15]);
142
+ const clampMin = Math.min(0, peekOffset);
143
+ const clampMax = Math.max(0, peekOffset);
144
+ const twoWay = restOffset !== 0 || peeks;
145
+ const makeAxisGesture = () => vertical ? Gesture.Pan().activeOffsetY(twoWay ? [-10, 10] : closeDirection * 10).failOffsetX([-15, 15]) : Gesture.Pan().activeOffsetX(twoWay ? [-10, 10] : closeDirection * 10).failOffsetY([-15, 15]);
132
146
  const gestureStartOffset = useSharedValue(closedOffset);
133
147
  const backdropTapGesture = Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
134
148
  if (success) scheduleOnRN(callWorkletCallback, closeKey);
135
149
  });
136
- const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
150
+ const withDragHandlers = (axisGesture) => axisGesture.enabled(open || peeks).onStart(() => {
137
151
  "worklet";
138
152
  gestureStartOffset.value = translateOffset.value;
139
153
  }).onUpdate((event) => {
@@ -152,13 +166,18 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
152
166
  const progress = restD > 0 ? (restD - currentD) / restD : 1;
153
167
  target = progress > 1 / 3 || velocityD < -VELOCITY_THRESHOLD ? 0 : restOffset;
154
168
  } else {
155
- const progress = effectiveSize > 0 ? (currentD - restD) / effectiveSize : 1;
156
- closing = progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD;
157
- target = closing ? closedOffset : restOffset;
169
+ const segment = effectiveSize - peek;
170
+ const progress = segment > 0 ? (currentD - restD) / segment : 1;
171
+ closing = open ? progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD : !(progress < 2 / 3 || velocityD < -VELOCITY_THRESHOLD);
172
+ target = closing ? peekOffset : restOffset;
158
173
  }
174
+ if (!open && !closing) target = restOffset;
159
175
  translateOffset.value = withSpring(target, SPRING);
160
- if (closing) scheduleOnRN(callWorkletCallback, closeKey);
176
+ if (closing && open) scheduleOnRN(callWorkletCallback, closeKey);
177
+ if (!closing && !open) scheduleOnRN(callWorkletCallback, openKey);
161
178
  });
179
+ const handleGesture = withDragHandlers(makeAxisGesture());
180
+ const contentGesture = withDragHandlers(makeAxisGesture()).enabled(peeks);
162
181
  const HANDLE_STRIP_THICKNESS = 28;
163
182
  const HANDLE_HIT_SLOP = 20;
164
183
  const HANDLE_STRIP_TOTAL_THICKNESS = HANDLE_STRIP_THICKNESS + HANDLE_HIT_SLOP;
@@ -167,7 +186,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
167
186
  const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
168
187
  const handleStripPaddingStyle = side === "left" ? { paddingLeft: HANDLE_HIT_SLOP } : side === "right" ? { paddingRight: HANDLE_HIT_SLOP } : side === "top" ? { paddingTop: HANDLE_HIT_SLOP } : { paddingBottom: HANDLE_HIT_SLOP };
169
188
  const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
170
- const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
189
+ const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open || peeks ? "auto" : "none" };
171
190
  const webCursorStyle2 = { cursor: Platform.OS === "web" ? "pointer" : void 0 };
172
191
  const handleVisibilityStyle = useAnimatedStyle(() => {
173
192
  const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
@@ -185,7 +204,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
185
204
  ] }),
186
205
  /* @__PURE__ */ jsx(View, { pointerEvents: "box-none", style: [styles.panelClip, clipOverflowStyle, { zIndex: zIndex + 1 }], children: /* @__PURE__ */ jsxs(Animated.View, { style: drawerOuterStyle, children: [
187
206
  resolvedPanelShadow && /* @__PURE__ */ jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle] }),
188
- contentSize ? /* @__PURE__ */ jsx(View, { style: contentClipStyle, children: fill }) : fill,
207
+ peeks ? /* @__PURE__ */ jsx(GestureDetector, { gesture: contentGesture, children: /* @__PURE__ */ jsx(View, { collapsable: false, style: StyleSheet.absoluteFill, children: contentSize ? /* @__PURE__ */ jsx(View, { style: contentClipStyle, children: fill }) : fill }) }) : contentSize ? /* @__PURE__ */ jsx(View, { style: contentClipStyle, children: fill }) : fill,
189
208
  dismissible && /* @__PURE__ */ jsx(GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ jsx(Animated.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle2, handleVisibilityStyle, handleStripInteractionStyle], children: showHandle && /* @__PURE__ */ jsx(View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
190
209
  ] }) })
191
210
  ] });
@@ -314,18 +333,19 @@ var styles2 = StyleSheet2.create({
314
333
 
315
334
  // src/createDrawer.tsx
316
335
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
317
- var noop = () => {
336
+ var noop2 = () => {
318
337
  };
319
- var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, showHandle: factoryShowHandle, side = "left", width = 300, zIndex: factoryZIndex } = {}) => {
338
+ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, peek: factoryPeek, showHandle: factoryShowHandle, side = "left", width = 300, zIndex: factoryZIndex } = {}) => {
320
339
  const defaultExpandProgress = { value: 1 };
321
- const DrawerActionsContext = createContext({ close: noop, expandProgress: defaultExpandProgress, isOpen: false, isVisible: false, open: noop });
340
+ const DrawerActionsContext = createContext({ close: noop2, expandProgress: defaultExpandProgress, isOpen: false, isVisible: false, open: noop2 });
322
341
  const vertical = isVerticalSide(side);
323
342
  const size = vertical ? height : width;
324
343
  const maxSize = vertical ? maxHeight : maxWidth;
325
344
  const closeDirection = -getOpenDirection(side);
326
- const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, showHandle: showHandleOverride, zIndex: zIndexOverride }) => {
345
+ const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, peek: peekOverride, showHandle: showHandleOverride, zIndex: zIndexOverride }) => {
346
+ const peek = peekOverride ?? factoryPeek ?? 0;
327
347
  const [isOpen, setIsOpen] = useState2(false);
328
- const [isVisible, setIsVisible] = useState2(false);
348
+ const [isVisible, setIsVisible] = useState2(peek > 0);
329
349
  const [measuredSize, setMeasuredSize] = useState2(null);
330
350
  const backdropOpacity = backdropOpacityOverride ?? factoryBackdropOpacity ?? 0.45;
331
351
  const blur = blurOverride ?? factoryBlur;
@@ -336,8 +356,8 @@ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop:
336
356
  const showHandle = showHandleOverride ?? factoryShowHandle ?? true;
337
357
  const zIndex = zIndexOverride ?? factoryZIndex ?? 50;
338
358
  const effectiveSize = contentSize ? measuredSize ?? size : size;
339
- const { closedOffset, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? void 0 : maxSize, edgeInset);
340
- const translateOffset = useSharedValue2(closedOffset);
359
+ const { maxEffectiveSize, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? void 0 : maxSize, edgeInset);
360
+ const translateOffset = useSharedValue2(getPeekOffset(side, maxEffectiveSize, peek));
341
361
  const expandProgress = useDerivedValue(() => {
342
362
  const currentD = translateOffset.value * closeDirection;
343
363
  const restD = restOffset * closeDirection;
@@ -368,8 +388,8 @@ var createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop:
368
388
  }, [isOpen, closeOnBackPress]);
369
389
  return /* @__PURE__ */ jsxs2(DrawerActionsContext.Provider, { value: actions, children: [
370
390
  children,
371
- /* @__PURE__ */ jsx3(DrawerEdgeSwipe, { edgeInset, enabled: enabled && !isOpen, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onOpen: open, side, translateOffset, width: vertical ? width : effectiveSize }),
372
- /* @__PURE__ */ jsx3(Drawer, { backdropOpacity, blockingBackdrop, blur, contentSize, dismissible, edgeInset, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onClose: () => setIsOpen(false), onClosed: () => setIsVisible(false), onMeasure: setMeasuredSize, open: isOpen, showHandle, side, translateOffset, width: vertical ? width : effectiveSize, zIndex, children: content })
391
+ /* @__PURE__ */ jsx3(DrawerEdgeSwipe, { edgeInset, enabled: enabled && !isOpen && peek <= 0, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onOpen: open, side, translateOffset, width: vertical ? width : effectiveSize }),
392
+ /* @__PURE__ */ jsx3(Drawer, { backdropOpacity, blockingBackdrop, blur, contentSize, dismissible, edgeInset, height: vertical ? effectiveSize : height, maxHeight, maxWidth, onClose: () => setIsOpen(false), onClosed: () => setIsVisible(peek > 0), onMeasure: setMeasuredSize, onOpen: open, open: isOpen, peek, showHandle, side, translateOffset, width: vertical ? width : effectiveSize, zIndex, children: content })
373
393
  ] });
374
394
  };
375
395
  const useDrawer = () => useContext(DrawerActionsContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rific/drawer",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "description": "Left/right sliding drawer with edge-swipe gestures for React Native: spring-animated, theme-aware, one factory call per drawer instance",
5
5
  "keywords": [
6
6
  "react-native",
package/src/Drawer.tsx CHANGED
@@ -7,7 +7,7 @@ import Animated, { SharedValue, useAnimatedStyle, useSharedValue, withSpring, wi
7
7
  import { scheduleOnRN } from 'react-native-worklets'
8
8
 
9
9
  import { getDrawerConfig } from './DrawerConfig'
10
- import { type DrawerDimension, type DrawerSide, getOpenDirection, isVerticalSide } from './geometry'
10
+ import { type DrawerDimension, type DrawerSide, getOpenDirection, getPeekOffset, isVerticalSide } from './geometry'
11
11
  import { useDrawerSize } from './useDrawerSize'
12
12
 
13
13
  // stiffness raised from 300 (was ~400-450ms to visually settle): at this damping the system is
@@ -30,6 +30,8 @@ const VELOCITY_THRESHOLD = 500
30
30
  // fallback stands in when auto-paper isn't configured, so a per-render branch isn't needed.
31
31
  const useBlurFallback = (override?: boolean) => override ?? false
32
32
 
33
+ const noop = () => {}
34
+
33
35
  export type DrawerPanelShadow = {
34
36
  blurRadius?: number
35
37
  color?: string
@@ -96,6 +98,11 @@ export type DrawerProps = {
96
98
  // The maxWidth mirror of maxHeight, for `left`/`right` drawers.
97
99
  maxWidth?: DrawerDimension
98
100
  onClose: () => void
101
+ // Called when a drag on the handle commits open from the resting peek (see `peek`), the open-side
102
+ // mirror of onClose: the parent owns `open`, so it's the one that flips it. Only a panel with a peek
103
+ // can be dragged open by its handle; without one the handle is out of reach while closed. Omit it
104
+ // and a drag up from the peek just springs back.
105
+ onOpen?: () => void
99
106
  // Fires once the close animation actually finishes settling at closedOffset, not when `open`
100
107
  // merely flips to false, which happens the instant something asks to close, well before the panel
101
108
  // has visually finished sliding away. Lets a parent (e.g. DrawerInstanceProvider's isVisible) track "still
@@ -121,6 +128,15 @@ export type DrawerProps = {
121
128
  // shadow rendering doesn't know or care that its box is off-screen, so a few px of blur reads as
122
129
  // a permanent, unwanted line along that edge, closed or not.
123
130
  panelShadow?: boolean | DrawerPanelShadow
131
+ // How much of the panel, in px, stays on screen while closed: a resting peek, like a maps app's
132
+ // bottom sheet showing a summary bar until it's pulled up. 0 (the default) closes it fully off
133
+ // screen, as always. While peeking there's no dimming and the backdrop never catches a touch, so
134
+ // whatever's behind the panel stays usable; the peeking part of `children` (the edge nearest the
135
+ // open side: a bottom sheet's top) takes touches as usual, so a summary there can call the
136
+ // parent's own open on a tap. The handle stays live at the peek: dragging it open past a third of
137
+ // the way commits and calls onOpen, and closing (onClose, the backdrop, the handle) comes back to
138
+ // the peek rather than off screen.
139
+ peek?: number
124
140
  side?: DrawerSide
125
141
  // Whether the handle strip's own visual pill graphic draws, independent of `dismissible`, which
126
142
  // controls the strip (and its drag-to-dismiss gesture) as a whole. false keeps the strip's hit area
@@ -140,11 +156,12 @@ export type DrawerProps = {
140
156
  zIndex?: number
141
157
  }
142
158
 
143
- export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, panelShadow, side = 'left', showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }: DrawerProps) => {
159
+ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpen, onOpened, open, panelShadow, peek = 0, side = 'left', showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }: DrawerProps) => {
144
160
  const { colors } = useTheme()
145
161
  // Worklets below never get onClose itself: react-native-worklets holds a runOnJS target natively for as long as
146
162
  // the worklet lives, which pinned the whole drawer. They call the module-level callWorkletCallback by key.
147
163
  const closeKey = useWorkletCallback(onClose)
164
+ const openKey = useWorkletCallback(onOpen ?? noop)
148
165
  const vertical = isVerticalSide(side)
149
166
  const openDirection = getOpenDirection(side)
150
167
  const closeDirection = -openDirection as 1 | -1
@@ -170,8 +187,12 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
170
187
  const sizeInput = contentSize ? (measuredSize ?? (vertical ? height : width)) : vertical ? height : width
171
188
  const maxSizeInput = contentSize ? undefined : vertical ? maxHeight : maxWidth
172
189
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset)
190
+ // Where the panel rests while closed: closedOffset itself without a peek, otherwise `peek` px short
191
+ // of it. Every "closed" below means this.
192
+ const peekOffset = getPeekOffset(side, maxEffectiveSize, peek)
193
+ const peeks = peekOffset !== closedOffset
173
194
 
174
- const internalTranslateOffset = useSharedValue(closedOffset)
195
+ const internalTranslateOffset = useSharedValue(peekOffset)
175
196
  const translateOffset = externalTranslateOffset ?? internalTranslateOffset
176
197
  const { autoPaper } = getDrawerConfig()
177
198
  const resolvedBlur = (autoPaper?.useBlur ?? useBlurFallback)(blur)
@@ -201,24 +222,24 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
201
222
  return
202
223
  }
203
224
  if (!openChanged) {
204
- // Still closed, but closedOffset moved (the window resized, or contentSize re-measured): jump
225
+ // Still closed, but its resting offset moved (the window resized, or contentSize re-measured): jump
205
226
  // to it rather than spring. The panel's box takes its new size at once, so springing a grown
206
227
  // panel out from its old, smaller offset left the difference peeking in past the screen edge
207
228
  // for the whole spring (15px of a closed window-wide drawer when the window went 360 to 375).
208
229
  // A jump also cancels a close spring still in flight, whose callback then reports unfinished,
209
230
  // so onClosed is called here instead (a resize while settled closed re-fired it before too).
210
- translateOffset.value = closedOffset
231
+ translateOffset.value = peekOffset
211
232
  onClosed?.()
212
233
  return
213
234
  }
214
- translateOffset.value = withSpring(closedOffset, SPRING, (finished) => {
235
+ translateOffset.value = withSpring(peekOffset, SPRING, (finished) => {
215
236
  if (finished && onClosed) scheduleOnRN(onClosed)
216
237
  })
217
238
  // onOpened/onClosed deliberately excluded: both are plain closures (DrawerInstanceProvider passes a
218
239
  // fresh function every render), and including them would restart this spring from its current
219
240
  // position every time the parent re-renders for any unrelated reason.
220
241
  // eslint-disable-next-line react-hooks/exhaustive-deps
221
- }, [open, closedOffset, restOffset, translateOffset])
242
+ }, [open, peekOffset, restOffset, translateOffset])
222
243
 
223
244
  useEffect(() => {
224
245
  if (contentSize) {
@@ -236,7 +257,15 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
236
257
  // on web before the window's real size is measured (e.g. during SSR/hydration), which would
237
258
  // otherwise divide 0/0 into NaN and crash react-native-web's style layer. Falls back to fully
238
259
  // transparent, matching "closed," since a not-yet-sized panel isn't meaningfully open yet either.
239
- const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }))
260
+ // With a peek, dimming starts from it rather than from fully closed: a resting peek isn't the panel
261
+ // opening, so it leaves what's behind it undimmed (peek is 0 otherwise, which is the formula as it
262
+ // always was).
263
+ const backdropStyle = useAnimatedStyle(() => {
264
+ const dimmingRange = maxEffectiveSize - peek
265
+ if (dimmingRange <= 0) return { opacity: 0 }
266
+ const visibleSize = maxEffectiveSize - Math.abs(translateOffset.value)
267
+ return { opacity: Math.min(1, Math.max(0, (visibleSize - peek) / dimmingRange)) * backdropOpacity }
268
+ })
240
269
  const animatedSizeStyle = useAnimatedStyle(() => (vertical ? { height: animatedSize.value } : { width: animatedSize.value }))
241
270
  // 'box-none' (not 'auto'): this wrapper is just a positioning shell around the dimming tint and
242
271
  // the actual tap-catching view below - on react-native-web, an ancestor's own explicit zIndex
@@ -370,8 +399,9 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
370
399
  // expanded (0) - and the drag can commit toward whichever of those neighbors it's currently
371
400
  // nearest, in either direction. Deliberately its own hit area rather than the whole panel, so it
372
401
  // can't steal touches from arbitrary interactive content inside `children`.
373
- const clampMin = Math.min(0, closedOffset)
374
- const clampMax = Math.max(0, closedOffset)
402
+ // A peeking panel can't be dragged further shut than its peek.
403
+ const clampMin = Math.min(0, peekOffset)
404
+ const clampMax = Math.max(0, peekOffset)
375
405
 
376
406
  // A single signed offset (e.g. closeDirection * 10) only arms the gesture for drags past that
377
407
  // threshold in ONE direction - exactly what the plain close-only case wants (dragging the "wrong"
@@ -380,13 +410,18 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
380
410
  // maxHeight/maxWidth (restOffset always 0) that's fine, since there's nothing to expand into: keep
381
411
  // the single-direction threshold, unchanged from before. Once expansion is possible, the gesture
382
412
  // needs to recognize BOTH directions, so it switches to a symmetric range instead.
383
- const handleAxisGesture = vertical
384
- ? Gesture.Pan()
385
- .activeOffsetY(restOffset !== 0 ? [-10, 10] : closeDirection * 10)
386
- .failOffsetX([-15, 15])
387
- : Gesture.Pan()
388
- .activeOffsetX(restOffset !== 0 ? [-10, 10] : closeDirection * 10)
389
- .failOffsetY([-15, 15])
413
+ // From the peek the drag goes the other way (open), so a peeking panel listens both ways too.
414
+ const twoWay = restOffset !== 0 || peeks
415
+ // A function, not one gesture: a peeking panel's content drags it too (see contentGesture below),
416
+ // and a gesture object can only be attached to one GestureDetector.
417
+ const makeAxisGesture = () =>
418
+ vertical
419
+ ? Gesture.Pan()
420
+ .activeOffsetY(twoWay ? [-10, 10] : closeDirection * 10)
421
+ .failOffsetX([-15, 15])
422
+ : Gesture.Pan()
423
+ .activeOffsetX(twoWay ? [-10, 10] : closeDirection * 10)
424
+ .failOffsetY([-15, 15])
390
425
 
391
426
  // Snapshotted at the start of each drag rather than assumed to be 0/restOffset: a drag can begin
392
427
  // mid-expansion (or even mid-spring, if a new touch interrupts one still settling), and onUpdate
@@ -404,54 +439,71 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
404
439
  if (success) scheduleOnRN(callWorkletCallback, closeKey)
405
440
  })
406
441
 
407
- const handleGesture = handleAxisGesture
408
- .enabled(open)
409
- .onStart(() => {
410
- 'worklet'
411
- gestureStartOffset.value = translateOffset.value
412
- })
413
- .onUpdate((event) => {
414
- 'worklet'
415
- const translation = vertical ? event.translationY : event.translationX
416
- // Same SharedValue false positive as the open/close effect above (see its comment).
417
- // eslint-disable-next-line react-hooks/immutability
418
- translateOffset.value = Math.min(clampMax, Math.max(clampMin, gestureStartOffset.value + translation))
419
- })
420
- .onEnd((event) => {
421
- 'worklet'
422
- const velocity = vertical ? event.velocityY : event.velocityX
423
- // Everything below works in "closing-direction" units (closeDirection-normalized), where 0 is
424
- // always fully expanded and larger is always closer to closed, regardless of `side`'s sign
425
- // convention - the same trick the old single-segment formula used, just reused per segment.
426
- const velocityD = velocity * closeDirection
427
- const currentD = translateOffset.value * closeDirection
428
- const restD = restOffset * closeDirection // 0 when there's no maxHeight/maxWidth
429
- let target: number
430
- let closing = false
431
- if (currentD <= restD) {
432
- // Between rest (this segment's "start," at progress 0) and fully expanded (its far end, at
433
- // progress 1): traveled = restD - currentD, since currentD counts down from restD to 0 as
434
- // the drag moves toward expanding. Same 1/3-traveled threshold as the rest/closed segment
435
- // below, just scoped to this segment's own length and direction; a fast fling toward
436
- // expanding (velocityD very negative - the opposite sign from the closing fling below) also
437
- // commits, regardless of distance covered.
438
- const progress = restD > 0 ? (restD - currentD) / restD : 1
439
- target = progress > 1 / 3 || velocityD < -VELOCITY_THRESHOLD ? 0 : restOffset
440
- } else {
441
- // Between rest and fully closed. Identical formula (and, with no maxHeight/maxWidth, identical
442
- // numbers) to the pre-expansion version of this gesture: restD is 0 and this segment's own
443
- // length is effectiveSize, exactly like `effectiveSize` was the sole threshold denominator
444
- // before. Guarded the same way as the expand branch above, for the same reason (see
445
- // backdropStyle's comment): effectiveSize can be transiently 0 on web pre-hydration.
446
- const progress = effectiveSize > 0 ? (currentD - restD) / effectiveSize : 1
447
- closing = progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD
448
- target = closing ? closedOffset : restOffset
449
- }
450
- // Same SharedValue false positive as the open/close effect above (see its comment).
451
- // eslint-disable-next-line react-hooks/immutability
452
- translateOffset.value = withSpring(target, SPRING)
453
- if (closing) scheduleOnRN(callWorkletCallback, closeKey)
454
- })
442
+ // A peeking panel's handle stays live while closed, so it can be dragged open from the peek.
443
+ const withDragHandlers = (axisGesture: ReturnType<typeof makeAxisGesture>) =>
444
+ axisGesture
445
+ .enabled(open || peeks)
446
+ .onStart(() => {
447
+ 'worklet'
448
+ gestureStartOffset.value = translateOffset.value
449
+ })
450
+ .onUpdate((event) => {
451
+ 'worklet'
452
+ const translation = vertical ? event.translationY : event.translationX
453
+ // Same SharedValue false positive as the open/close effect above (see its comment).
454
+
455
+ translateOffset.value = Math.min(clampMax, Math.max(clampMin, gestureStartOffset.value + translation))
456
+ })
457
+ .onEnd((event) => {
458
+ 'worklet'
459
+ const velocity = vertical ? event.velocityY : event.velocityX
460
+ // Everything below works in "closing-direction" units (closeDirection-normalized), where 0 is
461
+ // always fully expanded and larger is always closer to closed, regardless of `side`'s sign
462
+ // convention - the same trick the old single-segment formula used, just reused per segment.
463
+ const velocityD = velocity * closeDirection
464
+ const currentD = translateOffset.value * closeDirection
465
+ const restD = restOffset * closeDirection // 0 when there's no maxHeight/maxWidth
466
+ let target: number
467
+ let closing = false
468
+ if (currentD <= restD) {
469
+ // Between rest (this segment's "start," at progress 0) and fully expanded (its far end, at
470
+ // progress 1): traveled = restD - currentD, since currentD counts down from restD to 0 as
471
+ // the drag moves toward expanding. Same 1/3-traveled threshold as the rest/closed segment
472
+ // below, just scoped to this segment's own length and direction; a fast fling toward
473
+ // expanding (velocityD very negative - the opposite sign from the closing fling below) also
474
+ // commits, regardless of distance covered.
475
+ const progress = restD > 0 ? (restD - currentD) / restD : 1
476
+ target = progress > 1 / 3 || velocityD < -VELOCITY_THRESHOLD ? 0 : restOffset
477
+ } else {
478
+ // Between rest and closed (the peek, when there is one). Identical formula (and, with no
479
+ // maxHeight/maxWidth or peek, identical numbers) to the pre-expansion version of this gesture:
480
+ // restD is 0 and this segment's own length is effectiveSize, exactly like `effectiveSize` was
481
+ // the sole threshold denominator before; a peek shortens the segment by what stays on screen.
482
+ // Guarded the same way as the expand branch above, for the same reason (see backdropStyle's
483
+ // comment): effectiveSize can be transiently 0 on web pre-hydration.
484
+ const segment = effectiveSize - peek
485
+ const progress = segment > 0 ? (currentD - restD) / segment : 1
486
+ // From the peek the same third counts the other way: dragged a third of the way open (two
487
+ // thirds left), or flung open, it commits open.
488
+ closing = open ? progress > 1 / 3 || velocityD > VELOCITY_THRESHOLD : !(progress < 2 / 3 || velocityD < -VELOCITY_THRESHOLD)
489
+ target = closing ? peekOffset : restOffset
490
+ }
491
+ // Opening from the peek always comes to rest first: the parent's `open` then springs it to
492
+ // restOffset anyway, so a drag past rest toward expanded isn't kept from a closed start.
493
+ if (!open && !closing) target = restOffset
494
+ // Same SharedValue false positive as the open/close effect above (see its comment).
495
+
496
+ translateOffset.value = withSpring(target, SPRING)
497
+ if (closing && open) scheduleOnRN(callWorkletCallback, closeKey)
498
+ if (!closing && !open) scheduleOnRN(callWorkletCallback, openKey)
499
+ })
500
+
501
+ const handleGesture = withDragHandlers(makeAxisGesture())
502
+ // A peeking panel drags by its content as well as its handle, open or at the peek: what peeks is
503
+ // what someone reaches for, as with a maps app's sheet. The pan only takes over once a finger has
504
+ // moved 10px along the axis, so a tap still reaches the content (a summary that opens on a tap, a
505
+ // button). Off without a peek, where content stays free of the panel's gestures as always.
506
+ const contentGesture = withDragHandlers(makeAxisGesture()).enabled(peeks)
455
507
 
456
508
  // The whole strip along the closed-direction edge is grabbable, flush against it, not just the
457
509
  // small pill drawn inside it, so there's nothing precise to aim for. It spans the full length of
@@ -488,7 +540,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
488
540
  // invisible margin around it grew.
489
541
  const handleStripPaddingStyle: ViewStyle = side === 'left' ? { paddingLeft: HANDLE_HIT_SLOP } : side === 'right' ? { paddingRight: HANDLE_HIT_SLOP } : side === 'top' ? { paddingTop: HANDLE_HIT_SLOP } : { paddingBottom: HANDLE_HIT_SLOP }
490
542
  const handlePillStyle: ViewStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 }
491
- const handleStripInteractionStyle: ViewStyle = { zIndex: zIndex + 2, pointerEvents: open ? 'auto' : 'none' }
543
+ const handleStripInteractionStyle: ViewStyle = { zIndex: zIndex + 2, pointerEvents: open || peeks ? 'auto' : 'none' }
492
544
  // react-native-web reads `cursor` straight off style; native ignores the unknown key. ViewStyle (the
493
545
  // native type these files are typed against) has no such property, hence the cast.
494
546
  const webCursorStyle = { cursor: Platform.OS === 'web' ? 'pointer' : undefined } as ViewStyle
@@ -575,7 +627,19 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
575
627
  intercepting anything even at full opacity. Absolutely filled to the panel's own current
576
628
  bounds, contentSize included, rather than a fixed size, so it tracks that animation too. */}
577
629
  {resolvedPanelShadow && <Animated.View pointerEvents='none' style={[StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle]} />}
578
- {contentSize ? <View style={contentClipStyle}>{fill}</View> : fill}
630
+ {peeks ? (
631
+ <GestureDetector gesture={contentGesture}>
632
+ {/* collapsable={false}: paint-free, so the native view flattener would otherwise remove it
633
+ and leave the detector nothing to attach to (see the backdrop's tap-catcher). */}
634
+ <View collapsable={false} style={StyleSheet.absoluteFill}>
635
+ {contentSize ? <View style={contentClipStyle}>{fill}</View> : fill}
636
+ </View>
637
+ </GestureDetector>
638
+ ) : contentSize ? (
639
+ <View style={contentClipStyle}>{fill}</View>
640
+ ) : (
641
+ fill
642
+ )}
579
643
  {dismissible && (
580
644
  <GestureDetector gesture={handleGesture}>
581
645
  {/* pointerEvents mirrors handleGesture's own .enabled(open) above, the same way the
@@ -4,7 +4,7 @@ import { type SharedValue, useDerivedValue, useSharedValue } from 'react-native-
4
4
 
5
5
  import { Drawer } from './Drawer'
6
6
  import { DrawerEdgeSwipe } from './DrawerEdgeSwipe'
7
- import { type DrawerDimension, type DrawerSide, getOpenDirection, isVerticalSide } from './geometry'
7
+ import { type DrawerDimension, type DrawerSide, getOpenDirection, getPeekOffset, isVerticalSide } from './geometry'
8
8
  import { useDrawerSize } from './useDrawerSize'
9
9
 
10
10
  export type DrawerActions = {
@@ -25,7 +25,8 @@ export type DrawerActions = {
25
25
  // True from open() through the full close animation, only dropping to false once the panel has
26
26
  // actually finished sliding away, unlike isOpen, which flips the instant close() is called. For
27
27
  // anything that needs to stay above/alongside the panel for as long as it's visually on screen
28
- // (e.g. a FAB row portaled above it) rather than disappearing the moment closing starts.
28
+ // (e.g. a FAB row portaled above it) rather than disappearing the moment closing starts. Always true
29
+ // for a drawer with a peek, which never leaves the screen.
29
30
  isVisible: boolean
30
31
  open: () => void
31
32
  }
@@ -52,6 +53,10 @@ export type CreateDrawerOptions = {
52
53
  maxHeight?: DrawerDimension
53
54
  // The maxWidth mirror of maxHeight, for `left`/`right` drawers.
54
55
  maxWidth?: DrawerDimension
56
+ // See Drawer's own peek doc: how much of the panel, in px, stays on screen while closed. Dragging its
57
+ // handle open, or calling open() (say from a tap on the peeking summary), opens it; closing comes
58
+ // back to the peek. The edge swipe is off for a drawer with a peek: the peeking panel is the way in.
59
+ peek?: number
55
60
  showHandle?: boolean
56
61
  side?: DrawerSide
57
62
  width?: DrawerDimension
@@ -82,6 +87,8 @@ export type DrawerInstanceProviderProps = {
82
87
  dismissible?: boolean
83
88
  // Lets a screen temporarily suppress the edge-swipe gesture (e.g. while another drawer is open).
84
89
  enabled?: boolean
90
+ // Overrides the peek passed to createDrawer() (if any) for this mount.
91
+ peek?: number
85
92
  // Overrides the showHandle passed to createDrawer() (if any) for this mount.
86
93
  showHandle?: boolean
87
94
  // Overrides the zIndex passed to createDrawer() (if any) for this mount.
@@ -97,7 +104,7 @@ const noop = () => {}
97
104
 
98
105
  // One call per drawer instance: each gets its own Context, so a left nav drawer and a right
99
106
  // settings drawer (say) stay fully independent without a stringly-typed id to keep them apart.
100
- export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, showHandle: factoryShowHandle, side = 'left', width = 300, zIndex: factoryZIndex }: CreateDrawerOptions = {}): CreateDrawerResult => {
107
+ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, peek: factoryPeek, showHandle: factoryShowHandle, side = 'left', width = 300, zIndex: factoryZIndex }: CreateDrawerOptions = {}): CreateDrawerResult => {
101
108
  // Static, non-reactive stand-in for the default context value only (before any real Provider has
102
109
  // mounted) - same reasoning as the plain `noop` functions alongside it.
103
110
  const defaultExpandProgress = { value: 1 } as SharedValue<number>
@@ -107,11 +114,13 @@ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blocking
107
114
  const maxSize = vertical ? maxHeight : maxWidth
108
115
  const closeDirection = -getOpenDirection(side)
109
116
 
110
- const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, showHandle: showHandleOverride, zIndex: zIndexOverride }: DrawerInstanceProviderProps): JSX.Element => {
117
+ const DrawerInstanceProvider = ({ backdropOpacity: backdropOpacityOverride, blockingBackdrop: blockingBackdropOverride, blur: blurOverride, children, closeOnBackPress: closeOnBackPressOverride, content, contentSize: contentSizeOverride, dismissible: dismissibleOverride, enabled = true, peek: peekOverride, showHandle: showHandleOverride, zIndex: zIndexOverride }: DrawerInstanceProviderProps): JSX.Element => {
118
+ const peek = peekOverride ?? factoryPeek ?? 0
111
119
  const [isOpen, setIsOpen] = useState(false)
112
120
  // Starts in lockstep with isOpen (both false) and stays true past isOpen turning false, until
113
121
  // Drawer's onClosed reports the outro spring has actually settled: see the isVisible field above.
114
- const [isVisible, setIsVisible] = useState(false)
122
+ // A peeking panel is never off screen, so it's always visible.
123
+ const [isVisible, setIsVisible] = useState(peek > 0)
115
124
  const [measuredSize, setMeasuredSize] = useState<number | null>(null)
116
125
  const backdropOpacity = backdropOpacityOverride ?? factoryBackdropOpacity ?? 0.45
117
126
  const blur = blurOverride ?? factoryBlur
@@ -132,8 +141,8 @@ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blocking
132
141
  // createDrawer needs it directly - both for translateOffset's own initial seed, and restOffset
133
142
  // for expandProgress below. contentSize never gets a maxSize (mirrors Drawer's own
134
143
  // contentSize-has-no-expand-ceiling rule), so expandProgress is always a flat 1 there too.
135
- const { closedOffset, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? undefined : maxSize, edgeInset)
136
- const translateOffset = useSharedValue(closedOffset)
144
+ const { maxEffectiveSize, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? undefined : maxSize, edgeInset)
145
+ const translateOffset = useSharedValue(getPeekOffset(side, maxEffectiveSize, peek))
137
146
  // See DrawerActions' own doc comment for what this computes, and geometry.ts's getExpandProgress
138
147
  // (kept in sync, tested there directly) for the same formula explained in more depth. Inlined
139
148
  // rather than calling that shared helper: react-native-worklets (Reanimated 4+) only forwards a
@@ -181,8 +190,8 @@ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blocking
181
190
  return (
182
191
  <DrawerActionsContext.Provider value={actions}>
183
192
  {children}
184
- <DrawerEdgeSwipe edgeInset={edgeInset} enabled={enabled && !isOpen} height={vertical ? effectiveSize : height} maxHeight={maxHeight} maxWidth={maxWidth} onOpen={open} side={side} translateOffset={translateOffset} width={vertical ? width : effectiveSize} />
185
- <Drawer backdropOpacity={backdropOpacity} blockingBackdrop={blockingBackdrop} blur={blur} contentSize={contentSize} dismissible={dismissible} edgeInset={edgeInset} height={vertical ? effectiveSize : height} maxHeight={maxHeight} maxWidth={maxWidth} onClose={() => setIsOpen(false)} onClosed={() => setIsVisible(false)} onMeasure={setMeasuredSize} open={isOpen} showHandle={showHandle} side={side} translateOffset={translateOffset} width={vertical ? width : effectiveSize} zIndex={zIndex}>
193
+ <DrawerEdgeSwipe edgeInset={edgeInset} enabled={enabled && !isOpen && peek <= 0} height={vertical ? effectiveSize : height} maxHeight={maxHeight} maxWidth={maxWidth} onOpen={open} side={side} translateOffset={translateOffset} width={vertical ? width : effectiveSize} />
194
+ <Drawer backdropOpacity={backdropOpacity} blockingBackdrop={blockingBackdrop} blur={blur} contentSize={contentSize} dismissible={dismissible} edgeInset={edgeInset} height={vertical ? effectiveSize : height} maxHeight={maxHeight} maxWidth={maxWidth} onClose={() => setIsOpen(false)} onClosed={() => setIsVisible(peek > 0)} onMeasure={setMeasuredSize} onOpen={open} open={isOpen} peek={peek} showHandle={showHandle} side={side} translateOffset={translateOffset} width={vertical ? width : effectiveSize} zIndex={zIndex}>
186
195
  {content}
187
196
  </Drawer>
188
197
  </DrawerActionsContext.Provider>
package/src/geometry.ts CHANGED
@@ -17,6 +17,13 @@ export function getClosedOffset(side: DrawerSide, size: number): number {
17
17
  return size === 0 ? 0 : side === 'left' || side === 'top' ? -size : size
18
18
  }
19
19
 
20
+ // Where a closed panel with a resting peek sits: `peek` px of its `size` still on screen, the rest
21
+ // past its edge. Same sign convention as getClosedOffset, which it equals for a peek of 0. A peek at
22
+ // or past the panel's size leaves it fully on screen; a negative one counts as 0.
23
+ export function getPeekOffset(side: DrawerSide, size: number, peek: number): number {
24
+ return getClosedOffset(side, Math.max(0, size - Math.max(0, peek)))
25
+ }
26
+
20
27
  // Which drag direction (along the relevant axis) counts as "opening".
21
28
  export function getOpenDirection(side: DrawerSide): 1 | -1 {
22
29
  return side === 'left' || side === 'top' ? 1 : -1