@rific/drawer 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,7 @@ const { DrawerInstanceProvider: SettingsDrawerProvider, useDrawer: useSettingsDr
28
28
  const { DrawerInstanceProvider: SheetProvider, useDrawer: useSheet } = createDrawer({ side: 'bottom', height: 400 })
29
29
  ```
30
30
 
31
- `side` accepts `'left'`, `'right'`, `'top'`, or `'bottom'` (default `'left'`). `left`/`right` drawers size themselves with `width` (default `300`); `top`/`bottom` sheets use `height` instead (same default). Only the prop matching the chosen axis matters: pass `width` for a horizontal drawer, `height` for a vertical one. Either accepts a plain pixel number or a percentage string (`height: '50%'`) resolved against the window's height/width, re-resolving automatically on rotation/resize.
31
+ `side` accepts `'left'`, `'right'`, `'top'`, or `'bottom'` (default `'left'`). `left`/`right` drawers size themselves with `width` (default `300`); `top`/`bottom` sheets use `height` instead (same default). Only the prop matching the chosen axis matters: pass `width` for a horizontal drawer, `height` for a vertical one. Either accepts a plain pixel number or a percentage string (`height: '50%'`) resolved against the window's height/width, re-resolving automatically on rotation/resize. Either way, the resolved size is capped at the window's own size along that axis (the same goes for `maxHeight`/`maxWidth` below), so a fixed `width: 380` drawer fills a 360px-wide phone exactly instead of running its far edge off the screen, and stays 380 on anything wider.
32
32
 
33
33
  Mount each `DrawerInstanceProvider` once, near your app root: `children` is the rest of the app (so `useDrawer()` is reachable from anywhere inside it), and `content` is what renders inside the sliding panel itself. With more than one drawer, `combineDrawerProviders` flattens the nesting into a single wrapper (first argument is outermost, matching how you'd nest them by hand):
34
34
 
@@ -93,17 +93,17 @@ This isn't sheet-specific: the main axis is whichever one `side` uses, so it wor
93
93
 
94
94
  ## Expandable sheets
95
95
 
96
- Pass `maxHeight`/`maxWidth` (same shape as `height`/`width`: a number, or a percentage string) to let the drag handle pull the panel open further than its resting size, up to this ceiling — a sheet that opens partway but can be dragged the rest of the way open:
96
+ Pass `maxHeight`/`maxWidth` (same shape as `height`/`width`: a number, or a percentage string) to let the drag handle pull the panel open further than its resting size, up to this ceiling - a sheet that opens partway but can be dragged the rest of the way open:
97
97
 
98
98
  ```tsx
99
99
  const { DrawerInstanceProvider: SheetProvider } = createDrawer({ side: 'bottom', height: '50%', maxHeight: '100%' })
100
100
  ```
101
101
 
102
- This sheet opens — by calling `open()`, tapping, or swiping in from the edge — to half the screen, same as a plain `height: '50%'` would. From there, dragging the handle further up expands it the rest of the way to full screen; dragging back down closes it. Same commit rule either direction: past a third of the way toward the next state (or a fast enough flick) commits to it, otherwise it springs back to rest — just like the existing drag-to-dismiss behavior, now with a third resting point instead of two.
102
+ This sheet opens - by calling `open()`, tapping, or swiping in from the edge - to half the screen, same as a plain `height: '50%'` would. From there, dragging the handle further up expands it the rest of the way to full screen; dragging back down closes it. Same commit rule either direction: past a third of the way toward the next state (or a fast enough flick) commits to it, otherwise it springs back to rest - just like the existing drag-to-dismiss behavior, now with a third resting point instead of two.
103
103
 
104
- Without `maxHeight`/`maxWidth` (the default), nothing changes: `height`/`width` alone is both the resting size and the ceiling, so there's nothing to expand into, and the handle drag is a plain two-way open/closed toggle exactly as before. No effect when `contentSize` is set either, since that already sizes the panel to its content — there's no separate rest-vs-max to speak of.
104
+ Without `maxHeight`/`maxWidth` (the default), nothing changes: `height`/`width` alone is both the resting size and the ceiling, so there's nothing to expand into, and the handle drag is a plain two-way open/closed toggle exactly as before. No effect when `contentSize` is set either, since that already sizes the panel to its content - there's no separate rest-vs-max to speak of.
105
105
 
106
- `useDrawer()` also returns `expandProgress`, a `SharedValue<number>`: 0 anywhere at or before resting (nothing to indicate — the panel isn't showing any more than its configured rest size), 1 once a drag has pulled it all the way open to `maxHeight`/`maxWidth`, smoothly interpolating in between as the handle is dragged or the spring animates. Content that only cares once the panel is genuinely at its full extent — see [Safe area](#safe-area) below for the motivating example — can read it directly in a `useAnimatedStyle`:
106
+ `useDrawer()` also returns `expandProgress`, a `SharedValue<number>`: 0 anywhere at or before resting (nothing to indicate - the panel isn't showing any more than its configured rest size), 1 once a drag has pulled it all the way open to `maxHeight`/`maxWidth`, smoothly interpolating in between as the handle is dragged or the spring animates. Content that only cares once the panel is genuinely at its full extent - see [Safe area](#safe-area) below for the motivating example - can read it directly in a `useAnimatedStyle`:
107
107
 
108
108
  ```tsx
109
109
  const { expandProgress } = sheet.useDrawer()
@@ -117,9 +117,9 @@ Always a flat `1` while open when there's no `maxHeight`/`maxWidth` (rest alread
117
117
 
118
118
  The panel renders edge-to-edge, behind the status bar/notch and home indicator, on purpose. This package doesn't take a position on how you handle that. Pad your `content` yourself, however fits your app: `useSafeAreaInsets()` from `react-native-safe-area-context` directly, or a safe-area-aware header like `@rific/scroll-view`'s. Baking a fixed strategy into the panel itself would double up with whichever one you're already using for the rest of your app.
119
119
 
120
- For an expandable sheet specifically, a *top* inset is usually only relevant once the sheet is actually fully expanded (reaching the screen's own top edge/notch) — wasted space while it's merely resting at a partial `height`. `expandProgress` (see [Expandable sheets](#expandable-sheets) above) is built for exactly this: scale the top inset by it instead of applying it unconditionally, and it smoothly animates in as the sheet expands rather than snapping. A bottom inset doesn't need this treatment — the sheet's bottom edge sits flush against the screen's bottom at any size, rest or expanded, so that inset stays relevant throughout and can be applied unconditionally as usual.
120
+ For an expandable sheet specifically, a *top* inset is usually only relevant once the sheet is actually fully expanded (reaching the screen's own top edge/notch) - wasted space while it's merely resting at a partial `height`. `expandProgress` (see [Expandable sheets](#expandable-sheets) above) is built for exactly this: scale the top inset by it instead of applying it unconditionally, and it smoothly animates in as the sheet expands rather than snapping. A bottom inset doesn't need this treatment - the sheet's bottom edge sits flush against the screen's bottom at any size, rest or expanded, so that inset stays relevant throughout and can be applied unconditionally as usual.
121
121
 
122
- This padding approach keeps the panel itself full-bleed and compensates inside `content`, which is the right call if you want the panel's background to actually reach the screen edge (a full-screen sheet look once expanded). If instead you want the panel to visibly stop short of the status bar even fully expanded — so an expanded sheet still reads as a *drawer*, not a full-screen modal — there's a second, opposite approach: `edgeInset`.
122
+ This padding approach keeps the panel itself full-bleed and compensates inside `content`, which is the right call if you want the panel's background to actually reach the screen edge (a full-screen sheet look once expanded). If instead you want the panel to visibly stop short of the status bar even fully expanded - so an expanded sheet still reads as a *drawer*, not a full-screen modal - there's a second, opposite approach: `edgeInset`.
123
123
 
124
124
  ### Stopping the panel itself short of the inset
125
125
 
@@ -130,11 +130,11 @@ const insets = useSafeAreaInsets()
130
130
  const { DrawerInstanceProvider: SheetProvider } = createDrawer({ side: 'bottom', height: '50%', maxHeight: '100%', edgeInset: insets.top })
131
131
  ```
132
132
 
133
- Dragged all the way open, this sheet's top edge now stops at `insets.top` rather than sliding behind the status bar — there's nothing left for `content` to compensate for, so skip the `expandProgress` padding trick for this edge entirely (applying both would double the gap: the panel already stops at the inset, and the padding would push `content` down by another `insets.top` on top of that).
133
+ Dragged all the way open, this sheet's top edge now stops at `insets.top` rather than sliding behind the status bar - there's nothing left for `content` to compensate for, so skip the `expandProgress` padding trick for this edge entirely (applying both would double the gap: the panel already stops at the inset, and the padding would push `content` down by another `insets.top` on top of that).
134
134
 
135
- A plain pixel value is deliberately left untouched by `edgeInset` — `resolveDimension` ignores its window-size argument entirely for numbers, so it's unaffected regardless. A percentage means "fill the available space" (which should already account for a known inset); a literal px value means "this exact size," typically one you already computed deliberately, and `edgeInset` silently overriding that would take away your only way to opt a specific drawer back out of it.
135
+ A plain pixel value is deliberately left untouched by `edgeInset` - `resolveDimension` ignores its window-size argument entirely for numbers, so it's unaffected regardless. A percentage means "fill the available space" (which should already account for a known inset); a literal px value means "this exact size," typically one you already computed deliberately, and `edgeInset` silently overriding that would take away your only way to opt a specific drawer back out of it.
136
136
 
137
- Both approaches are just different values passed to the same props, so nothing stops one drawer in your app from going full-bleed with `expandProgress`-scaled padding while another uses `edgeInset` to stay clear of the inset outright — pick whichever fits each drawer, per drawer instance. The one thing to avoid is combining both for the *same* edge on the *same* drawer.
137
+ Both approaches are just different values passed to the same props, so nothing stops one drawer in your app from going full-bleed with `expandProgress`-scaled padding while another uses `edgeInset` to stay clear of the inset outright - pick whichever fits each drawer, per drawer instance. The one thing to avoid is combining both for the *same* edge on the *same* drawer.
138
138
 
139
139
  ## Blur
140
140
 
@@ -180,11 +180,36 @@ Only the panel surface blurs; the backdrop behind it stays solid, same as today.
180
180
 
181
181
  `Drawer` (the sliding panel and backdrop) and `DrawerEdgeSwipe` (the edge gesture zone) are also exported directly, for apps that want to manage the open/closed state and shared value themselves instead of using `createDrawer()`. Both take a `translateOffset` prop, a `SharedValue<number>` holding the panel's offset along its axis (`translateX` for `left`/`right`, `translateY` for `top`/`bottom`), so `DrawerEdgeSwipe`'s gesture and `Drawer`'s spring animation can share the same value.
182
182
 
183
+ Seed that shared value at the drawer's closed offset with `useDrawerSize`, the same hook `Drawer`, `DrawerEdgeSwipe` and `createDrawer()` resolve their own geometry with, rather than negating the size by hand: a hand-negated `-380` disagrees with a panel that's been capped to a narrower window (see [Usage](#usage)). Pass it the same `side`, size, max size and `edgeInset` the `Drawer` gets. Its `effectiveSize` is also the panel's actual rest size in px, for laying out anything sized to the panel itself (a full-width carousel page, say):
184
+
185
+ ```tsx
186
+ import { Drawer, DrawerEdgeSwipe, useDrawerSize } from '@rific/drawer'
187
+ import { useSharedValue } from 'react-native-reanimated'
188
+
189
+ const WIDTH = 380
190
+
191
+ const MenuDrawer = ({ open, onOpen, onClose }: MenuDrawerProps) => {
192
+ const { closedOffset, effectiveSize } = useDrawerSize('left', WIDTH)
193
+ const translateOffset = useSharedValue(closedOffset)
194
+
195
+ return (
196
+ <>
197
+ <DrawerEdgeSwipe onOpen={onOpen} translateOffset={translateOffset} width={WIDTH} />
198
+ <Drawer onClose={onClose} open={open} translateOffset={translateOffset} width={WIDTH}>
199
+ <Carousel pageWidth={effectiveSize} />
200
+ </Drawer>
201
+ </>
202
+ )
203
+ }
204
+ ```
205
+
206
+ The seed only matters for the very first frame: after that, `Drawer` springs the value to its own closed offset whenever that changes (rotation, a resize across the cap).
207
+
183
208
  If you're driving `Drawer` standalone with `contentSize` and want `DrawerEdgeSwipe`'s own commit-threshold math to track the measured size too, pass `Drawer` an `onMeasure?: (size: number) => void` and feed the result into the `height`/`width` you pass `DrawerEdgeSwipe`: this is exactly what `createDrawer()` does internally.
184
209
 
185
- Both also take `maxHeight`/`maxWidth` (see [Expandable sheets](#expandable-sheets)) — pass the same values to both, same as `height`/`width`, so `DrawerEdgeSwipe`'s edge-swipe-to-open lands at the same rest position `Drawer`'s own tap-to-open does. Same for `edgeInset` (see [Safe area](#safe-area)): pass the same value to both, or their rest/max geometry will disagree.
210
+ Both also take `maxHeight`/`maxWidth` (see [Expandable sheets](#expandable-sheets)) - pass the same values to both, same as `height`/`width`, so `DrawerEdgeSwipe`'s edge-swipe-to-open lands at the same rest position `Drawer`'s own tap-to-open does. Same for `edgeInset` (see [Safe area](#safe-area)): pass the same value to both, or their rest/max geometry will disagree.
186
211
 
187
- `DrawerEdgeSwipe` alone also takes `insetTop`/`insetBottom`/`insetLeft`/`insetRight` (all default `0`), which shrink the edge-swipe hitbox's span along its long axis — only the pair perpendicular to `side`'s own strip thickness applies: `insetTop`/`insetBottom` for a `left`/`right` drawer's vertical strip, `insetLeft`/`insetRight` for a `top`/`bottom` drawer's horizontal one; the other pair is ignored. Use these to carve out chrome near the edge — a header or tab bar — that would otherwise have its own taps stolen by a hitbox spanning the full screen. Don't confuse this with `edgeInset` (see [Safe area](#safe-area)): that shrinks the *basis* a percentage size resolves against, on both `Drawer` and `DrawerEdgeSwipe`; these inset props only trim `DrawerEdgeSwipe`'s own hitbox span and have no equivalent on `Drawer` or `createDrawer()`.
212
+ `DrawerEdgeSwipe` alone also takes `insetTop`/`insetBottom`/`insetLeft`/`insetRight` (all default `0`), which shrink the edge-swipe hitbox's span along its long axis - only the pair perpendicular to `side`'s own strip thickness applies: `insetTop`/`insetBottom` for a `left`/`right` drawer's vertical strip, `insetLeft`/`insetRight` for a `top`/`bottom` drawer's horizontal one; the other pair is ignored. Use these to carve out chrome near the edge - a header or tab bar - that would otherwise have its own taps stolen by a hitbox spanning the full screen. Don't confuse this with `edgeInset` (see [Safe area](#safe-area)): that shrinks the *basis* a percentage size resolves against, on both `Drawer` and `DrawerEdgeSwipe`; these inset props only trim `DrawerEdgeSwipe`'s own hitbox span and have no equivalent on `Drawer` or `createDrawer()`.
188
213
 
189
214
  `Drawer` also takes an `onClosed?: () => void`, fired once the close spring actually settles rather than the instant `open` flips to `false`: this is what powers `isVisible` above; drive it yourself the same way if you're managing `open` state by hand. `onOpened?: () => void` is the same idea for the open direction: fired once the panel has actually finished sliding in, e.g. to autofocus a field inside `content` only once it's actually on screen. `createDrawer()` doesn't need it internally (nothing downstream waits on the open side settling the way `isVisible` waits on the close side), so it's only available driving `Drawer` directly.
190
215
 
package/dist/index.d.mts CHANGED
@@ -120,4 +120,12 @@ type DrawerEdgeSwipeProps = {
120
120
  };
121
121
  declare const DrawerEdgeSwipe: ({ edgeInset, enabled, height, insetBottom, insetLeft, insetRight, insetTop, maxHeight, maxWidth, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
122
122
 
123
- export { type AutoPaperModule, type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, type DrawerConfig, type DrawerDimension, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type DrawerInstanceProviderComponent, type DrawerInstanceProviderProps, type DrawerProps, DrawerProvider, type DrawerProviderProps, type DrawerSide, combineDrawerProviders, configureDrawer, createDrawer, getDrawerConfig };
123
+ type DrawerSize = {
124
+ effectiveSize: number;
125
+ closedOffset: number;
126
+ maxEffectiveSize: number;
127
+ restOffset: number;
128
+ };
129
+ declare function useDrawerSize(side: DrawerSide, size: DrawerDimension, maxSize?: DrawerDimension, edgeInset?: number): DrawerSize;
130
+
131
+ export { type AutoPaperModule, type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, type DrawerConfig, type DrawerDimension, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type DrawerInstanceProviderComponent, type DrawerInstanceProviderProps, type DrawerProps, DrawerProvider, type DrawerProviderProps, type DrawerSide, type DrawerSize, combineDrawerProviders, configureDrawer, createDrawer, getDrawerConfig, useDrawerSize };
package/dist/index.d.ts CHANGED
@@ -120,4 +120,12 @@ type DrawerEdgeSwipeProps = {
120
120
  };
121
121
  declare const DrawerEdgeSwipe: ({ edgeInset, enabled, height, insetBottom, insetLeft, insetRight, insetTop, maxHeight, maxWidth, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
122
122
 
123
- export { type AutoPaperModule, type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, type DrawerConfig, type DrawerDimension, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type DrawerInstanceProviderComponent, type DrawerInstanceProviderProps, type DrawerProps, DrawerProvider, type DrawerProviderProps, type DrawerSide, combineDrawerProviders, configureDrawer, createDrawer, getDrawerConfig };
123
+ type DrawerSize = {
124
+ effectiveSize: number;
125
+ closedOffset: number;
126
+ maxEffectiveSize: number;
127
+ restOffset: number;
128
+ };
129
+ declare function useDrawerSize(side: DrawerSide, size: DrawerDimension, maxSize?: DrawerDimension, edgeInset?: number): DrawerSize;
130
+
131
+ export { type AutoPaperModule, type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, type DrawerConfig, type DrawerDimension, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type DrawerInstanceProviderComponent, type DrawerInstanceProviderProps, type DrawerProps, DrawerProvider, type DrawerProviderProps, type DrawerSide, type DrawerSize, combineDrawerProviders, configureDrawer, createDrawer, getDrawerConfig, useDrawerSize };
package/dist/index.js CHANGED
@@ -36,7 +36,8 @@ __export(index_exports, {
36
36
  combineDrawerProviders: () => combineDrawerProviders,
37
37
  configureDrawer: () => configureDrawer,
38
38
  createDrawer: () => createDrawer,
39
- getDrawerConfig: () => getDrawerConfig
39
+ getDrawerConfig: () => getDrawerConfig,
40
+ useDrawerSize: () => useDrawerSize
40
41
  });
41
42
  module.exports = __toCommonJS(index_exports);
42
43
 
@@ -72,6 +73,9 @@ function getOpenDirection(side) {
72
73
  function resolveDimension(value, windowSize) {
73
74
  return typeof value === "number" ? value : Number.parseFloat(value) / 100 * windowSize;
74
75
  }
76
+ function clampToWindow(size, windowSize) {
77
+ return windowSize > 0 ? Math.min(size, windowSize) : size;
78
+ }
75
79
 
76
80
  // src/useDrawerSize.ts
77
81
  var import_react_native = require("react-native");
@@ -79,8 +83,8 @@ function useDrawerSize(side, size, maxSize, edgeInset = 0) {
79
83
  const windowDimensions = (0, import_react_native.useWindowDimensions)();
80
84
  const windowSize = isVerticalSide(side) ? windowDimensions.height : windowDimensions.width;
81
85
  const percentBasis = windowSize - edgeInset;
82
- const effectiveSize = resolveDimension(size, percentBasis);
83
- const maxEffectiveSize = maxSize === void 0 ? effectiveSize : Math.max(resolveDimension(maxSize, percentBasis), effectiveSize);
86
+ const effectiveSize = clampToWindow(resolveDimension(size, percentBasis), windowSize);
87
+ const maxEffectiveSize = maxSize === void 0 ? effectiveSize : Math.max(clampToWindow(resolveDimension(maxSize, percentBasis), windowSize), effectiveSize);
84
88
  const closedOffset = getClosedOffset(side, maxEffectiveSize);
85
89
  const restOffset = getClosedOffset(side, maxEffectiveSize - effectiveSize);
86
90
  return { closedOffset, effectiveSize, maxEffectiveSize, restOffset };
@@ -267,7 +271,7 @@ var styles = import_react_native2.StyleSheet.create({
267
271
  justifyContent: "center",
268
272
  position: "absolute"
269
273
  },
270
- // See the comment above <View style={styles.panelClip}> in the render — the unconditional clip
274
+ // See the comment above <View style={styles.panelClip}> in the render - the unconditional clip
271
275
  // ancestor that keeps a translated-off-screen "closed" panel from inflating page scroll extent.
272
276
  panelClip: {
273
277
  bottom: 0,
@@ -414,5 +418,6 @@ var combineDrawerProviders = (...entries) => {
414
418
  combineDrawerProviders,
415
419
  configureDrawer,
416
420
  createDrawer,
417
- getDrawerConfig
421
+ getDrawerConfig,
422
+ useDrawerSize
418
423
  });
package/dist/index.mjs CHANGED
@@ -30,6 +30,9 @@ function getOpenDirection(side) {
30
30
  function resolveDimension(value, windowSize) {
31
31
  return typeof value === "number" ? value : Number.parseFloat(value) / 100 * windowSize;
32
32
  }
33
+ function clampToWindow(size, windowSize) {
34
+ return windowSize > 0 ? Math.min(size, windowSize) : size;
35
+ }
33
36
 
34
37
  // src/useDrawerSize.ts
35
38
  import { useWindowDimensions } from "react-native";
@@ -37,8 +40,8 @@ function useDrawerSize(side, size, maxSize, edgeInset = 0) {
37
40
  const windowDimensions = useWindowDimensions();
38
41
  const windowSize = isVerticalSide(side) ? windowDimensions.height : windowDimensions.width;
39
42
  const percentBasis = windowSize - edgeInset;
40
- const effectiveSize = resolveDimension(size, percentBasis);
41
- const maxEffectiveSize = maxSize === void 0 ? effectiveSize : Math.max(resolveDimension(maxSize, percentBasis), effectiveSize);
43
+ const effectiveSize = clampToWindow(resolveDimension(size, percentBasis), windowSize);
44
+ const maxEffectiveSize = maxSize === void 0 ? effectiveSize : Math.max(clampToWindow(resolveDimension(maxSize, percentBasis), windowSize), effectiveSize);
42
45
  const closedOffset = getClosedOffset(side, maxEffectiveSize);
43
46
  const restOffset = getClosedOffset(side, maxEffectiveSize - effectiveSize);
44
47
  return { closedOffset, effectiveSize, maxEffectiveSize, restOffset };
@@ -225,7 +228,7 @@ var styles = StyleSheet.create({
225
228
  justifyContent: "center",
226
229
  position: "absolute"
227
230
  },
228
- // See the comment above <View style={styles.panelClip}> in the render — the unconditional clip
231
+ // See the comment above <View style={styles.panelClip}> in the render - the unconditional clip
229
232
  // ancestor that keeps a translated-off-screen "closed" panel from inflating page scroll extent.
230
233
  panelClip: {
231
234
  bottom: 0,
@@ -371,5 +374,6 @@ export {
371
374
  combineDrawerProviders,
372
375
  configureDrawer,
373
376
  createDrawer,
374
- getDrawerConfig
377
+ getDrawerConfig,
378
+ useDrawerSize
375
379
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rific/drawer",
3
- "version": "0.6.2",
3
+ "version": "0.7.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
@@ -31,18 +31,18 @@ const useBlurFallback = (override?: boolean) => override ?? false
31
31
  export type DrawerPanelShadow = {
32
32
  blurRadius?: number
33
33
  color?: string
34
- // Magnitude only, in px — always positive, regardless of `side`. The actual signed offset
34
+ // Magnitude only, in px - always positive, regardless of `side`. The actual signed offset
35
35
  // (which way the shadow falls) is derived from `side` internally, the same way DrawerEdgeSwipe
36
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
37
+ // right/bottom-anchored panel (an easy mistake - see this prop's own top-level doc comment) is
38
38
  // exactly the bug this exists to make impossible.
39
39
  distance?: number
40
- // Android's own native shadow system, alongside (not instead of) the boxShadow above — the two
40
+ // Android's own native shadow system, alongside (not instead of) the boxShadow above - the two
41
41
  // aren't redundant: boxShadow is what actually paints on iOS/web, and while the New
42
42
  // Architecture's Fabric renderer does translate boxShadow to a real shadow on Android too,
43
43
  // elevation is the longer-established, better-tested path there and worth keeping as a belt-
44
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
45
+ // could run on. Defaults to blurRadius itself - the same plain magnitude-to-elevation
46
46
  // correspondence a consumer would otherwise hand-roll (this mirrors what this repo's own past
47
47
  // panelContent styles, now replaced by this prop, always did: elevation set to the same number
48
48
  // as blurRadius). Rendered on the SAME view panelShadowVisibilityStyle animates the opacity of,
@@ -72,11 +72,11 @@ export type DrawerProps = {
72
72
  // content-facing edge) rather than claiming space inside it.
73
73
  dismissible?: boolean
74
74
  // Shrinks the basis a *percentage* height/width/maxHeight/maxWidth resolves against, so `'100%'`
75
- // fills exactly up to `edgeInset` px short of the screen's edge instead of reaching it — e.g.
75
+ // fills exactly up to `edgeInset` px short of the screen's edge instead of reaching it - e.g.
76
76
  // `edgeInset={insets.top}` on a `bottom` sheet with `maxHeight: '100%'` stops it just short of the
77
77
  // status bar/notch, rather than sliding behind it. The geometry-clamp alternative to padding
78
78
  // `content` away from a safe-area inset (see the README's Safe area section): the panel itself
79
- // never reaches the inset, so there's nothing inside `content` to compensate for — don't combine
79
+ // never reaches the inset, so there's nothing inside `content` to compensate for - don't combine
80
80
  // the two for the same edge, or the inset ends up applied twice. Has no effect on a plain px
81
81
  // number: that's taken as the exact size you asked for, same as always, letting you opt back out
82
82
  // of the inset for a specific drawer by passing a literal value instead of a percentage. Defaults
@@ -109,13 +109,13 @@ export type DrawerProps = {
109
109
  // autofocusing a field inside `content` only once it's actually on screen.
110
110
  onOpened?: () => void
111
111
  open: boolean
112
- // Off by default (this is a real, paid render — an extra always-mounted Animated.View — not
112
+ // Off by default (this is a real, paid render - an extra always-mounted Animated.View - not
113
113
  // free to opt every consumer into). true uses sensible defaults (2px distance, 8px blur, 30%
114
114
  // black); pass a DrawerPanelShadow to override any of those. Opacity fades in/out together with
115
115
  // the handle strip's own pill (both driven by the same visibleSize), rather than being either
116
116
  // permanently on or permanently off: a plain static shadow on the panel bleeds past its own
117
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) —
118
+ // closed panel sits exactly flush against the screen edge (translateOffset === closedOffset) -
119
119
  // shadow rendering doesn't know or care that its box is off-screen, so a few px of blur reads as
120
120
  // a permanent, unwanted line along that edge, closed or not.
121
121
  panelShadow?: boolean | DrawerPanelShadow
@@ -150,12 +150,12 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
150
150
  const panelShadowElevation = resolvedPanelShadow?.elevation ?? panelShadowBlurRadius
151
151
  // Same sign convention as the "opens toward" direction below (openDirection: 1 for left/top, -1
152
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.
153
+ // sits on its open side - which is exactly the side its own drag-to-open motion points toward.
154
154
  const panelShadowMagnitude = panelShadowDistance * openDirection
155
155
  const panelShadowStyle: ViewStyle = { boxShadow: [{ offsetX: vertical ? 0 : panelShadowMagnitude, offsetY: vertical ? panelShadowMagnitude : 0, blurRadius: panelShadowBlurRadius, color: panelShadowColor }], elevation: panelShadowElevation }
156
156
 
157
157
  const [measuredSize, setMeasuredSize] = useState<number | null>(null)
158
- // Tracks the last value actually committed to measuredSize, rounded — see handleLayout below for
158
+ // Tracks the last value actually committed to measuredSize, rounded - see handleLayout below for
159
159
  // why the comparison has to happen against this rather than just re-deriving it from measuredSize
160
160
  // itself on every call.
161
161
  const lastMeasuredRef = useRef<number | null>(null)
@@ -178,7 +178,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
178
178
 
179
179
  useEffect(() => {
180
180
  if (open) {
181
- // Rests at restOffset (== 0, fully expanded, when there's no maxHeight/maxWidth — identical
181
+ // Rests at restOffset (== 0, fully expanded, when there's no maxHeight/maxWidth - identical
182
182
  // to before), not always 0: an expandable sheet opens to its rest size, not its max size.
183
183
  translateOffset.value = withSpring(restOffset, SPRING, (finished) => {
184
184
  if (finished && onOpened) runOnJS(onOpened)()
@@ -202,7 +202,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
202
202
 
203
203
  const drawerStyle = useAnimatedStyle(() => ({ transform: [vertical ? { translateY: translateOffset.value } : { translateX: translateOffset.value }] }))
204
204
  // Denominator is maxEffectiveSize, not effectiveSize/rest: dims proportionally to how much of the
205
- // panel's full (possibly-expanded) size is currently covering the screen, not just its rest size —
205
+ // panel's full (possibly-expanded) size is currently covering the screen, not just its rest size -
206
206
  // otherwise a still-collapsing expandable sheet would hit full backdropOpacity well before it's
207
207
  // actually fully open. Reduces to today's exact behavior when there's no maxHeight/maxWidth, since
208
208
  // maxEffectiveSize === effectiveSize then.
@@ -213,14 +213,14 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
213
213
  const backdropStyle = useAnimatedStyle(() => ({ opacity: maxEffectiveSize > 0 ? (1 - Math.abs(translateOffset.value) / maxEffectiveSize) * backdropOpacity : 0 }))
214
214
  const animatedSizeStyle = useAnimatedStyle(() => (vertical ? { height: animatedSize.value } : { width: animatedSize.value }))
215
215
  // 'box-none' (not 'auto'): this wrapper is just a positioning shell around the dimming tint and
216
- // the actual tap-catching view below — on react-native-web, an ancestor's own explicit zIndex
216
+ // the actual tap-catching view below - on react-native-web, an ancestor's own explicit zIndex
217
217
  // wins hit-testing over a plain-DOM-order sibling's lower-tier descendants (the panel lives inside
218
- // panelClip, which now carries the panel's tier itself — see its comment), so this wrapper being 'auto' made
218
+ // panelClip, which now carries the panel's tier itself - see its comment), so this wrapper being 'auto' made
219
219
  // its own full-screen box outrank the panel for every click anywhere on screen, even where the
220
- // panel visually covers it — a tap on real panel content (e.g. a settings toggle) would land on
220
+ // panel visually covers it - a tap on real panel content (e.g. a settings toggle) would land on
221
221
  // this inert wrapper instead and silently do nothing. 'box-none' keeps the wrapper itself out of
222
222
  // hit-testing while still letting its own children (the tap-catcher below) receive touches within
223
- // their own (now-shrunk, see backdropTapAreaStyle) bounds — exactly the "auto" behavior this was
223
+ // their own (now-shrunk, see backdropTapAreaStyle) bounds - exactly the "auto" behavior this was
224
224
  // meant to have, minus the container falsely claiming space it doesn't actually own.
225
225
  //
226
226
  //
@@ -233,12 +233,12 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
233
233
  const backdropPointerEvents = open && blockingBackdrop ? 'box-none' : 'none'
234
234
  // react-native-gesture-handler's web backend resolves a Gesture.Tap's hit region from this
235
235
  // view's own measured bounds, not from real DOM occlusion/z-index the way native UIKit/Android
236
- // hit-testing does — so on web, a tap landing anywhere on the (opaque, higher-zIndex) panel on
236
+ // hit-testing does - so on web, a tap landing anywhere on the (opaque, higher-zIndex) panel on
237
237
  // top of this backdrop was still satisfying the backdrop's OWN Tap gesture underneath it,
238
238
  // closing the drawer out from under a perfectly normal tap on its content (e.g. a toggle inside
239
239
  // a settings panel). Native is unaffected (its real view hierarchy already occludes correctly),
240
240
  // but shrinking this view's own bounds to exclude the panel's footprint is correct on every
241
- // platform regardless — that region was always hidden behind the opaque panel anyway, so this
241
+ // platform regardless - that region was always hidden behind the opaque panel anyway, so this
242
242
  // changes nothing observable, it just stops the gesture from being reachable there at all.
243
243
  const backdropTapAreaStyle: ViewStyle = side === 'left' ? { left: maxEffectiveSize } : side === 'right' ? { right: maxEffectiveSize } : side === 'top' ? { top: maxEffectiveSize } : { bottom: maxEffectiveSize }
244
244
 
@@ -250,14 +250,14 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
250
250
  // Rounded (not the raw sub-pixel float layout reports) and short-circuited against the last value
251
251
  // actually committed: an animated ancestor (animatedSizeStyle below, mid-withTiming) can cause
252
252
  // Yoga to re-measure this supposedly content-unconstrained wrapper on every frame it's still
253
- // moving, and floating-point noise between passes (e.g. 283.3333740234375 vs 283.33331298828125 —
253
+ // moving, and floating-point noise between passes (e.g. 283.3333740234375 vs 283.33331298828125 -
254
254
  // the same logical height, off by ~1/16000th of a pixel) is "different" by strict equality. Left
255
255
  // unguarded, that noise commits a "new" measuredSize every frame, which restarts the very
256
- // withTiming animation that's causing the re-measurement in the first place — a self-sustaining
256
+ // withTiming animation that's causing the re-measurement in the first place - a self-sustaining
257
257
  // loop that never lets the height settle, seen as a stutter rather than a single smooth resize.
258
258
  // Comparing against a ref (not measuredSize itself) matters here: measuredSize is the state that's
259
259
  // deliberately being skipped on a no-op call, so re-deriving the comparison from it would still
260
- // see the same (unchanged) value next time regardless — the ref is what actually remembers what
260
+ // see the same (unchanged) value next time regardless - the ref is what actually remembers what
261
261
  // was last committed.
262
262
  const handleLayout = (event: LayoutChangeEvent) => {
263
263
  const measured = Math.round(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width)
@@ -300,10 +300,10 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
300
300
  )
301
301
  // contentSize's measuring wrapper above is deliberately given no style of its own (see the
302
302
  // comment above `fillStyle`): it must report ITS OWN natural size, which only works if `children`
303
- // itself has an intrinsic height Yoga can compute directly from its subtree — e.g. plain
303
+ // itself has an intrinsic height Yoga can compute directly from its subtree - e.g. plain
304
304
  // Views/Text/FABs, including a `flexWrap: 'wrap'` row like FabRow. A `ScrollView` breaks this: on
305
- // native, ScrollView's outer box does NOT size itself to its content the way a plain View does —
306
- // it needs a bounded height from an ANCESTOR instead (see ScrollView's own docs) — so measuring
305
+ // native, ScrollView's outer box does NOT size itself to its content the way a plain View does -
306
+ // it needs a bounded height from an ANCESTOR instead (see ScrollView's own docs) - so measuring
307
307
  // one via onLayout here reports some small, real-but-wrong box height (whatever Yoga happens to
308
308
  // resolve it to absent an explicit bound) rather than the content's true extent, and clips
309
309
  // anything beyond that. contentSize's `children` must render its own natural-height content
@@ -326,17 +326,17 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
326
326
  // the panel slides back toward), gesture-matched to `side` the same way DrawerEdgeSwipe is. With no
327
327
  // maxHeight/maxWidth it's a simple two-point toggle, same as before: starts from the OPEN/rest
328
328
  // position (restOffset, which equals 0 in that case) and commits toward `closedOffset` or springs
329
- // back. With one, it's three points along the same axis — closedOffset, restOffset, and fully
330
- // expanded (0) — and the drag can commit toward whichever of those neighbors it's currently
329
+ // back. With one, it's three points along the same axis - closedOffset, restOffset, and fully
330
+ // expanded (0) - and the drag can commit toward whichever of those neighbors it's currently
331
331
  // nearest, in either direction. Deliberately its own hit area rather than the whole panel, so it
332
332
  // can't steal touches from arbitrary interactive content inside `children`.
333
333
  const clampMin = Math.min(0, closedOffset)
334
334
  const clampMax = Math.max(0, closedOffset)
335
335
 
336
336
  // A single signed offset (e.g. closeDirection * 10) only arms the gesture for drags past that
337
- // threshold in ONE direction — exactly what the plain close-only case wants (dragging the "wrong"
337
+ // threshold in ONE direction - exactly what the plain close-only case wants (dragging the "wrong"
338
338
  // way, further into "already open," should fall through rather than eat the touch), but it means a
339
- // drag toward expanding — the opposite direction — never activates the gesture at all. With no
339
+ // drag toward expanding - the opposite direction - never activates the gesture at all. With no
340
340
  // maxHeight/maxWidth (restOffset always 0) that's fine, since there's nothing to expand into: keep
341
341
  // the single-direction threshold, unchanged from before. Once expansion is possible, the gesture
342
342
  // needs to recognize BOTH directions, so it switches to a symmetric range instead.
@@ -380,7 +380,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
380
380
  const velocity = vertical ? event.velocityY : event.velocityX
381
381
  // Everything below works in "closing-direction" units (closeDirection-normalized), where 0 is
382
382
  // always fully expanded and larger is always closer to closed, regardless of `side`'s sign
383
- // convention — the same trick the old single-segment formula used, just reused per segment.
383
+ // convention - the same trick the old single-segment formula used, just reused per segment.
384
384
  const velocityD = velocity * closeDirection
385
385
  const currentD = translateOffset.value * closeDirection
386
386
  const restD = restOffset * closeDirection // 0 when there's no maxHeight/maxWidth
@@ -391,7 +391,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
391
391
  // progress 1): traveled = restD - currentD, since currentD counts down from restD to 0 as
392
392
  // the drag moves toward expanding. Same 1/3-traveled threshold as the rest/closed segment
393
393
  // below, just scoped to this segment's own length and direction; a fast fling toward
394
- // expanding (velocityD very negative — the opposite sign from the closing fling below) also
394
+ // expanding (velocityD very negative - the opposite sign from the closing fling below) also
395
395
  // commits, regardless of distance covered.
396
396
  const progress = restD > 0 ? (restD - currentD) / restD : 1
397
397
  target = progress > 1 / 3 || velocityD < -VELOCITY_THRESHOLD ? 0 : restOffset
@@ -419,26 +419,26 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
419
419
  // minimum touch target) without the pill itself growing or the strip visually eating panel space.
420
420
  // Deliberately not done via Gesture.Pan().hitSlop(): react-native-gesture-handler's web backend
421
421
  // binds its pointer listeners directly to the strip's own DOM node, so a pointer genuinely outside
422
- // that node's rendered box never reaches the handler there at all — hitSlop only helps on native,
422
+ // that node's rendered box never reaches the handler there at all - hitSlop only helps on native,
423
423
  // where the OS extends the touch region a different way. Growing the real box, below, works
424
424
  // everywhere a pointer/touch can actually land.
425
425
  const HANDLE_HIT_SLOP = 20
426
426
  const HANDLE_STRIP_TOTAL_THICKNESS = HANDLE_STRIP_THICKNESS + HANDLE_HIT_SLOP
427
427
  const handleStripSizeStyle: ViewStyle = vertical ? { height: HANDLE_STRIP_TOTAL_THICKNESS, left: 0, right: 0 } : { bottom: 0, top: 0, width: HANDLE_STRIP_TOTAL_THICKNESS }
428
428
  // Sits OUTSIDE the panel's own box rather than claiming interior visual space. Anchored from the
429
- // FAR (backdrop-facing) edge — the opposite side from `side` — since that edge's distance from the
429
+ // FAR (backdrop-facing) edge - the opposite side from `side` - since that edge's distance from the
430
430
  // panel is the one constant here (always exactly HANDLE_STRIP_THICKNESS past the panel, same as
431
431
  // before this box grew): [oppositeSide]: -HANDLE_STRIP_THICKNESS fixes it there, and the box's full
432
432
  // HANDLE_STRIP_TOTAL_THICKNESS width/height extends back from that fixed point, covering the
433
433
  // original strip's footprint plus HANDLE_HIT_SLOP more, into the panel. `right`/`left`/`top`/
434
- // `bottom` values are always relative to the parent's actual current edge, so — like the old
435
- // percentage-based version — this still tracks correctly while contentSize is animating the
434
+ // `bottom` values are always relative to the parent's actual current edge, so - like the old
435
+ // percentage-based version - this still tracks correctly while contentSize is animating the
436
436
  // panel's size. Requires drawerOuterStyle to stay unclipped (see its comment above) or this would
437
437
  // be cut off.
438
438
  const oppositeSide = side === 'left' ? 'right' : side === 'right' ? 'left' : side === 'top' ? 'bottom' : 'top'
439
439
  const handleStripEdgeStyle: ViewStyle = { [oppositeSide]: -HANDLE_STRIP_THICKNESS }
440
440
  // React Native sizes width/height as the outer box (unlike default web CSS box-sizing), so this
441
- // padding — on the panel-facing side only — shrinks just the flex CONTENT area back down to the
441
+ // padding - on the panel-facing side only - shrinks just the flex CONTENT area back down to the
442
442
  // original 28px, without changing the box's own outer bounds. alignItems/justifyContent below then
443
443
  // center the pill within that content area, landing it at exactly its pre-hit-slop spot: only the
444
444
  // invisible margin around it grew.
@@ -453,7 +453,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
453
453
  // panel's own content, it isn't carried off-screen by the panel's close translation: that
454
454
  // translation is only ever calibrated to hide the panel's own maxEffectiveSize, not the strip's
455
455
  // extra thickness beyond it. Once less than the strip's own thickness of panel remains visible,
456
- // there's no panel edge left for it to be flush against, so it's hidden — otherwise it wells up
456
+ // there's no panel edge left for it to be flush against, so it's hidden - otherwise it wells up
457
457
  // sitting right at the screen edge looking like the drawer is still (a little) open, even at rest
458
458
  // fully closed. visibleSize mirrors the gesture's own D-space trick above: 0 at fully closed,
459
459
  // maxEffectiveSize at fully expanded, regardless of `side`'s sign convention.
@@ -466,7 +466,7 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
466
466
  // the panel's true edge) rather than snapping like the handle strip's own binary visibleSize
467
467
  // check above: by the time visibleSize passes that point, the panel edge itself is already
468
468
  // further onto the screen than the shadow ever bled, so there's no longer a "fake" shadow to
469
- // distinguish from a real one — full opacity is correct from there on. Always computed (hooks
469
+ // distinguish from a real one - full opacity is correct from there on. Always computed (hooks
470
470
  // can't be called conditionally) even when panelShadow is falsy; harmless, since the style is
471
471
  // never applied to anything in that case.
472
472
  const panelShadowFadeDistance = panelShadowBlurRadius + panelShadowDistance
@@ -482,42 +482,42 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
482
482
  backdropStyle's animated opacity, separate from the tap-catching view below and from the
483
483
  OUTER container above (which must stay paint-free, not just visually transparent at
484
484
  opacity 0): on iOS, a view at opacity 0 (e.g. backdropOpacity={0}, an intentional no-dim
485
- backdrop — see controlGroups.tsx) is excluded from hit-testing entirely by UIKit,
485
+ backdrop - see controlGroups.tsx) is excluded from hit-testing entirely by UIKit,
486
486
  regardless of pointerEvents. That's fine for a purely decorative tint, but it would
487
- silently make the whole backdrop untouchable too if the SAME view carried both — and if
487
+ silently make the whole backdrop untouchable too if the SAME view carried both - and if
488
488
  the outer container carried the background color instead, it would paint solid black at
489
489
  full opacity at all times (no animated opacity of its own), open or not. */}
490
490
  <Animated.View style={[styles.backdropTint, backdropStyle]} pointerEvents='none' />
491
491
  <GestureDetector gesture={backdropTapGesture}>
492
492
  {/* collapsable={false}: this view has no paint properties of its own (no background,
493
493
  no animated style), exactly the shape React Native's view-flattening optimizer removes
494
- from the native tree on native platforms — leaving the GestureDetector above with no real
494
+ from the native tree on native platforms - leaving the GestureDetector above with no real
495
495
  view left to attach its tap recognizer to, so it would silently never receive a touch.
496
- backdropTapAreaStyle shrinks this view's own bounds to exclude the panel's footprint —
496
+ backdropTapAreaStyle shrinks this view's own bounds to exclude the panel's footprint -
497
497
  see its own comment above for why that matters specifically on web. */}
498
498
  <Animated.View collapsable={false} style={[StyleSheet.absoluteFill, backdropTapAreaStyle]} />
499
499
  </GestureDetector>
500
500
  </Animated.View>
501
- {/* panelClip is a NEW, unconditional clipping ancestor around the panel — NOT the same box as
501
+ {/* panelClip is a NEW, unconditional clipping ancestor around the panel - NOT the same box as
502
502
  drawerOuterStyle/styles.drawer, and deliberately not itself transformed. drawerOuterStyle
503
503
  carries the open/closed translate (drawerStyle) and is anchored flush to its edge at its
504
- FULL maxEffectiveSize (sizeStyle) — so a "closed" panel is never actually removed from the
504
+ FULL maxEffectiveSize (sizeStyle) - so a "closed" panel is never actually removed from the
505
505
  tree, only slid to closedOffset, which for side='right'/'bottom' lands at a POSITIVE
506
- coordinate just past the visible edge (see geometry.ts's getClosedOffset — left/top land at
506
+ coordinate just past the visible edge (see geometry.ts's getClosedOffset - left/top land at
507
507
  NEGATIVE coordinates instead, which ordinary page scroll can't reach, which is why this only
508
508
  ever showed up on right/bottom drawers). With nothing upstream constraining that positive
509
509
  offset, react-native-web's host page treats the translated-but-still-full-size panel as real
510
- document content sitting just outside the viewport, which grows the page's scrollable area —
510
+ document content sitting just outside the viewport, which grows the page's scrollable area -
511
511
  scrolling into it reveals a fully rendered "closed" panel. Adding overflow:'hidden' directly
512
512
  to styles.drawer itself is NOT the fix: that's the same box the transform moves, so its own
513
513
  clip region would travel with it and cut off the handle strip below, which is deliberately
514
514
  positioned outside drawerOuterStyle's bounds (see its own comment). panelClip instead fills
515
515
  the drawer's whole mount area (never itself transformed) and clips ITS bounds, which stay
516
- fixed regardless of where the translated panel inside it currently sits — so the handle strip
516
+ fixed regardless of where the translated panel inside it currently sits - so the handle strip
517
517
  (well within panelClip's much larger box) is unaffected, while a closed panel translated past
518
518
  panelClip's edge is clipped from paint and stops contributing to page scroll extent.
519
519
  pointerEvents='box-none': this wrapper spans the full mount area purely to establish the clip
520
- boundary — it must never itself catch a touch, only its real content underneath should.
520
+ boundary - it must never itself catch a touch, only its real content underneath should.
521
521
  zIndex + 1 (the panel's own tier) ON panelClip itself: react-native-web gives every View
522
522
  z-index 0, which makes panelClip a stacking context of its own, so the panel's zIndex + 1
523
523
  only ranks it inside panelClip. Without a tier here, the backdrop (zIndex, a sibling of
@@ -535,13 +535,13 @@ export const Drawer = ({ backdropOpacity = 0.45, blockingBackdrop = true, blur,
535
535
  <GestureDetector gesture={handleGesture}>
536
536
  {/* pointerEvents mirrors handleGesture's own .enabled(open) above, the same way the
537
537
  backdrop's tap-catcher mirrors backdropTapGesture's .enabled(open && blockingBackdrop)
538
- just above — handleVisibilityStyle's opacity already fades this strip out once the
538
+ just above - handleVisibilityStyle's opacity already fades this strip out once the
539
539
  panel's closed, but opacity alone doesn't stop hit-testing on web/Android (unlike iOS,
540
- which excludes opacity-0 views from hit-testing regardless of pointerEvents — see the
540
+ which excludes opacity-0 views from hit-testing regardless of pointerEvents - see the
541
541
  backdrop tint's own comment on that asymmetry). Left at 'auto' while closed, this
542
- 48px-wide strip sits at zIndex+2 flush against the screen edge closest to `side` —
542
+ 48px-wide strip sits at zIndex+2 flush against the screen edge closest to `side` -
543
543
  easy to land a consumer's own edge-anchored chrome (an app bar icon, say) in that same
544
- band — and swallows taps meant for whatever's underneath it despite being invisible
544
+ band - and swallows taps meant for whatever's underneath it despite being invisible
545
545
  AND, since the gesture itself is disabled here too, unable to do anything with them
546
546
  either. */}
547
547
  <Animated.View style={[styles.handleStrip, handleStripSizeStyle, handleStripEdgeStyle, handleStripPaddingStyle, webCursorStyle, handleVisibilityStyle, handleStripInteractionStyle]}>{showHandle && <View style={[styles.handlePill, handlePillStyle, { backgroundColor: colors.surface }]} />}</Animated.View>
@@ -603,7 +603,7 @@ const styles = StyleSheet.create({
603
603
  justifyContent: 'center',
604
604
  position: 'absolute'
605
605
  },
606
- // See the comment above <View style={styles.panelClip}> in the render — the unconditional clip
606
+ // See the comment above <View style={styles.panelClip}> in the render - the unconditional clip
607
607
  // ancestor that keeps a translated-off-screen "closed" panel from inflating page scroll extent.
608
608
  panelClip: {
609
609
  bottom: 0,
@@ -20,7 +20,7 @@ export type DrawerEdgeSwipeProps = {
20
20
  enabled?: boolean
21
21
  height?: DrawerDimension
22
22
  // Shrink the strip's span along its long axis, to clear chrome (a header, a tab bar, ...) that
23
- // would otherwise have its own touches stolen by this gesture — only the pair perpendicular to
23
+ // would otherwise have its own touches stolen by this gesture - only the pair perpendicular to
24
24
  // `side`'s own strip thickness applies: insetTop/insetBottom for a left/right drawer's vertical
25
25
  // strip, insetLeft/insetRight for a top/bottom drawer's horizontal one. The other pair is
26
26
  // ignored. All default to 0 (the strip's prior, full-length behavior).
@@ -29,7 +29,7 @@ export type DrawerEdgeSwipeProps = {
29
29
  insetRight?: number
30
30
  insetTop?: number
31
31
  // Mirrors Drawer's own maxHeight: when set, an edge swipe still only opens to `height` (the rest
32
- // size), not all the way to this ceiling — matching Drawer's tap-to-open behavior, which also
32
+ // size), not all the way to this ceiling - matching Drawer's tap-to-open behavior, which also
33
33
  // lands at rest. Reaching past rest, up to maxHeight, is only ever done via Drawer's own handle.
34
34
  maxHeight?: DrawerDimension
35
35
  // The maxWidth mirror of maxHeight, for `left`/`right` drawers.
@@ -61,7 +61,7 @@ export const DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, i
61
61
  'worklet'
62
62
  const translation = vertical ? event.translationY : event.translationX
63
63
  // react-hooks/immutability flags this because translateOffset is a prop, but mutating a
64
- // Reanimated SharedValue's .value is the correct way to drive it — not a prop reassignment.
64
+ // Reanimated SharedValue's .value is the correct way to drive it - not a prop reassignment.
65
65
  // eslint-disable-next-line react-hooks/immutability
66
66
  translateOffset.value = Math.min(clampMax, Math.max(clampMin, closedOffset + translation))
67
67
  })
@@ -85,7 +85,7 @@ export const DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, i
85
85
  return (
86
86
  <GestureDetector gesture={gesture}>
87
87
  {/* Same web-only affordance Drawer.tsx's own handle strip gives its drag grip (see its
88
- webCursorStyle) — without it, nothing on screen hints that this edge is draggable at
88
+ webCursorStyle) - without it, nothing on screen hints that this edge is draggable at
89
89
  all on a platform with a mouse cursor to change in the first place.
90
90
 
91
91
  pointerEvents here (not just gesture.enabled(enabled) above) matters on web specifically:
@@ -93,7 +93,7 @@ export const DrawerEdgeSwipe = ({ edgeInset = 0, enabled = true, height = 300, i
93
93
  doesn't stop this View's underlying DOM node from being hit-tested. Without this, a caller
94
94
  passing enabled={false} to shed the edge-swipe-to-open behavior (e.g. because their own
95
95
  screen never uses it) still ends up with this zone as an invisible, unconditionally opaque
96
- strip along the edge — silently swallowing presses meant for anything else placed there,
96
+ strip along the edge - silently swallowing presses meant for anything else placed there,
97
97
  even though the gesture it exists for no longer does anything. 'none' when disabled lets
98
98
  that click/tap fall straight through to whatever's actually underneath. */}
99
99
  <View style={[...edgeStyle, webCursorStyle, enabled ? styles.interactive : styles.nonInteractive]} />
@@ -9,14 +9,14 @@ import { useDrawerSize } from './useDrawerSize'
9
9
 
10
10
  export type DrawerActions = {
11
11
  close: () => void
12
- // 0 anywhere at or before `height`/`width` (closed, or resting at its default open size —
12
+ // 0 anywhere at or before `height`/`width` (closed, or resting at its default open size -
13
13
  // nothing to indicate, since the panel isn't showing any more than that), 1 once a drag has
14
14
  // pulled it all the way open to `maxHeight`/`maxWidth`, smoothly interpolating in between as the
15
15
  // handle is dragged or the spring animates. For content that only needs to react once the panel
16
- // is genuinely at its full extent — e.g. fading in a top safe-area inset that's wasted space while
16
+ // is genuinely at its full extent - e.g. fading in a top safe-area inset that's wasted space while
17
17
  // merely at rest, but genuinely needed once expansion reaches the screen edge/notch. This is the
18
18
  // content-padding approach to a safe-area inset; `edgeInset` (see CreateDrawerOptions) is the
19
- // alternative geometry-clamp approach, which keeps the panel itself short of the inset instead —
19
+ // alternative geometry-clamp approach, which keeps the panel itself short of the inset instead -
20
20
  // don't combine both for the same edge on the same drawer, or the inset gets applied twice. Always
21
21
  // a flat 1 while open (matching "already at full extent") when there's no maxHeight/maxWidth
22
22
  // configured.
@@ -99,7 +99,7 @@ const noop = () => {}
99
99
  // settings drawer (say) stay fully independent without a stringly-typed id to keep them apart.
100
100
  export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset = 0, height = 300, maxHeight, maxWidth, showHandle: factoryShowHandle, side = 'left', width = 300, zIndex: factoryZIndex }: CreateDrawerOptions = {}): CreateDrawerResult => {
101
101
  // Static, non-reactive stand-in for the default context value only (before any real Provider has
102
- // mounted) — same reasoning as the plain `noop` functions alongside it.
102
+ // mounted) - same reasoning as the plain `noop` functions alongside it.
103
103
  const defaultExpandProgress = { value: 1 } as SharedValue<number>
104
104
  const DrawerActionsContext = createContext<DrawerActions>({ close: noop, expandProgress: defaultExpandProgress, isOpen: false, isVisible: false, open: noop })
105
105
  const vertical = isVerticalSide(side)
@@ -129,7 +129,7 @@ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blocking
129
129
 
130
130
  // Percentages can't resolve outside a component (no window dimensions to hand), so unlike
131
131
  // Drawer/DrawerEdgeSwipe (which each resolve their own copy internally), this is the one place
132
- // createDrawer needs it directly — both for translateOffset's own initial seed, and restOffset
132
+ // createDrawer needs it directly - both for translateOffset's own initial seed, and restOffset
133
133
  // for expandProgress below. contentSize never gets a maxSize (mirrors Drawer's own
134
134
  // contentSize-has-no-expand-ceiling rule), so expandProgress is always a flat 1 there too.
135
135
  const { closedOffset, restOffset } = useDrawerSize(side, effectiveSize, contentSize ? undefined : maxSize, edgeInset)
@@ -138,7 +138,7 @@ export const createDrawer = ({ backdropOpacity: factoryBackdropOpacity, blocking
138
138
  // (kept in sync, tested there directly) for the same formula explained in more depth. Inlined
139
139
  // rather than calling that shared helper: react-native-worklets (Reanimated 4+) only forwards a
140
140
  // worklet's *relative* imports for files matching an explicit allowlist, which doesn't include
141
- // published node_modules packages by default — importing and calling it here would fail at
141
+ // published node_modules packages by default - importing and calling it here would fail at
142
142
  // runtime as an unrecognized cross-module "remote function" call from the UI thread. currentD/
143
143
  // restD are in the same closeDirection-normalized "D-space" Drawer.tsx's own gesture math uses,
144
144
  // so this stays agnostic of `side`'s sign convention.
package/src/geometry.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type DrawerSide = 'left' | 'right' | 'top' | 'bottom'
2
2
 
3
3
  // A plain pixel value, or a percentage of the relevant screen dimension (window height for
4
- // top/bottom, window width for left/right) — see resolveDimension.
4
+ // top/bottom, window width for left/right) - see resolveDimension.
5
5
  export type DrawerDimension = number | `${number}%`
6
6
 
7
7
  export function isVerticalSide(side: DrawerSide): boolean {
@@ -28,24 +28,34 @@ export function resolveDimension(value: DrawerDimension, windowSize: number): nu
28
28
  return typeof value === 'number' ? value : (Number.parseFloat(value) / 100) * windowSize
29
29
  }
30
30
 
31
+ // Caps a resolved size at the window's own size along the drawer's axis. A panel anchored flush to
32
+ // one edge can never show anything past the opposite one, so a fixed `width: 380` on a 360px-wide
33
+ // phone would otherwise just cut off its own far edge (and everything laid out against it) rather
34
+ // than fill the screen. A windowSize of 0 means the window hasn't been measured yet (web, briefly,
35
+ // before hydration), not a 0px screen: the size passes through untouched then, or a px-sized
36
+ // drawer would seed its closed offset at 0 and visibly slide shut once the real size arrives.
37
+ export function clampToWindow(size: number, windowSize: number): number {
38
+ return windowSize > 0 ? Math.min(size, windowSize) : size
39
+ }
40
+
31
41
  // How far past `height`/`width` (its rest size) an expandable sheet currently is, as a 0-1
32
- // fraction: 0 anywhere at or before rest (closed, or resting — nothing to indicate, since the
42
+ // fraction: 0 anywhere at or before rest (closed, or resting - nothing to indicate, since the
33
43
  // panel isn't showing any more than its configured rest size), 1 once fully expanded to
34
44
  // `maxHeight`/`maxWidth`, ramping smoothly in between. For content that only needs to react once
35
- // the panel is actually at its full extent — e.g. a top safe-area inset that's wasted space while
45
+ // the panel is actually at its full extent - e.g. a top safe-area inset that's wasted space while
36
46
  // merely at rest, but genuinely needed once expansion reaches the screen edge/notch.
37
47
  // currentD/restD are both expected in the same closeDirection-normalized "D-space" the gesture
38
48
  // math elsewhere uses (0 = fully expanded, larger = closer to closed), so this stays agnostic of
39
49
  // `side`'s sign convention. restD <= 0 (no maxHeight/maxWidth configured, or a degenerate config)
40
50
  // means there's no expand range to speak of: rest already IS the full extent, so this is always 1.
41
51
  // NOT actually called from createDrawer.tsx's useDerivedValue at runtime, despite computing the
42
- // exact same thing — deliberately duplicated inline there instead (see its own comment) rather
52
+ // exact same thing - deliberately duplicated inline there instead (see its own comment) rather
43
53
  // than imported, since react-native-worklets (Reanimated 4+) only forwards a worklet's *relative*
44
54
  // imports for files matching an explicit allowlist, which a published node_modules package like
45
55
  // this one isn't part of by default; an imported (not inlined) function called from inside a
46
56
  // worklet then fails at runtime as an unrecognized "remote function" call. This copy exists so the
47
57
  // interesting interpolation math (which createDrawer's own open/close-only test API can't reach)
48
- // still has a direct, isolated test — keep both in sync if this formula ever changes.
58
+ // still has a direct, isolated test - keep both in sync if this formula ever changes.
49
59
  export function getExpandProgress(currentD: number, restD: number): number {
50
60
  if (restD <= 0) return 1
51
61
  return Math.min(1, Math.max(0, (restD - currentD) / restD))
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export { Drawer, type DrawerProps } from './Drawer'
3
3
  export { type AutoPaperModule, configureDrawer, type DrawerConfig, DrawerProvider, type DrawerProviderProps, getDrawerConfig } from './DrawerConfig'
4
4
  export { DrawerEdgeSwipe, type DrawerEdgeSwipeProps } from './DrawerEdgeSwipe'
5
5
  export { type DrawerDimension, type DrawerSide } from './geometry'
6
+ export { type DrawerSize, useDrawerSize } from './useDrawerSize'
@@ -1,6 +1,6 @@
1
1
  import { useWindowDimensions } from 'react-native'
2
2
 
3
- import { type DrawerDimension, type DrawerSide, getClosedOffset, isVerticalSide, resolveDimension } from './geometry'
3
+ import { clampToWindow, type DrawerDimension, type DrawerSide, getClosedOffset, isVerticalSide, resolveDimension } from './geometry'
4
4
 
5
5
  export type DrawerSize = {
6
6
  // The panel's rest size, in px: what it opens to by default, and what a drag-to-close gesture
@@ -23,30 +23,41 @@ export type DrawerSize = {
23
23
  // current window size into concrete offsets, shared by Drawer, DrawerEdgeSwipe, and createDrawer
24
24
  // so all three always agree on where "closed"/"rest"/"expanded" actually are.
25
25
  //
26
+ // Also exported, for apps driving Drawer/DrawerEdgeSwipe standalone: pass the same side/size/
27
+ // maxSize/edgeInset the Drawer gets, then seed its translateOffset shared value with closedOffset
28
+ // (not a hand-negated size, which disagrees with the panel wherever the clamp below kicks in), and
29
+ // lay out anything sized to the panel itself (e.g. a full-width carousel page) by effectiveSize.
30
+ //
31
+ // Both sizes are capped at the window's own size along the drawer's axis (see clampToWindow): a
32
+ // fixed `width: 380` fills a 360px-wide phone exactly instead of running off its far edge, and
33
+ // every offset below follows from the capped size, so the closed panel still sits flush against
34
+ // its edge. Capped against the raw window, not the edgeInset-shrunk percentBasis below, so a plain
35
+ // px size stays clear of edgeInset exactly as described next.
36
+ //
26
37
  // edgeInset (px, default 0) shrinks the basis a *percentage* height/width/maxHeight/maxWidth
27
- // resolves against — windowSize - edgeInset instead of the raw windowSize — so `'100%'` fills
38
+ // resolves against - windowSize - edgeInset instead of the raw windowSize - so `'100%'` fills
28
39
  // exactly up to that boundary (e.g. `edgeInset={insets.top}` on a `bottom` sheet's `maxHeight:
29
40
  // '100%'` stops it just short of the status bar/notch instead of sliding behind it) rather than
30
41
  // the literal screen edge. This is the geometry-clamp alternative to padding `content` away from a
31
42
  // safe-area inset (see the README's Safe area section): the panel itself never reaches the inset,
32
- // so there's nothing inside `content` to compensate for — don't combine the two for the same edge,
43
+ // so there's nothing inside `content` to compensate for - don't combine the two for the same edge,
33
44
  // or the inset ends up applied twice.
34
45
  //
35
46
  // A plain pixel number is deliberately left untouched by edgeInset (resolveDimension ignores its
36
47
  // windowSize argument entirely for numbers, so passing the shrunk basis to it is a no-op there):
37
48
  // a percentage means "fill the available space," which should already account for a known inset,
38
49
  // while a literal px value means "this exact size," typically one the caller already computed
39
- // deliberately (including, if they want, against an inset themselves) — edgeInset silently
50
+ // deliberately (including, if they want, against an inset themselves) - edgeInset silently
40
51
  // overriding that would take away the one way to opt back out of it for a specific drawer.
41
52
  export function useDrawerSize(side: DrawerSide, size: DrawerDimension, maxSize?: DrawerDimension, edgeInset = 0): DrawerSize {
42
53
  const windowDimensions = useWindowDimensions()
43
54
  const windowSize = isVerticalSide(side) ? windowDimensions.height : windowDimensions.width
44
55
  const percentBasis = windowSize - edgeInset
45
56
 
46
- const effectiveSize = resolveDimension(size, percentBasis)
57
+ const effectiveSize = clampToWindow(resolveDimension(size, percentBasis), windowSize)
47
58
  // Guards a misconfigured maxSize smaller than size, which would otherwise produce a negative
48
59
  // "hidden" range and invert the rest/closed math below.
49
- const maxEffectiveSize = maxSize === undefined ? effectiveSize : Math.max(resolveDimension(maxSize, percentBasis), effectiveSize)
60
+ const maxEffectiveSize = maxSize === undefined ? effectiveSize : Math.max(clampToWindow(resolveDimension(maxSize, percentBasis), windowSize), effectiveSize)
50
61
 
51
62
  const closedOffset = getClosedOffset(side, maxEffectiveSize)
52
63
  const restOffset = getClosedOffset(side, maxEffectiveSize - effectiveSize)