@rific/drawer 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -52,6 +52,12 @@ declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderCompon
52
52
  children?: ReactNode;
53
53
  }) => JSX.Element;
54
54
 
55
+ type DrawerPanelShadow = {
56
+ blurRadius?: number;
57
+ color?: string;
58
+ distance?: number;
59
+ elevation?: number;
60
+ };
55
61
  type DrawerProps = {
56
62
  backdropOpacity?: number;
57
63
  blockingBackdrop?: boolean;
@@ -68,13 +74,14 @@ type DrawerProps = {
68
74
  onMeasure?: (size: number) => void;
69
75
  onOpened?: () => void;
70
76
  open: boolean;
77
+ panelShadow?: boolean | DrawerPanelShadow;
71
78
  side?: DrawerSide;
72
79
  showHandle?: boolean;
73
80
  translateOffset?: SharedValue<number>;
74
81
  width?: DrawerDimension;
75
82
  zIndex?: number;
76
83
  };
77
- declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
84
+ 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;
78
85
 
79
86
  type AutoPaperModule = {
80
87
  BlurView: ComponentType<{
package/dist/index.d.ts CHANGED
@@ -52,6 +52,12 @@ declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderCompon
52
52
  children?: ReactNode;
53
53
  }) => JSX.Element;
54
54
 
55
+ type DrawerPanelShadow = {
56
+ blurRadius?: number;
57
+ color?: string;
58
+ distance?: number;
59
+ elevation?: number;
60
+ };
55
61
  type DrawerProps = {
56
62
  backdropOpacity?: number;
57
63
  blockingBackdrop?: boolean;
@@ -68,13 +74,14 @@ type DrawerProps = {
68
74
  onMeasure?: (size: number) => void;
69
75
  onOpened?: () => void;
70
76
  open: boolean;
77
+ panelShadow?: boolean | DrawerPanelShadow;
71
78
  side?: DrawerSide;
72
79
  showHandle?: boolean;
73
80
  translateOffset?: SharedValue<number>;
74
81
  width?: DrawerDimension;
75
82
  zIndex?: number;
76
83
  };
77
- declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, edgeInset, height, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
84
+ 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;
78
85
 
79
86
  type AutoPaperModule = {
80
87
  BlurView: ComponentType<{
package/dist/index.js CHANGED
@@ -46,7 +46,6 @@ var import_react_native4 = require("react-native");
46
46
  var import_react_native_reanimated3 = require("react-native-reanimated");
47
47
 
48
48
  // src/Drawer.tsx
49
- var import_haptic_press = require("@rific/haptic-press");
50
49
  var import_react = require("react");
51
50
  var import_react_native2 = require("react-native");
52
51
  var import_react_native_gesture_handler = require("react-native-gesture-handler");
@@ -97,12 +96,20 @@ var import_jsx_runtime2 = require("react/jsx-runtime");
97
96
  var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
98
97
  var VELOCITY_THRESHOLD = 500;
99
98
  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, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
99
+ 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 }) => {
101
100
  const { colors } = (0, import_react_native_paper.useTheme)();
102
101
  const vertical = isVerticalSide(side);
103
102
  const openDirection = getOpenDirection(side);
104
103
  const closeDirection = -openDirection;
104
+ const resolvedPanelShadow = panelShadow === true ? {} : panelShadow || null;
105
+ const panelShadowDistance = resolvedPanelShadow?.distance ?? 2;
106
+ const panelShadowBlurRadius = resolvedPanelShadow?.blurRadius ?? 8;
107
+ const panelShadowColor = resolvedPanelShadow?.color ?? "rgba(0, 0, 0, 0.3)";
108
+ const panelShadowElevation = resolvedPanelShadow?.elevation ?? panelShadowBlurRadius;
109
+ const panelShadowMagnitude = panelShadowDistance * openDirection;
110
+ const panelShadowStyle = { boxShadow: [{ offsetX: vertical ? 0 : panelShadowMagnitude, offsetY: vertical ? panelShadowMagnitude : 0, blurRadius: panelShadowBlurRadius, color: panelShadowColor }], elevation: panelShadowElevation };
105
111
  const [measuredSize, setMeasuredSize] = (0, import_react.useState)(null);
112
+ const lastMeasuredRef = (0, import_react.useRef)(null);
106
113
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
107
114
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
108
115
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
@@ -130,10 +137,13 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
130
137
  const drawerStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => ({ transform: [vertical ? { translateY: translateOffset.value } : { translateX: translateOffset.value }] }));
131
138
  const backdropStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }));
