@rific/drawer 0.3.0 → 0.4.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/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");
@@ -103,6 +102,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
103
102
  const openDirection = getOpenDirection(side);
104
103
  const closeDirection = -openDirection;
105
104
  const [measuredSize, setMeasuredSize] = (0, import_react.useState)(null);
105
+ const lastMeasuredRef = (0, import_react.useRef)(null);
106
106
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
107
107
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
108
108
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
@@ -133,7 +133,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
133
133
  const positionStyle = side === "left" ? styles.anchorLeft : side === "right" ? styles.anchorRight : side === "top" ? styles.anchorTop : styles.anchorBottom;
134
134
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize };
135
135
  const handleLayout = (event) => {
136
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width;
136
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width);
137
+ if (lastMeasuredRef.current === measured) return;
138
+ lastMeasuredRef.current = measured;
137
139
  setMeasuredSize(measured);
138
140
  onMeasure?.(measured);
139
141
  };
@@ -151,6 +153,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
151
153
  const clampMax = Math.max(0, closedOffset);
152
154
  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
155
  const gestureStartOffset = (0, import_react_native_reanimated.useSharedValue)(closedOffset);
156
+ const backdropTapGesture = import_react_native_gesture_handler.Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
157
+ if (success) (0, import_react_native_reanimated.runOnJS)(onClose)();
158
+ });
154
159
  const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
155
160
  "worklet";
156
161
  gestureStartOffset.value = translateOffset.value;
@@ -191,7 +196,10 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
191
196
  return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
192
197
  });
193
198
  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 }) }),
199
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: [styles.backdropPosition, { zIndex, pointerEvents: open && blockingBackdrop ? "auto" : "none" }], children: [
200
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native_reanimated.default.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
201
+ /* @__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
+ ] }),
195
203
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native_reanimated.default.View, { style: drawerOuterStyle, children: [
196
204
  contentSize ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: contentClipStyle, children: fill }) : fill,
197
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, webCursorStyle, handleVisibilityStyle, { zIndex: zIndex + 2 }], children: showHandle && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: [styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }] }) }) })
@@ -219,7 +227,14 @@ var styles = import_react_native2.StyleSheet.create({
219
227
  right: 0,
220
228
  top: 0
221
229
  },
222
- backdrop: {
230
+ backdropPosition: {
231
+ bottom: 0,
232
+ left: 0,
233
+ position: "absolute",
234
+ right: 0,
235
+ top: 0
236
+ },
237
+ backdropTint: {
223
238
  backgroundColor: "#000",
224
239
  bottom: 0,
225
240
  left: 0,
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";
@@ -61,6 +60,7 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
61
60
  const openDirection = getOpenDirection(side);
62
61
  const closeDirection = -openDirection;
63
62
  const [measuredSize, setMeasuredSize] = useState(null);
63
+ const lastMeasuredRef = useRef(null);
64
64
  const sizeInput = contentSize ? measuredSize ?? (vertical ? height : width) : vertical ? height : width;
65
65
  const maxSizeInput = contentSize ? void 0 : vertical ? maxHeight : maxWidth;
66
66
  const { closedOffset, effectiveSize, maxEffectiveSize, restOffset } = useDrawerSize(side, sizeInput, maxSizeInput, edgeInset);
@@ -91,7 +91,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
91
91
  const positionStyle = side === "left" ? styles.anchorLeft : side === "right" ? styles.anchorRight : side === "top" ? styles.anchorTop : styles.anchorBottom;
92
92
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize };
93
93
  const handleLayout = (event) => {
94
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width;
94
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width);
95
+ if (lastMeasuredRef.current === measured) return;
96
+ lastMeasuredRef.current = measured;
95
97
  setMeasuredSize(measured);
96
98
  onMeasure?.(measured);
97
99
  };
@@ -109,6 +111,9 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
109
111
  const clampMax = Math.max(0, closedOffset);
110
112
  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
113
  const gestureStartOffset = useSharedValue(closedOffset);
114
+ const backdropTapGesture = Gesture.Tap().enabled(open && blockingBackdrop).onEnd((_event, success) => {
115
+ if (success) runOnJS(onClose)();
116
+ });
112
117
  const handleGesture = handleAxisGesture.enabled(open).onStart(() => {
113
118
  "worklet";
114
119
  gestureStartOffset.value = translateOffset.value;
@@ -149,7 +154,10 @@ var Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur, children,
149
154
  return { opacity: visibleSize >= HANDLE_STRIP_THICKNESS ? 1 : 0 };
150
155
  });
151
156
  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 }) }),
157
+ /* @__PURE__ */ jsxs(Animated.View, { style: [styles.backdropPosition, { zIndex, pointerEvents: open && blockingBackdrop ? "auto" : "none" }], children: [
158
+ /* @__PURE__ */ jsx2(Animated.View, { style: [styles.backdropTint, backdropStyle], pointerEvents: "none" }),
159
+ /* @__PURE__ */ jsx2(GestureDetector, { gesture: backdropTapGesture, children: /* @__PURE__ */ jsx2(Animated.View, { collapsable: false, style: StyleSheet.absoluteFill }) })
160
+ ] }),
153
161
  /* @__PURE__ */ jsxs(Animated.View, { style: drawerOuterStyle, children: [
154
162
  contentSize ? /* @__PURE__ */ jsx2(View, { style: contentClipStyle, children: fill }) : fill,
155
163
  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 }] }) }) })
