@rific/drawer 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +25 -5
- package/dist/index.mjs +26 -6
- package/package.json +1 -1
- package/src/Drawer.tsx +76 -3
- package/src/DrawerEdgeSwipe.tsx +22 -2
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
|
@@ -96,11 +96,18 @@ var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
|
96
96
|
var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
|
|
97
97
|
var VELOCITY_THRESHOLD = 500;
|
|
98
98
|
var useBlurFallback = (override) => override ?? false;
|
|
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, 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 }) => {
|
|
100
100
|
const { colors } = (0, import_react_native_paper.useTheme)();
|
|
101
101
|
const vertical = isVerticalSide(side);
|
|
102
102
|
const openDirection = getOpenDirection(side);
|
|
103
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 };
|
|
104
111
|
const [measuredSize, setMeasuredSize] = (0, import_react.useState)(null);
|
|
105
112
|
const lastMeasuredRef = (0, import_react.useRef)(null);
|
|
106
113
|
const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
|
|
@@ -130,6 +137,7 @@ 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) => {
|
|
@@ -190,19 +198,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
|
|
|
190
198
|
const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
|
|
191
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 };
|
|
192
200
|
const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
|
|
193
|
-
const
|
|
201
|
+
const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
|
|
202
|
+
const webCursorStyle2 = { cursor: import_react_native2.Platform.OS === "web" ? "pointer" : void 0 };
|
|
194
203
|
const handleVisibilityStyle = (0, import_react_native_reanimated.useAnimatedStyle)(() => {
|
|
195
204
|
const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
|
|
196
205
|
return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
|
|
197
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
|
+
});
|
|
198
212
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
199
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: [styles.backdropPosition,
|
|
213
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: [styles.backdropPosition, backdropInteractionStyle], children: [
|
|
200
214
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
|
|
201
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 }) })
|
|
202
216
|
] }),
|
|
203
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] }),
|
|
204
219
|
contentSize ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill,
|
|
205
|
-
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,
|
|
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 }] }) }) })
|
|
206
221
|
] })
|
|
207
222
|
] });
|
|
208
223
|
};
|
|
@@ -290,8 +305,9 @@ var DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, maxHeight,
|
|
|
290
305
|
}
|
|
291
306
|
});
|
|
292
307
|
const edgeStyle = vertical ? [styles2.edgeHorizontal, side === "top" ? styles2.top : styles2.bottom] : [styles2.edgeVertical, side === "left" ? styles2.left : styles2.right];
|
|
293
|
-
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, enabled ? styles2.interactive : styles2.nonInteractive] }) });
|
|
294
309
|
};
|
|
310
|
+
var webCursorStyle = { cursor: import_react_native3.Platform.OS === "web" ? "pointer" : void 0 };
|
|
295
311
|
var styles2 = import_react_native3.StyleSheet.create({
|
|
296
312
|
bottom: { bottom: 0 },
|
|
297
313
|
edgeHorizontal: {
|
|
@@ -308,7 +324,11 @@ var styles2 = import_react_native3.StyleSheet.create({
|
|
|
308
324
|
width: EDGE_WIDTH,
|
|
309
325
|
zIndex: 5
|
|
310
326
|
},
|
|
327
|
+
// See enabled's own comment above for why this needs to be a real style toggle, not just the
|
|
328
|
+
// gesture's own .enabled(enabled).
|
|
329
|
+
interactive: { pointerEvents: "auto" },
|
|
311
330
|
left: { left: 0 },
|
|
331
|
+
nonInteractive: { pointerEvents: "none" },
|
|
312
332
|
right: { right: 0 },
|
|
313
333
|
top: { top: 0 }
|
|
314
334
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -54,11 +54,18 @@ import { Fragment as Fragment2, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
|
54
54
|
var SPRING = { damping: 45, stiffness: 500, overshootClamping: true, restDisplacementThreshold: 0.5, restSpeedThreshold: 10 };
|
|
55
55
|
var VELOCITY_THRESHOLD = 500;
|
|
56
56
|
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, 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 }) => {
|
|
58
58
|
const { colors } = useTheme();
|
|
59
59
|
const vertical = isVerticalSide(side);
|
|
60
60
|
const openDirection = getOpenDirection(side);
|
|
61
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 };
|
|
62
69
|
const [measuredSize, setMeasuredSize] = useState(null);
|
|
63
70
|
const lastMeasuredRef = useRef(null);
|
|
64
71
|
const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
|
|
@@ -88,6 +95,7 @@ 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) => {
|
|
@@ -148,19 +156,26 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
|
|
|
148
156
|
const handleStripEdgeStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS };
|
|
149
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 };
|
|
150
158
|
const handlePillStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 };
|
|
151
|
-
const
|
|
159
|
+
const handleStripInteractionStyle = { zIndex: zIndex + 2, pointerEvents: open ? "auto" : "none" };
|
|
160
|
+
const webCursorStyle2 = { cursor: Platform.OS === "web" ? "pointer" : void 0 };
|
|
152
161
|
const handleVisibilityStyle = useAnimatedStyle(() => {
|
|
153
162
|
const visibleSize = maxEffectiveSize - translateOffset.value * closeDirection;
|
|
154
163
|
return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
|
|
155
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
|
+
});
|
|
156
170
|
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
157
|
-
/* @__PURE__ */ jsxs(Animated.View, { style: [styles.backdropPosition,
|
|
171
|
+
/* @__PURE__ */ jsxs(Animated.View, { style: [styles.backdropPosition, backdropInteractionStyle], children: [
|
|
158
172
|
/* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
|
|
159
173
|
/* @__PURE__ */ jsx2(GestureDetector, { gesture: backdropTapGesture, children: /* @__PURE__ */ jsx2(Animated.View, { collapsable: false, style: StyleSheet.absoluteFill }) })
|
|
160
174
|
] }),
|
|
161
175
|
/* @__PURE__ */ jsxs(Animated.View, { style: drawerOuterStyle, children: [
|
|
176
|
+
resolvedPanelShadow && /* @__PURE__ */ jsx2(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, panelShadowStyle, panelShadowVisibilityStyle] }),
|
|
162
177
|
contentSize ? /* @__PURE__ */ jsx2(View, { style: contentClipStyle, children: fill }) : fill,
|
|
163
|
-
dismissible && /* @__PURE__ */ jsx2(GestureDetector, { gesture: handleGesture, children: /* @__PURE__ */ jsx2(Animated.View, { style: [styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle,
|
|
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 }] }) }) })
|
|
164
179
|
] })
|
|
165
180
|
] });
|
|
166
181
|
};
|
|
@@ -217,7 +232,7 @@ var styles = StyleSheet.create({
|
|
|
217
232
|
});
|
|
218
233
|
|
|
219
234
|
// src/DrawerEdgeSwipe.tsx
|
|
220
|
-
import { StyleSheet as StyleSheet2, View as View2 } from "react-native";
|
|
235
|
+
import { Platform as Platform2, StyleSheet as StyleSheet2, View as View2 } from "react-native";
|
|
221
236
|
import { Gesture as Gesture2, GestureDetector as GestureDetector2 } from "react-native-gesture-handler";
|
|
222
237
|
import { runOnJS as runOnJS2, withSpring as withSpring2 } from "react-native-reanimated";
|
|
223
238
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
@@ -248,8 +263,9 @@ var DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, maxHeight,
|
|
|
248
263
|
}
|
|
249
264
|
});
|
|
250
265
|
const edgeStyle = vertical ? [styles2.edgeHorizontal, side === "top" ? styles2.top : styles2.bottom] : [styles2.edgeVertical, side === "left" ? styles2.left : styles2.right];
|
|
251
|
-
return /* @__PURE__ */ jsx3(GestureDetector2, { gesture, children: /* @__PURE__ */ jsx3(View2, { style: edgeStyle }) });
|
|
266
|
+
return /* @__PURE__ */ jsx3(GestureDetector2, { gesture, children: /* @__PURE__ */ jsx3(View2, { style: [...edgeStyle, webCursorStyle, enabled ? styles2.interactive : styles2.nonInteractive] }) });
|
|
252
267
|
};
|
|
268
|
+
var webCursorStyle = { cursor: Platform2.OS === "web" ? "pointer" : void 0 };
|
|
253
269
|
var styles2 = StyleSheet2.create({
|
|
254
270
|
bottom: { bottom: 0 },
|
|
255
271
|
edgeHorizontal: {
|
|
@@ -266,7 +282,11 @@ var styles2 = StyleSheet2.create({
|
|
|
266
282
|
width: EDGE_WIDTH,
|
|
267
283
|
zIndex: 5
|
|
268
284
|
},
|
|
285
|
+
// See enabled's own comment above for why this needs to be a real style toggle, not just the
|
|
286
|
+
// gesture's own .enabled(enabled).
|
|
287
|
+
interactive: { pointerEvents: "auto" },
|
|
269
288
|
left: { left: 0 },
|
|
289
|
+
nonInteractive: { pointerEvents: "none" },
|
|
270
290
|
right: { right: 0 },
|
|
271
291
|
top: { top: 0 }
|
|
272
292
|
});
|
package/package.json
CHANGED
package/src/Drawer.tsx
CHANGED
|
@@ -28,6 +28,28 @@ const VELOCITY_THRESHOLD = 500
|
|
|
28
28
|
// fallback stands in when auto-paper isn't configured, so a per-render branch isn't needed.
|
|
29
29
|
const useBlurFallback = (override?: boolean) => override ?? false
|
|
30
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
|
+
|
|
31
53
|
export type DrawerProps = {
|
|
32
54
|
// Peak backdrop opacity once fully open (scaled down as the panel slides toward closed, same as
|
|
33
55
|
// before): 0 renders no dimming at all, letting whatever's behind the panel stay fully visible.
|
|
@@ -87,6 +109,16 @@ export type DrawerProps = {
|
|
|
87
109
|
// autofocusing a field inside `content` only once it's actually on screen.
|
|
88
110
|
onOpened?: () => void
|
|
89
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
|
|
90
122
|
side?: DrawerSide
|
|
91
123
|
// Whether the handle strip's own visual pill graphic draws, independent of `dismissible`, which
|
|
92
124
|
// controls the strip (and its drag-to-dismiss gesture) as a whole. false keeps the strip's hit area
|
|
@@ -106,11 +138,21 @@ export type DrawerProps = {
|
|
|
106
138
|
zIndex?: number
|
|
107
139
|
}
|
|
108
140
|
|
|
109
|
-
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) => {
|
|
110
142
|
const { colors } = useTheme()
|
|
111
143
|
const vertical = isVerticalSide(side)
|
|
112
144
|
const openDirection = getOpenDirection(side)
|
|
113
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 }
|
|
114
156
|
|
|
115
157
|
const [measuredSize, setMeasuredSize] = useState<number | null>(null)
|
|
116
158
|
// Tracks the last value actually committed to measuredSize, rounded — see handleLayout below for
|
|
@@ -169,6 +211,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
|
|
|
169
211
|
// transparent, matching "closed," since a not-yet-sized panel isn't meaningfully open yet either.
|
|
170
212
|
const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }))
|
|
171
213
|
const animatedSizeStyle = useAnimatedStyle(() => (vertical ? { height: animatedSize.value } : { width: animatedSize.value }))
|
|
214
|
+
const backdropInteractionStyle: ViewStyle = { zIndex, pointerEvents: open && blockingBackdrop ? 'auto' : 'none' }
|
|
172
215
|
|
|
173
216
|
const positionStyle = side === 'left' ? styles.anchorLeft : side === 'right' ? styles.anchorRight : side === 'top' ? styles.anchorTop : styles.anchorBottom
|
|
174
217
|
// maxEffectiveSize, not the raw height/width prop: the box must be big enough to show the panel
|
|
@@ -372,6 +415,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
|
|
|
372
415
|
// invisible margin around it grew.
|
|
373
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 }
|
|
374
417
|
const handlePillStyle: ViewStyle = vertical ? { height: 6, width: 64 } : { height: 64, width: 6 }
|
|
418
|
+
const handleStripInteractionStyle: ViewStyle = { zIndex: zIndex + 2, pointerEvents: open ? 'auto' : 'none' }
|
|
375
419
|
// react-native-web reads `cursor` straight off style; native ignores the unknown key. ViewStyle (the
|
|
376
420
|
// native type these files are typed against) has no such property, hence the cast.
|
|
377
421
|
const webCursorStyle = { cursor: Platform.OS === 'web' ? 'pointer' : undefined } as ViewStyle
|
|
@@ -389,9 +433,22 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
|
|
|
389
433
|
return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 }
|
|
390
434
|
})
|
|
391
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
|
+
|
|
392
449
|
return (
|
|
393
450
|
<>
|
|
394
|
-
<Animated.View style={[styles.backdropPosition,
|
|
451
|
+
<Animated.View style={[styles.backdropPosition, backdropInteractionStyle]}>
|
|
395
452
|
{/* The dimming tint is its own child, carrying the actual black backgroundColor and
|
|
396
453
|
backdropStyle's animated opacity, separate from the tap-catching view below and from the
|
|
397
454
|
OUTER container above (which must stay paint-free, not just visually transparent at
|
|
@@ -411,10 +468,26 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
|
|
|
411
468
|
</GestureDetector>
|
|
412
469
|
</Animated.View>
|
|
413
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]} />}
|
|
414
476
|
{contentSize ? <View style={contentClipStyle}>{fill}</View> : fill}
|
|
415
477
|
{dismissible && (
|
|
416
478
|
<GestureDetector gesture={handleGesture}>
|
|
417
|
-
|
|
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>
|
|
418
491
|
</GestureDetector>
|
|
419
492
|
)}
|
|
420
493
|
</Animated.View>
|
package/src/DrawerEdgeSwipe.tsx
CHANGED
|
@@ -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,27 @@ export const DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, m
|
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
72
|
<GestureDetector gesture={gesture}>
|
|
73
|
-
|
|
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
|
+
|
|
77
|
+
pointerEvents here (not just gesture.enabled(enabled) above) matters on web specifically:
|
|
78
|
+
RNGH's own enabled() only stops the Pan gesture from recognizing/completing a touch, it
|
|
79
|
+
doesn't stop this View's underlying DOM node from being hit-tested. Without this, a caller
|
|
80
|
+
passing enabled={false} to shed the edge-swipe-to-open behavior (e.g. because their own
|
|
81
|
+
screen never uses it) still ends up with this zone as an invisible, unconditionally opaque
|
|
82
|
+
strip along the edge — silently swallowing presses meant for anything else placed there,
|
|
83
|
+
even though the gesture it exists for no longer does anything. 'none' when disabled lets
|
|
84
|
+
that click/tap fall straight through to whatever's actually underneath. */}
|
|
85
|
+
<View style={[...edgeStyle, webCursorStyle, enabled ? styles.interactive : styles.nonInteractive]} />
|
|
74
86
|
</GestureDetector>
|
|
75
87
|
)
|
|
76
88
|
}
|
|
77
89
|
|
|
90
|
+
// react-native-web reads `cursor` straight off style; native ignores the unknown key. ViewStyle
|
|
91
|
+
// (the native type this file is typed against) has no such property, hence the cast.
|
|
92
|
+
const webCursorStyle = { cursor: Platform.OS === 'web' ? 'pointer' : undefined } as ViewStyle
|
|
93
|
+
|
|
78
94
|
const styles = StyleSheet.create({
|
|
79
95
|
bottom: { bottom: 0 },
|
|
80
96
|
edgeHorizontal: {
|
|
@@ -91,7 +107,11 @@ const styles = StyleSheet.create({
|
|
|
91
107
|
width: EDGE_WIDTH,
|
|
92
108
|
zIndex: 5
|
|
93
109
|
},
|
|
110
|
+
// See enabled's own comment above for why this needs to be a real style toggle, not just the
|
|
111
|
+
// gesture's own .enabled(enabled).
|
|
112
|
+
interactive: { pointerEvents: 'auto' },
|
|
94
113
|
left: { left: 0 },
|
|
114
|
+
nonInteractive: { pointerEvents: 'none' },
|
|
95
115
|
right: { right: 0 },
|
|
96
116
|
top: { top: 0 }
|
|
97
117
|
})
|