132
139
  const animatedSizeStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => vertical ? { height: animatedSize.value } : { width: animatedSize.value });
140
+ const backdropInteractionStyle = { zIndex, pointerEvents: open && blockingBackdrop ? "auto" : "none" };
133
141
  const positionStyle = side === "left" ? styles.anchorLeft : side === "right" ? styles.anchorRight : side === "top" ? styles.anchorTop : styles.anchorBottom;
134
142
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize };
135
143
  const handleLayout = (event) => {
136
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width;
144
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width);
145
+ if (lastMeasuredRef.current === measured) return;
146
+ lastMeasuredRef.current = measured;
137
147
  setMeasuredSize(measured);
138
148
  onMeasure?.(measured);
139
149
  };
@@ -151,6 +161,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
151
161
  const clampMax = Math.max(0, closedOffset);
152
162
  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]);
153
163
  const gestureStartOffset = (0, import_react_native_reanimated.useSharedValue)(closedOffset);
164
+ const backdropTapGesture = import_react_native_gesture_handler.Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
165
+ if (success) (0, import_react_native_reanimated.runOnJS)(onClose)();
166
+ });
154
167
  const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
155
168
  "worklet";
156
169
  gestureStartOffset.value = translateOffset.value;
@@ -185,16 +198,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
185
198
  const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
186
199
  const handleStripPaddingStyle = side === "left" ? { paddingLeft: HANDLE_HIT_SLOP } : side === "right" ? { paddingRight: HANDLE_HIT_SLOP } : side === "top" ? { paddingTop: HANDLE_HIT_SLOP } : { paddingBottom: HANDLE_HIT_SLOP };
187
200
  const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
188
- const webCursorStyle = { cursor: import_react_native2.Platform.OS === "web" ? "pointer" : void 0 };
201
+ const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
202
+ const webCursorStyle2 = { cursor: import_react_native2.Platform.OS === "web" ? "pointer" : void 0 };
189
203
  const handleVisibilityStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
190
204
  const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
191
205
  return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
192
206
  });
207
+ const panelShadowFadeDistance = panelShadowBlurRadius + panelShadowDistance;
208
+ const panelShadowVisibilityStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
209
+ const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
210
+ return { opacity: Math.min(1, Math.max(0, visibleSize / panelShadowFadeDistance)) };
211
+ });
193
212
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
194
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.backdrop, { zIndex }, backdropStyle], pointerEvents: open && blockingBackdrop ? "auto" : "none", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_haptic_press.Pressable, { style: import_react_native2.StyleSheet.absoluteFill, onPress: onClose }) }),
213
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: [styles.backdropPosition, backdropInteractionStyle], children: [
214
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
215
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_gesture_handler.GestureDetector, { gesture: backdropTapGesture, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { collapsable: false, style: import_react_native2.StyleSheet.absoluteFill }) })
216
+ ] }),
195
217
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: drawerOuterStyle, children: [
218
+ resolvedPanelShadow && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { pointerEvents: "none", style: [import_react_native2.StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle] }),
196
219
  contentSize ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill,
197
- dismissible && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_gesture_handler.GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle, handleVisibilityStyle, { zIndex: zIndex + 2 }], children: showHandle && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
220
+ dismissible && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_gesture_handler.GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle2, handleVisibilityStyle, handleStripInteractionStyle], children: showHandle && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
198
221
  ] })
199
222
  ] });
200
223
  };
@@ -219,7 +242,14 @@ var styles = import_react_native2.StyleSheet.create({
219
242
  right: 0,
220
243
  top: 0
221
244
  },
222
- backdrop: {
245
+ backdropPosition: {
246
+ bottom: 0,
247
+ left: 0,
248
+ position: "absolute",
249
+ right: 0,
250
+ top: 0
251
+ },
252
+ backdropTint: {
223
253
  backgroundColor: "#000",
224
254
  bottom: 0,
225
255
  left: 0,
@@ -275,8 +305,9 @@ var DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, maxHeight,
275
305
  }
276
306
  });
277
307
  const edgeStyle = vertical ? [styles2.edgeHorizontal, side === "top" ? styles2.top : styles2.bottom] : [styles2.edgeVertical, side === "left" ? styles2.left : styles2.right];
278
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_gesture_handler2.GestureDetector, { gesture, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: edgeStyle }) });
308
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_gesture_handler2.GestureDetector, { gesture, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: [...edgeStyle, webCursorStyle] }) });
279
309
  };