@@ -177,7 +185,14 @@ var styles = StyleSheet.create({
177
185
  right: 0,
178
186
  top: 0
179
187
  },
180
- backdrop: {
188
+ backdropPosition: {
189
+ bottom: 0,
190
+ left: 0,
191
+ position: "absolute",
192
+ right: 0,
193
+ top: 0
194
+ },
195
+ backdropTint: {
181
196
  backgroundColor: "#000",
182
197
  bottom: 0,
183
198
  left: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rific/drawer",
3
- "version": "0.3.0",
3
+ "version": "0.4.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
@@ -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'
@@ -114,6 +113,10 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
114
113
  const closeDirection = -openDirection as 1 | -1
115
114
 
116
115
  const [measuredSize, setMeasuredSize] = useState<number | null>(null)
116
+ // Tracks the last value actually committed to measuredSize, rounded — see handleLayout below for
117
+ // why the comparison has to happen against this rather than just re-deriving it from measuredSize
118
+ // itself on every call.
119
+ const lastMeasuredRef = useRef<number | null>(null)
117
120
  // contentSize measures its own box from natural content size, so it has no separate rest-vs-max
118
121
  // concept: maxHeight/maxWidth (the drag-to-expand ceiling) only apply in the fixed-size path.
119
122
  // height/width remain the pre-measurement placeholder until the first layout, same as before.
@@ -172,8 +175,22 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
172
175
  // fully expanded, even though it usually only shows effectiveSize px of that at rest.
173
176
  const sizeStyle = vertical ? { height: maxEffectiveSize } : { width: maxEffectiveSize }
174
177
 
178
+ // Rounded (not the raw sub-pixel float layout reports) and short-circuited against the last value
179
+ // actually committed: an animated ancestor (animatedSizeStyle below, mid-withTiming) can cause
180
+ // Yoga to re-measure this supposedly content-unconstrained wrapper on every frame it's still
181
+ // moving, and floating-point noise between passes (e.g. 283.3333740234375 vs 283.33331298828125 —
182
+ // the same logical height, off by ~1/16000th of a pixel) is "different" by strict equality. Left
183
+ // unguarded, that noise commits a "new" measuredSize every frame, which restarts the very
184
+ // withTiming animation that's causing the re-measurement in the first place — a self-sustaining
185
+ // loop that never lets the height settle, seen as a stutter rather than a single smooth resize.
186
+ // Comparing against a ref (not measuredSize itself) matters here: measuredSize is the state that's
187
+ // deliberately being skipped on a no-op call, so re-deriving the comparison from it would still
188
+ // see the same (unchanged) value next time regardless — the ref is what actually remembers what
189
+ // was last committed.
175
190
  const handleLayout = (event: LayoutChangeEvent) => {
176
- const measured = vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width
191
+ const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width)
192
+ if (lastMeasuredRef.current === measured) return
193
+ lastMeasuredRef.current = measured
177
194
  setMeasuredSize(measured)
178
195
  onMeasure?.(measured)
179
196
  }
@@ -209,6 +226,16 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
209
226
  ) : (
210
227
  <View style={[fillStyle, { backgroundColor: colors.surface }]}>{children}</View>
211
228
  )
229
+ // contentSize's measuring wrapper above is deliberately given no style of its own (see the
230
+ // comment above `fillStyle`): it must report ITS OWN natural size, which only works if `children`
231
+ // itself has an intrinsic height Yoga can compute directly from its subtree — e.g. plain
232
+ // Views/Text/FABs, including a `flexWrap: 'wrap'` row like FabRow. A `ScrollView` breaks this: on
233
+ // native, ScrollView's outer box does NOT size itself to its content the way a plain View does —
234
+ // it needs a bounded height from an ANCESTOR instead (see ScrollView's own docs) — so measuring
235
+ // one via onLayout here reports some small, real-but-wrong box height (whatever Yoga happens to
236
+ // resolve it to absent an explicit bound) rather than the content's true extent, and clips
237
+ // anything beyond that. contentSize's `children` must render its own natural-height content
238
+ // directly (no ScrollView) for this measurement to be meaningful.
212
239
 
213
240
  // Deliberately NOT clipped (no overflow: hidden here, unlike the contentSize clip wrapper below):
214
241
  // the handle strip is a child of this view, positioned outside its bounds (see
@@ -254,6 +281,17 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
254
281
  // needs to offset from wherever the panel actually was, not always from rest.
255
282
  const gestureStartOffset = useSharedValue(closedOffset)
256
283
 
284
+ // react-native-gesture-handler's own Tap, not @rific/haptic-press's plain-RN Pressable: this
285
+ // sits in the same GestureDetector-based system as the panel's own drag handle below, rather
286
+ // than mixing RNGH's native recognizers with RN's separate classic responder system on the one
287
+ // view in the tree (the backdrop) that most needs to reliably win a touch over whatever's behind
288
+ // it, including a consumer's own full-screen canvas gestures (e.g. Swirlio's pan/pinch/rotation).
289
+ const backdropTapGesture = Gesture.Tap()
290
+ .enabled(open && blockingBackdrop)
291
+ .onEnd((_event, success) => {
292
+ if (success) runOnJS(onClose)()
293
+ })
294
+
257
295
  const handleGesture = handleAxisGesture
258
296
  .enabled(open)
259
297
  .onStart(() => {
@@ -353,8 +391,24 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
353
391
 
354
392
  return (
355
393
  <>
356
- <Animated.View style={[styles.backdrop, { zIndex }, backdropStyle]} pointerEvents={open && blockingBackdrop ? 'auto' : 'none'}>
357
- <Pressable style={StyleSheet.absoluteFill} onPress={onClose} />
394
+ <Animated.View style={[styles.backdropPosition, { zIndex, pointerEvents: open && blockingBackdrop ? 'auto' : 'none' }]}>
395
+ {/* The dimming tint is its own child, carrying the actual black backgroundColor and
396
+ backdropStyle's animated opacity, separate from the tap-catching view below and from the
397
+ OUTER container above (which must stay paint-free, not just visually transparent at
398
+ opacity 0): on iOS, a view at opacity 0 (e.g. backdropOpacity={0}, an intentional no-dim
399
+ backdrop — see controlGroups.tsx) is excluded from hit-testing entirely by UIKit,
400
+ regardless of pointerEvents. That's fine for a purely decorative tint, but it would
401
+ silently make the whole backdrop untouchable too if the SAME view carried both — and if
402
+ the outer container carried the background color instead, it would paint solid black at
403
+ full opacity at all times (no animated opacity of its own), open or not. */}
404
+ <Animated.View style={[styles.backdropTint, backdropStyle]} pointerEvents='none' />
405
+ <GestureDetector gesture={backdropTapGesture}>
406
+ {/* collapsable={false}: this view has no paint properties of its own (no background,
407
+ no animated style), exactly the shape React Native's view-flattening optimizer removes
408
+ from the native tree on native platforms — leaving the GestureDetector above with no real
409
+ view left to attach its tap recognizer to, so it would silently never receive a touch. */}
410
+ <Animated.View collapsable={false} style={StyleSheet.absoluteFill} />
411
+ </GestureDetector>
358
412
  </Animated.View>
359
413
  <Animated.View style={drawerOuterStyle}>
360
414
  {contentSize ? <View style={contentClipStyle}>{fill}</View> : fill}
@@ -389,7 +443,14 @@ const styles = StyleSheet.create({
389
443
  right: 0,
390
444
  top: 0
391
445
  },
392
- backdrop: {
446
+ backdropPosition: {
447
+ bottom: 0,
448
+ left: 0,
449
+ position: 'absolute',
450
+ right: 0,
451
+ top: 0
452
+ },
453
+ backdropTint: {
393
454
  backgroundColor: '#000',
394
455
  bottom: 0,
395
456
  left: 0,