310
+ var webCursorStyle = { cursor: import_react_native3.Platform.OS === "web" ? "pointer" : void 0 };
280
311
  var styles2 = import_react_native3.StyleSheet.create({
281
312
  bottom: { bottom: 0 },
282
313
  edgeHorizontal: {
package/dist/index.mjs CHANGED
@@ -4,8 +4,7 @@ import { BackHandler } from "react-native";
4
4
  import { useDerivedValue, useSharedValue as useSharedValue2 } from "react-native-reanimated";
5
5
 
6
6
  // src/Drawer.tsx
7
- import { Pressable } from "@rific/haptic-press";
8
- import { useEffect, useState } from "react";
7
+ import { useEffect, useRef, useState } from "react";
9
8
  import { Platform, StyleSheet, View } from "react-native";
10
9
  import { Gesture, GestureDetector } from "react-native-gesture-handler";
11
10
  import { useTheme } from "react-native-paper";
@@ -55,12 +54,20 @@ import { Fragment as Fragment2, jsx as jsx2, jsxs } from "react/jsx-runtime";
55
54
  var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
56
55
  var VELOCITY_THRESHOLD = 500;
57
56
  var useBlurFallback = (override) => override ?? false;
58
- var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children, contentSize = false, dismissible = true, edgeInset = 0, height = 300, maxHeight, maxWidth, onClose, onClosed, onMeasure, onOpened, open, side = "left", showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }) => {
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 }) => {
59
58
  const { colors } = useTheme();
60
59
  const vertical = isVerticalSide(side);
61
60
  const openDirection = getOpenDirection(side);
62
61
  const closeDirection = -openDirection;
62
+ const resolvedPanelShadow = panelShadow === true ? {} : panelShadow || null;
63
+ const panelShadowDistance = resolvedPanelShadow?.distance ?? 2;
64
+ const panelShadowBlurRadius = resolvedPanelShadow?.blurRadius ?? 8;
65
+ const panelShadowColor = resolvedPanelShadow?.color ?? "rgba(0, 0, 0, 0.3)";
66
+ const panelShadowElevation = resolvedPanelShadow?.elevation ?? panelShadowBlurRadius;
67
+ const panelShadowMagnitude = panelShadowDistance * openDirection;
68
+ const panelShadowStyle = { boxShadow: [{ offsetX: vertical ? 0 : panelShadowMagnitude, offsetY: vertical ? panelShadowMagnitude : 0, blurRadius: panelShadowBlurRadius, color: panelShadowColor }], elevation: panelShadowElevation };
63
69
  const [measuredSize, setMeasuredSize] = useState(null);
70
+ const lastMeasuredRef = useRef(null);
64
71
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
65
72
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
66
73
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
@@ -88,10 +95,13 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
88
95
  const drawerStyle = useAnimatedStyle(() => ({ transform: [vertical ? { translateY: translateOffset.value } : { translateX: translateOffset.value }] }));
89
96
  const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }));
90
97
  const animatedSizeStyle = useAnimatedStyle(() => vertical ? { height: animatedSize.value } : { width: animatedSize.value });
98
+ const backdropInteractionStyle = { zIndex, pointerEvents: open && blockingBackdrop ? "auto" : "none" };
91
99
  const positionStyle = side === "left" ? styles.anchorLeft : side === "right" ? styles.anchorRight : side === "top" ? styles.anchorTop : styles.anchorBottom;
92
100
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize };
93
101
  const handleLayout = (event) => {
94
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width;
102
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width);
103
+ if (lastMeasuredRef.current === measured) return;
104
+ lastMeasuredRef.current = measured;
95
105
  setMeasuredSize(measured);
96
106
  onMeasure?.(measured);
97
107
  };
@@ -109,6 +119,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
109
119
  const clampMax = Math.max(0, closedOffset);
110
120
  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]);
111
121
  const gestureStartOffset = useSharedValue(closedOffset);
122
+ const backdropTapGesture = Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
123
+ if (success) runOnJS(onClose)();
124
+ });
112
125
  const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
113
126
  "worklet";
114
127
  gestureStartOffset.value = translateOffset.value;
@@ -143,16 +156,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
143
156
  const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
144
157
  const handleStripPaddingStyle = side === "left" ? { paddingLeft: HANDLE_HIT_SLOP } : side === "right" ? { paddingRight: HANDLE_HIT_SLOP } : side === "top" ? { paddingTop: HANDLE_HIT_SLOP } : { paddingBottom: HANDLE_HIT_SLOP };
145
158
  const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
146
- const webCursorStyle = { cursor: Platform.OS === "web" ? "pointer" : void 0 };
159
+ const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
160
+ const webCursorStyle2 = { cursor: Platform.OS === "web" ? "pointer" : void 0 };
147
161
  const handleVisibilityStyle = useAnimatedStyle(() => {
148
162
  const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
149
163
  return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
150
164
  });
165
+ const panelShadowFadeDistance = panelShadowBlurRadius + panelShadowDistance;
166
+ const panelShadowVisibilityStyle = useAnimatedStyle(() => {
167
+ const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
168
+ return { opacity: Math.min(1, Math.max(0, visibleSize / panelShadowFadeDistance)) };
169
+ });
151
170
  return /* @__PURE__ */ jsxs(Fragment2, { children: [
152
- /* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdrop, { zIndex }, backdropStyle], pointerEvents: open && blockingBackdrop ? "auto" : "none", children: /* @__PURE__ */ jsx2(Pressable, { style: StyleSheet.absoluteFill, onPress: onClose }) }),
171
+ /* @__PURE__ */ jsxs(Animated.View, { style: [styles.backdropPosition, backdropInteractionStyle], children: [
172
+ /* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
173
+ /* @__PURE__ */ jsx2(GestureDetector, { gesture: backdropTapGesture, children: /* @__PURE__ */ jsx2(Animated.View, { collapsable: false, style: StyleSheet.absoluteFill }) })
174
+ ] }),
153
175
  /* @__PURE__ */ jsxs(Animated.View, { style: drawerOuterStyle, children: [
176
+ resolvedPanelShadow && /* @__PURE__ */ jsx2(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle] }),
154
177
  contentSize ? /* @__PURE__ */ jsx2(View, { style: contentClipStyle, children: fill }) : fill,
155
- dismissible && /* @__PURE__ */ jsx2(GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ jsx2(Animated.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle, handleVisibilityStyle, { zIndex: zIndex + 2 }], children: showHandle && /* @__PURE__ */ jsx2(View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
178
+ dismissible && /* @__PURE__ */ jsx2(GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ jsx2(Animated.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle2, handleVisibilityStyle, handleStripInteractionStyle], children: showHandle && /* @__PURE__ */ jsx2(View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
156
179
  ] })
157
180
  ] });
158
181
  };
@@ -177,7 +200,14 @@ var styles = StyleSheet.create({
177
200
  right: 0,
178
201
  top: 0
179
202
  },
180
- backdrop: {
203
+ backdropPosition: {
204
+ bottom: 0,
205
+ left: 0,
206
+ position: "absolute",
207
+ right: 0,
208
+ top: 0
209
+ },
210
+ backdropTint: {
181
211
  backgroundColor: "#000",
182
212
  bottom: 0,
183
213
  left: 0,
@@ -202,7 +232,7 @@ var styles = StyleSheet.create({
202
232
  });
203
233
 
204
234
  // src/DrawerEdgeSwipe.tsx
205
- import { StyleSheet as StyleSheet2, View as View2 } from "react-native";
235
+ import { Platform as Platform2, StyleSheet as StyleSheet2, View as View2 } from "react-native";
206
236
  import { Gesture as Gesture2, GestureDetector as GestureDetector2 } from "react-native-gesture-handler";
207
237
  import { runOnJS as runOnJS2, withSpring as withSpring2 } from "react-native-reanimated";
208
238
  import { jsx as jsx3 } from "react/jsx-runtime";
@@ -233,8 +263,9 @@ var DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, maxHeight,
233
263
  }
234
264
  });
235
265
  const edgeStyle = vertical ? [styles2.edgeHorizontal, side === "top" ? styles2.top : styles2.bottom] : [styles2.edgeVertical, side === "left" ? styles2.left : styles2.right];
236
- return /* @__PURE__ */ jsx3(GestureDetector2, { gesture, children: /* @__PURE__ */ jsx3(View2, { style: edgeStyle }) });
266
+ return /* @__PURE__ */ jsx3(GestureDetector2, { gesture, children: /* @__PURE__ */ jsx3(View2, { style: [...edgeStyle, webCursorStyle] }) });
237
267
  };
268
+ var webCursorStyle = { cursor: Platform2.OS === "web" ? "pointer" : void 0 };
238
269
  var styles2 = StyleSheet2.create({
239
270
  bottom: { bottom: 0 },
240
271
  edgeHorizontal: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rific/drawer",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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
@@ -1,5 +1,4 @@
1
- import { Pressable } from '@rific/haptic-press'
2
- import { ReactNode, useEffect, useState } from 'react'
1
+ import { ReactNode, useEffect, useRef, useState } from 'react'
3
2
  import { LayoutChangeEvent, Platform, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
4
3
  import { Gesture, GestureDetector } from 'react-native-gesture-handler'
5
4
  import { useTheme } from 'react-native-paper'
@@ -29,6 +28,28 @@ const VELOCITY_THRESHOLD = 500
29
28
  // fallback stands in when auto-paper isn't configured, so a per-render branch isn't needed.
30
29
  const useBlurFallback = (override?: boolean) => override ?? false
31
30
 
31
+ export type DrawerPanelShadow = {
32
+ blurRadius?: number
33
+ color?: string
34
+ // Magnitude only, in px — always positive, regardless of `side`. The actual signed offset
35
+ // (which way the shadow falls) is derived from `side` internally, the same way DrawerEdgeSwipe
36
+ // derives its own opening direction from it: a consumer supplying the wrong sign for a
37
+ // right/bottom-anchored panel (an easy mistake — see this prop's own top-level doc comment) is
38
+ // exactly the bug this exists to make impossible.
39
+ distance?: number
40
+ // Android's own native shadow system, alongside (not instead of) the boxShadow above — the two
41
+ // aren't redundant: boxShadow is what actually paints on iOS/web, and while the New
42
+ // Architecture's Fabric renderer does translate boxShadow to a real shadow on Android too,
43
+ // elevation is the longer-established, better-tested path there and worth keeping as a belt-
44
+ // and-suspenders fallback rather than trusting boxShadow alone on every Android/RN version this
45
+ // could run on. Defaults to blurRadius itself — the same plain magnitude-to-elevation
46
+ // correspondence a consumer would otherwise hand-roll (this mirrors what this repo's own past
47
+ // panelContent styles, now replaced by this prop, always did: elevation set to the same number
48
+ // as blurRadius). Rendered on the SAME view panelShadowVisibilityStyle animates the opacity of,
49
+ // so it fades in/out right along with the boxShadow rather than needing its own logic.
50
+ elevation?: number
51
+ }
52
+
32
53
  export type DrawerProps = {
33
54
  // Peak backdrop opacity once fully open (scaled down as the panel slides toward closed, same as
34
55
  // before): 0 renders no dimming at all, letting whatever's behind the panel stay fully visible.
@@ -88,6 +109,16 @@ export type DrawerProps = {
88
109
  // autofocusing a field inside `content` only once it's actually on screen.
89
110
  onOpened?: () => void
90
111
  open: boolean
112
+ // Off by default (this is a real, paid render — an extra always-mounted Animated.View — not
113
+ // free to opt every consumer into). true uses sensible defaults (2px distance, 8px blur, 30%
114
+ // black); pass a DrawerPanelShadow to override any of those. Opacity fades in/out together with
115
+ // the handle strip's own pill (both driven by the same visibleSize), rather than being either
116
+ // permanently on or permanently off: a plain static shadow on the panel bleeds past its own
117
+ // blurRadius even while `open` is false and the panel is translated fully off-screen, since a
118
+ // closed panel sits exactly flush against the screen edge (translateOffset === closedOffset) —
119
+ // shadow rendering doesn't know or care that its box is off-screen, so a few px of blur reads as
120
+ // a permanent, unwanted line along that edge, closed or not.
121
+ panelShadow?: boolean | DrawerPanelShadow
91
122
  side?: DrawerSide
92
123
  // Whether the handle strip's own visual pill graphic draws, independent of `dismissible`, which
93
124
  // controls the strip (and its drag-to-dismiss gesture) as a whole. false keeps the strip's hit area
@@ -107,13 +138,27 @@ export type DrawerProps = {
107
138
  zIndex?: number
108
139
  }
109
140
 
110
- 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, side = 'left', showHandle = true, translateOffset: externalTranslateOffset, width = 300, zIndex = 50 }: DrawerProps) => {
141
+ 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) => {
111
142
  const { colors } = useTheme()
112
143
  const vertical = isVerticalSide(side)
113
144
  const openDirection = getOpenDirection(side)
114
145
  const closeDirection = -openDirection as 1 | -1
146
+ const resolvedPanelShadow = panelShadow === true ? {} : panelShadow || null
147
+ const panelShadowDistance = resolvedPanelShadow?.distance ?? 2
148
+ const panelShadowBlurRadius = resolvedPanelShadow?.blurRadius ?? 8
149
+ const panelShadowColor = resolvedPanelShadow?.color ?? 'rgba(0, 0, 0, 0.3)'
150
+ const panelShadowElevation = resolvedPanelShadow?.elevation ?? panelShadowBlurRadius
151
+ // Same sign convention as the "opens toward" direction below (openDirection: 1 for left/top, -1
152
+ // for right/bottom): a panel's shadow always falls AWAY from the panel, onto whatever content
153
+ // sits on its open side — which is exactly the side its own drag-to-open motion points toward.
154
+ const panelShadowMagnitude = panelShadowDistance * openDirection
155
+ const panelShadowStyle: ViewStyle = { boxShadow: [{ offsetX: vertical ? 0 : panelShadowMagnitude, offsetY: vertical ? panelShadowMagnitude : 0, blurRadius: panelShadowBlurRadius, color: panelShadowColor }], elevation: panelShadowElevation }
115
156
 
116
157
  const [measuredSize, setMeasuredSize] = useState<number | null>(null)
158
+ // Tracks the last value actually committed to measuredSize, rounded — see handleLayout below for
159
+ // why the comparison has to happen against this rather than just re-deriving it from measuredSize
160
+ // itself on every call.
161
+ const lastMeasuredRef = useRef<number | null>(null)
117
162
  // contentSize measures its own box from natural content size, so it has no separate rest-vs-max
118
163
  // concept: maxHeight/maxWidth (the drag-to-expand ceiling) only apply in the fixed-size path.
119
164
  // height/width remain the pre-measurement placeholder until the first layout, same as before.
@@ -166,14 +211,29 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
166
211
  // transparent, matching "closed," since a not-yet-sized panel isn't meaningfully open yet either.
167
212
  const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }))
168
213
  const animatedSizeStyle = useAnimatedStyle(() => (vertical ? { height: animatedSize.value } : { width: animatedSize.value }))
214
+ const backdropInteractionStyle: ViewStyle = { zIndex, pointerEvents: open && blockingBackdrop ? 'auto' : 'none' }
169
215
 
170
216
  const positionStyle = side === 'left' ? styles.anchorLeft : side === 'right' ? styles.anchorRight : side === 'top' ? styles.anchorTop : styles.anchorBottom
171
217
  // maxEffectiveSize, not the raw height/width prop: the box must be big enough to show the panel
172
218
  // fully expanded, even though it usually only shows effectiveSize px of that at rest.
173
219
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize }
174
220
 
221
+ // Rounded (not the raw sub-pixel float layout reports) and short-circuited against the last value
222
+ // actually committed: an animated ancestor (animatedSizeStyle below, mid-withTiming) can cause
223
+ // Yoga to re-measure this supposedly content-unconstrained wrapper on every frame it's still
224
+ // moving, and floating-point noise between passes (e.g. 283.3333740234375 vs 283.33331298828125 —
225
+ // the same logical height, off by ~1/16000th of a pixel) is "different" by strict equality. Left
226
+ // unguarded, that noise commits a "new" measuredSize every frame, which restarts the very
227
+ // withTiming animation that's causing the re-measurement in the first place — a self-sustaining
228
+ // loop that never lets the height settle, seen as a stutter rather than a single smooth resize.
229
+ // Comparing against a ref (not measuredSize itself) matters here: measuredSize is the state that's
230
+ // deliberately being skipped on a no-op call, so re-deriving the comparison from it would still
231
+ // see the same (unchanged) value next time regardless — the ref is what actually remembers what
232
+ // was last committed.
175
233
  const handleLayout = (event: LayoutChangeEvent) => {
176
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width
234
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width)
235
+ if (lastMeasuredRef.current === measured) return
236
+ lastMeasuredRef.current = measured
177
237
  setMeasuredSize(measured)
178
238
  onMeasure?.(measured)
179
239
  }
@@ -209,6 +269,16 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
209
269
  ) : (
210
270
  <View style={[fillStyle, { backgroundColor: colors.surface }]}>{children}</View>
211
271
  )
272
+ // contentSize's measuring wrapper above is deliberately given no style of its own (see the
273
+ // comment above `fillStyle`): it must report ITS OWN natural size, which only works if `children`
274
+ // itself has an intrinsic height Yoga can compute directly from its subtree — e.g. plain
275
+ // Views/Text/FABs, including a `flexWrap: 'wrap'` row like FabRow. A `ScrollView` breaks this: on
276
+ // native, ScrollView's outer box does NOT size itself to its content the way a plain View does —
277
+ // it needs a bounded height from an ANCESTOR instead (see ScrollView's own docs) — so measuring
278
+ // one via onLayout here reports some small, real-but-wrong box height (whatever Yoga happens to
279
+ // resolve it to absent an explicit bound) rather than the content's true extent, and clips
280
+ // anything beyond that. contentSize's `children` must render its own natural-height content
281
+ // directly (no ScrollView) for this measurement to be meaningful.
212
282
 
213
283
  // Deliberately NOT clipped (no overflow: hidden here, unlike the contentSize clip wrapper below):
214
284
  // the handle strip is a child of this view, positioned outside its bounds (see
@@ -254,6 +324,17 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
254
324
  // needs to offset from wherever the panel actually was, not always from rest.
255
325
  const gestureStartOffset = useSharedValue(closedOffset)
256
326
 
327
+ // react-native-gesture-handler's own Tap, not @rific/haptic-press's plain-RN Pressable: this
328
+ // sits in the same GestureDetector-based system as the panel's own drag handle below, rather
329
+ // than mixing RNGH's native recognizers with RN's separate classic responder system on the one
330
+ // view in the tree (the backdrop) that most needs to reliably win a touch over whatever's behind
331
+ // it, including a consumer's own full-screen canvas gestures (e.g. Swirlio's pan/pinch/rotation).
332
+ const backdropTapGesture = Gesture.Tap()
333
+ .enabled(open && blockingBackdrop)
334
+ .onEnd((_event, success) => {
335
+ if (success) runOnJS(onClose)()
336
+ })
337
+
257
338
  const handleGesture = handleAxisGesture
258
339
  .enabled(open)
259
340
  .onStart(() => {
@@ -334,6 +415,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
334
415
  // invisible margin around it grew.
335
416
  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 }
336
417
  const handlePillStyle: ViewStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 }
418
+ const handleStripInteractionStyle: ViewStyle = { zIndex: zIndex + 2, pointerEvents: open ? 'auto' : 'none' }
337
419
  // react-native-web reads `cursor` straight off style; native ignores the unknown key. ViewStyle (the
338
420
  // native type these files are typed against) has no such property, hence the cast.
339
421
  const webCursorStyle = { cursor: Platform.OS === 'web' ? 'pointer' : undefined } as ViewStyle
@@ -351,16 +433,61 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
351
433
  return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 }
352
434
  })
353
435
 
436
+ // Ramps smoothly over the shadow's own visual extent (how far its blur can actually reach past
437
+ // the panel's true edge) rather than snapping like the handle strip's own binary visibleSize
438
+ // check above: by the time visibleSize passes that point, the panel edge itself is already
439
+ // further onto the screen than the shadow ever bled, so there's no longer a "fake" shadow to
440
+ // distinguish from a real one — full opacity is correct from there on. Always computed (hooks
441
+ // can't be called conditionally) even when panelShadow is falsy; harmless, since the style is
442
+ // never applied to anything in that case.
443
+ const panelShadowFadeDistance = panelShadowBlurRadius + panelShadowDistance
444
+ const panelShadowVisibilityStyle = useAnimatedStyle(() => {
445
+ const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection
446
+ return { opacity: Math.min(1, Math.max(0, visibleSize / panelShadowFadeDistance)) }
447
+ })
448
+
354
449
  return (
355
450
  <>
356
- <Animated.View style={[styles.backdrop, { zIndex }, backdropStyle]} pointerEvents={open && blockingBackdrop ? 'auto' : 'none'}>
357
- <Pressable style={StyleSheet.absoluteFill} onPress={onClose} />
451
+ <Animated.View style={[styles.backdropPosition, backdropInteractionStyle]}>
452
+ {/* The dimming tint is its own child, carrying the actual black backgroundColor and
453
+ backdropStyle's animated opacity, separate from the tap-catching view below and from the
454
+ OUTER container above (which must stay paint-free, not just visually transparent at
455
+ opacity 0): on iOS, a view at opacity 0 (e.g. backdropOpacity={0}, an intentional no-dim
456
+ backdrop — see controlGroups.tsx) is excluded from hit-testing entirely by UIKit,
457
+ regardless of pointerEvents. That's fine for a purely decorative tint, but it would
458
+ silently make the whole backdrop untouchable too if the SAME view carried both — and if
459
+ the outer container carried the background color instead, it would paint solid black at
460
+ full opacity at all times (no animated opacity of its own), open or not. */}
461
+ <Animated.View style={[styles.backdropTint, backdropStyle]} pointerEvents='none' />
462
+ <GestureDetector gesture={backdropTapGesture}>
463
+ {/* collapsable={false}: this view has no paint properties of its own (no background,
464
+ no animated style), exactly the shape React Native's view-flattening optimizer removes
465
+ from the native tree on native platforms — leaving the GestureDetector above with no real
466
+ view left to attach its tap recognizer to, so it would silently never receive a touch. */}
467
+ <Animated.View collapsable={false} style={StyleSheet.absoluteFill} />
468
+ </GestureDetector>
358
469
  </Animated.View>
359
470
  <Animated.View style={drawerOuterStyle}>
471
+ {/* pointerEvents='none': purely decorative, drawn outside the panel's own box (a directional
472
+ box-shadow never paints over the box's own content area), so it has no business
473
+ intercepting anything even at full opacity. Absolutely filled to the panel's own current
474
+ bounds, contentSize included, rather than a fixed size, so it tracks that animation too. */}
475
+ {resolvedPanelShadow && <Animated.View pointerEvents='none' style={[StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle]} />}
360
476
  {contentSize ? <View style={contentClipStyle}>{fill}</View> : fill}
361
477
  {dismissible && (
362
478
  <GestureDetector gesture={handleGesture}>
363
- <Animated.View style={[styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle, handleVisibilityStyle, { zIndex: zIndex + 2 }]}>{showHandle && <View style={[styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }]} />}</Animated.View>
479
+ {/* pointerEvents mirrors handleGesture's own .enabled(open) above, the same way the
480
+ backdrop's tap-catcher mirrors backdropTapGesture's .enabled(open && blockingBackdrop)
481
+ just above — handleVisibilityStyle's opacity already fades this strip out once the
482
+ panel's closed, but opacity alone doesn't stop hit-testing on web/Android (unlike iOS,
483
+ which excludes opacity-0 views from hit-testing regardless of pointerEvents — see the
484
+ backdrop tint's own comment on that asymmetry). Left at 'auto' while closed, this
485
+ 48px-wide strip sits at zIndex+2 flush against the screen edge closest to `side` —
486
+ easy to land a consumer's own edge-anchored chrome (an app bar icon, say) in that same
487
+ band — and swallows taps meant for whatever's underneath it despite being invisible
488
+ AND, since the gesture itself is disabled here too, unable to do anything with them
489
+ either. */}
490
+ <Animated.View style={[styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle, handleVisibilityStyle, handleStripInteractionStyle]}>{showHandle && <View style={[styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }]} />}</Animated.View>
364
491
  </GestureDetector>
365
492
  )}
366
493
  </Animated.View>
@@ -389,7 +516,14 @@ const styles = StyleSheet.create({
389
516
  right: 0,
390
517
  top: 0
391
518
  },
392
- backdrop: {
519
+ backdropPosition: {
520
+ bottom: 0,
521
+ left: 0,
522
+ position: 'absolute',
523
+ right: 0,
524
+ top: 0
525
+ },
526
+ backdropTint: {
393
527
  backgroundColor: '#000',
394
528
  bottom: 0,
395
529
  left: 0,
@@ -1,4 +1,4 @@
1
- import { StyleSheet, View } from 'react-native'
1
+ import { Platform, StyleSheet, View, type ViewStyle } from 'react-native'
2
2
  import { Gesture, GestureDetector } from 'react-native-gesture-handler'
3
3
  import { runOnJS, SharedValue, withSpring } from 'react-native-reanimated'
4
4
 
@@ -70,11 +70,18 @@ export const DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, m
70
70
 
71
71
  return (
72
72
  <GestureDetector gesture={gesture}>
73
- <View style={edgeStyle} />
73
+ {/* Same web-only affordance Drawer.tsx's own handle strip gives its drag grip (see its
74
+ webCursorStyle) — without it, nothing on screen hints that this edge is draggable at
75
+ all on a platform with a mouse cursor to change in the first place. */}
76
+ <View style={[...edgeStyle, webCursorStyle]} />
74
77
  </GestureDetector>
75
78
  )
76
79
  }
77
80
 
81
+ // react-native-web reads `cursor` straight off style; native ignores the unknown key. ViewStyle
82
+ // (the native type this file is typed against) has no such property, hence the cast.
83
+ const webCursorStyle = { cursor: Platform.OS === 'web' ? 'pointer' : undefined } as ViewStyle
84
+
78
85
  const styles = StyleSheet.create({
79
86
  bottom: { bottom: 0 },
80
87
  edgeHorizontal: {