@rific/drawer 0.2.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/README.md +98 -31
- package/dist/index.d.mts +46 -15
- package/dist/index.d.ts +46 -15
- package/dist/index.js +149 -79
- package/dist/index.mjs +137 -77
- package/package.json +14 -11
- package/src/Drawer.tsx +272 -83
- package/src/DrawerConfig.tsx +48 -0
- package/src/DrawerEdgeSwipe.tsx +22 -9
- package/src/createDrawer.tsx +75 -25
- package/src/geometry.ts +38 -2
- package/src/index.ts +3 -2
- package/src/useDrawerSize.ts +55 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rific/drawer
|
|
2
2
|
|
|
3
|
-
Sliding drawer/sheet for React Native. Spring-animated, theme-aware (reads colors from `react-native-paper`), and opens either by calling an action or by swiping in from the screen edge. Slides in from any of the four edges
|
|
3
|
+
Sliding drawer/sheet for React Native. Spring-animated, theme-aware (reads colors from `react-native-paper`), and opens either by calling an action or by swiping in from the screen edge. Slides in from any of the four edges (`left`/`right` for a nav/settings drawer, `top`/`bottom` for a sheet), using the same mechanism either way. One `createDrawer()` call per drawer instance, so a left nav drawer and a bottom sheet stay fully independent.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -16,21 +16,21 @@ npm install react-native-gesture-handler react-native-reanimated react-native-pa
|
|
|
16
16
|
|
|
17
17
|
Your app's root must already be wrapped in `GestureHandlerRootView` (from `react-native-gesture-handler`). This package doesn't add its own, since only one should ever wrap the whole app.
|
|
18
18
|
|
|
19
|
-
Optionally install `@rific/auto-paper` as well to opt into blurred panels
|
|
19
|
+
Optionally install `@rific/auto-paper` as well and configure it via `DrawerProvider` to opt into blurred panels; see [Blur](#blur) below.
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
24
|
import { createDrawer } from '@rific/drawer'
|
|
25
25
|
|
|
26
|
-
const {
|
|
27
|
-
const {
|
|
28
|
-
const {
|
|
26
|
+
const { DrawerInstanceProvider: NavDrawerProvider, useDrawer: useNavDrawer } = createDrawer({ side: 'left', width: 300 })
|
|
27
|
+
const { DrawerInstanceProvider: SettingsDrawerProvider, useDrawer: useSettingsDrawer } = createDrawer({ side: 'right', width: 320 })
|
|
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
|
|
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.
|
|
32
32
|
|
|
33
|
-
Mount each `
|
|
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
|
|
|
35
35
|
```tsx
|
|
36
36
|
import { combineDrawerProviders } from '@rific/drawer'
|
|
@@ -48,7 +48,7 @@ export default function RootLayout() {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
Each drawer's state stays fully independent under the hood. This is purely a way to avoid writing out the nesting by hand. With a single drawer, just render its `
|
|
51
|
+
Each drawer's state stays fully independent under the hood. This is purely a way to avoid writing out the nesting by hand. With a single drawer, just render its `DrawerInstanceProvider` directly with a `content` prop; `combineDrawerProviders` only earns its keep once you have more than one.
|
|
52
52
|
|
|
53
53
|
Then anywhere else in the tree:
|
|
54
54
|
|
|
@@ -60,63 +60,130 @@ const { isOpen, isVisible, open, close } = useNavDrawer()
|
|
|
60
60
|
<IconButton icon='menu' onPress={open} />
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
`isOpen` flips the instant `open()`/`close()` is called (or a swipe gesture commits). `isVisible` stays `true` for the full close animation too, only dropping to `false` once the panel has actually finished sliding away
|
|
63
|
+
`isOpen` flips the instant `open()`/`close()` is called (or a swipe gesture commits). `isVisible` stays `true` for the full close animation too, only dropping to `false` once the panel has actually finished sliding away, useful for anything that needs to stay mounted/visible for as long as the panel is on screen (e.g. a FAB row portaled above it), rather than disappearing the moment closing starts.
|
|
64
64
|
|
|
65
|
-
The drawer opens by calling `open()`, by tapping the backdrop or an in-content close button (call `close()`), by swiping in from the screen edge, or
|
|
65
|
+
The drawer opens by calling `open()`, by tapping the backdrop or an in-content close button (call `close()`), by swiping in from the screen edge, or, by default, by swiping the panel's own drag handle back toward its closed edge. No extra wiring is needed for either gesture; both are built into `DrawerInstanceProvider`. Pass `enabled={false}` to `DrawerInstanceProvider` to temporarily suppress the edge-swipe gesture (e.g. on a screen where it would conflict with another gesture).
|
|
66
66
|
|
|
67
|
-
A few more options, settable at `createDrawer()` (a fixed default) and overridable per-mount on `
|
|
67
|
+
A few more options, settable at `createDrawer()` (a fixed default) and overridable per-mount on `DrawerInstanceProvider`, same pattern as `blur` below:
|
|
68
68
|
|
|
69
|
-
- **`dismissible`** (default `true`)
|
|
70
|
-
- **`showHandle`** (default `true`)
|
|
71
|
-
- **`blockingBackdrop`** (default `true`)
|
|
72
|
-
- **`backdropOpacity`** (default `0.45`)
|
|
73
|
-
- **`contentSize`** (default `false`)
|
|
74
|
-
- **`closeOnBackPress`** (default `true`)
|
|
75
|
-
- **`zIndex`** (default `50`)
|
|
69
|
+
- **`dismissible`** (default `true`): renders a small drag handle pinned to the panel's edge closest to closed, that can be swiped to dismiss the panel. It floats just outside the panel's own bounds, over the backdrop, so it never claims space from `content`; it's also a dedicated hit area, not the whole panel, so it won't conflict with interactive content (sliders, buttons) inside `content`. The visible strip is 28px thick, but the actual grabbable area extends another 20px into the panel's own edge (48px total, a comfortable finger target) without growing anything visually or reaching into the backdrop. Pass `dismissible={false}` to remove it entirely (no visual, no gesture): `close()`, an in-content close button, or the backdrop remain as the other dismiss paths.
|
|
70
|
+
- **`showHandle`** (default `true`): whether the drag handle's pill graphic renders. Only affects that visual; the strip's hit area and its drag-to-dismiss gesture (controlled by `dismissible` above) render exactly the same when this is `false`: the strip is still there and still grabbable, just without the pill drawn inside it.
|
|
71
|
+
- **`blockingBackdrop`** (default `true`): whether the backdrop intercepts touches while the panel is open. The dimming/blur visual is unaffected either way; setting it to `false` only stops the backdrop from swallowing touches, so sibling content behind/around the panel stays reachable while it's open (tap-to-dismiss via the backdrop stops working in that mode: `dismissible`'s handle or your own close button take over).
|
|
72
|
+
- **`backdropOpacity`** (default `0.45`): peak backdrop opacity once the panel is fully open, scaled down as it slides toward closed. `0` renders no dimming at all, leaving whatever's behind the panel fully visible. Independent of `blockingBackdrop`: a panel can stay undimmed and still block touches, or vice versa.
|
|
73
|
+
- **`contentSize`** (default `false`): see [Content-driven sizing](#content-driven-sizing) below.
|
|
74
|
+
- **`closeOnBackPress`** (default `true`): whether the Android hardware back button closes the drawer while it's open, instead of falling through to whatever's behind it (a screen, a navigator). No-op on iOS/web, where that back-press event never fires.
|
|
75
|
+
- **`zIndex`** (default `50`): see [Stacking multiple drawers](#stacking-multiple-drawers) below.
|
|
76
76
|
|
|
77
77
|
## Stacking multiple drawers
|
|
78
78
|
|
|
79
|
-
If your app can have more than one drawer open at the same time (say, a nav drawer and a confirmation sheet both created via separate `createDrawer()` calls), which one renders on top is otherwise decided by plain View z-index ties, which break on render order
|
|
79
|
+
If your app can have more than one drawer open at the same time (say, a nav drawer and a confirmation sheet both created via separate `createDrawer()` calls), which one renders on top is otherwise decided by plain View z-index ties, which break on render order: whatever order your `DrawerInstanceProvider`s happen to be nested/declared in, not necessarily the order that makes sense for that screen. Give the one that should stack on top a higher `zIndex`:
|
|
80
80
|
|
|
81
81
|
```tsx
|
|
82
|
-
const {
|
|
83
|
-
const {
|
|
82
|
+
const { DrawerInstanceProvider: NavDrawerProvider } = createDrawer({ side: 'left', width: 300 }) // zIndex 50 (default)
|
|
83
|
+
const { DrawerInstanceProvider: ConfirmSheetProvider } = createDrawer({ side: 'bottom', height: 200, zIndex: 100 })
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
`zIndex` sets the backdrop's stacking tier directly; the panel and its drag handle use `zIndex + 1` / `zIndex + 2`, so raising one drawer's `zIndex` moves its whole backdrop+panel+handle stack together, above any other drawer using a lower value.
|
|
87
87
|
|
|
88
88
|
## Content-driven sizing
|
|
89
89
|
|
|
90
|
-
By default the panel is a fixed `height`/`width`. Pass `contentSize` to size it to its content's natural size along the main axis instead, and it'll smoothly animate as that natural size changes (e.g. swapping to differently-sized content while open). `height`/`width` still matter as the pre-measurement placeholder
|
|
90
|
+
By default the panel is a fixed `height`/`width`. Pass `contentSize` to size it to its content's natural size along the main axis instead, and it'll smoothly animate as that natural size changes (e.g. swapping to differently-sized content while open). `height`/`width` still matter as the pre-measurement placeholder: the size used for the very first render, before the content's natural size has been measured.
|
|
91
91
|
|
|
92
|
-
This isn't sheet-specific
|
|
92
|
+
This isn't sheet-specific: the main axis is whichever one `side` uses, so it works the same way for a `left`/`right` drawer sizing itself to its content's natural *width* as it does for a `top`/`bottom` sheet sizing to height.
|
|
93
|
+
|
|
94
|
+
## Expandable sheets
|
|
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:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
const { DrawerInstanceProvider: SheetProvider } = createDrawer({ side: 'bottom', height: '50%', maxHeight: '100%' })
|
|
100
|
+
```
|
|
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.
|
|
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.
|
|
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`:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
const { expandProgress } = sheet.useDrawer()
|
|
110
|
+
const insets = useSafeAreaInsets()
|
|
111
|
+
const style = useAnimatedStyle(() => ({ paddingTop: expandProgress.value * insets.top }))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Always a flat `1` while open when there's no `maxHeight`/`maxWidth` (rest already is the full extent, same as the handle-drag behavior above).
|
|
93
115
|
|
|
94
116
|
## Safe area
|
|
95
117
|
|
|
96
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.
|
|
97
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.
|
|
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`.
|
|
123
|
+
|
|
124
|
+
### Stopping the panel itself short of the inset
|
|
125
|
+
|
|
126
|
+
`edgeInset` (settable at `createDrawer()`, or directly on `Drawer`/`DrawerEdgeSwipe`) shrinks the basis a *percentage* `height`/`width`/`maxHeight`/`maxWidth` resolves against, so `'100%'` fills exactly up to `edgeInset` px short of the screen edge instead of reaching it:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
const insets = useSafeAreaInsets()
|
|
130
|
+
const { DrawerInstanceProvider: SheetProvider } = createDrawer({ side: 'bottom', height: '50%', maxHeight: '100%', edgeInset: insets.top })
|
|
131
|
+
```
|
|
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).
|
|
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.
|
|
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.
|
|
138
|
+
|
|
98
139
|
## Blur
|
|
99
140
|
|
|
100
|
-
The panel can render with a blurred background instead of a solid one, via the sibling package [`@rific/auto-paper`](https://www.npmjs.com/package/@rific/auto-paper) (which ships a themed `BlurView` and a `useBlur()` hook backed by a global user preference). It's an optional peer
|
|
141
|
+
The panel can render with a blurred background instead of a solid one, via the sibling package [`@rific/auto-paper`](https://www.npmjs.com/package/@rific/auto-paper) (which ships a themed `BlurView` and a `useBlur()` hook backed by a global user preference). It's an optional peer, and never auto-detected. Install it and configure it once, near your app root, above every `createDrawer()` `DrawerInstanceProvider`:
|
|
101
142
|
|
|
102
143
|
```sh
|
|
103
144
|
npm install @rific/auto-paper
|
|
104
145
|
```
|
|
105
146
|
|
|
106
|
-
|
|
147
|
+
```tsx
|
|
148
|
+
import { DrawerProvider } from '@rific/drawer'
|
|
149
|
+
import * as AutoPaper from '@rific/auto-paper'
|
|
150
|
+
|
|
151
|
+
export default function RootLayout() {
|
|
152
|
+
return (
|
|
153
|
+
<DrawerProvider autoPaper={AutoPaper}>
|
|
154
|
+
<AllDrawersProvider>{/* your app */}</AllDrawersProvider>
|
|
155
|
+
</DrawerProvider>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`DrawerProvider` is a thin wrapper: it just calls `configureDrawer({ autoPaper })` for you. Not to be confused with the per-drawer `DrawerInstanceProvider` that `createDrawer()` returns: this one is app-wide, mounted once, for optional peer config; that one is per-drawer, mounted once per `createDrawer()` call, for that drawer's own open/closed state. If you'd rather not wrap anything, call `configureDrawer()` directly instead, anywhere before your first `<Drawer>` renders (e.g. the top of `App.tsx`):
|
|
107
161
|
|
|
108
162
|
```tsx
|
|
109
|
-
|
|
163
|
+
import { configureDrawer } from '@rific/drawer'
|
|
164
|
+
import * as AutoPaper from '@rific/auto-paper'
|
|
165
|
+
|
|
166
|
+
configureDrawer({ autoPaper: AutoPaper })
|
|
110
167
|
```
|
|
111
168
|
|
|
112
|
-
|
|
169
|
+
Either way this is one-time setup, not reactive state: call it once, before anything renders. Every `Drawer`, from any `createDrawer()` instance, picks it up automatically; there's nothing to pass per-drawer.
|
|
170
|
+
|
|
171
|
+
Pass `blur` wherever suits your app: to `createDrawer()` (a fixed default for that drawer), to `DrawerInstanceProvider` (overriding the `createDrawer()` default for that mount), or directly to `Drawer` if you're using it standalone. If you don't pass `blur` at all, the panel falls back to `@rific/auto-paper`'s own global `settings.blur` user preference via `useBlur()`.
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
const { DrawerInstanceProvider: SettingsDrawerProvider } = createDrawer({ side: 'right', width: 320, blur: true })
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Only the panel surface blurs; the backdrop behind it stays solid, same as today. Without `autoPaper` configured, the panel always renders its solid `colors.surface` fallback, exactly as before.
|
|
113
178
|
|
|
114
179
|
## Lower-level pieces
|
|
115
180
|
|
|
116
|
-
`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
|
|
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
|
+
|
|
183
|
+
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.
|
|
117
184
|
|
|
118
|
-
|
|
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.
|
|
119
186
|
|
|
120
|
-
`Drawer` also takes an `onClosed?: () => void`, fired once the close spring actually settles rather than the instant `open` flips to `false
|
|
187
|
+
`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.
|
|
121
188
|
|
|
122
|
-
`Drawer` also takes the same `zIndex` prop described in [Stacking multiple drawers](#stacking-multiple-drawers)
|
|
189
|
+
`Drawer` also takes the same `zIndex` prop described in [Stacking multiple drawers](#stacking-multiple-drawers), useful if you're rendering more than one standalone `Drawer` (or mixing standalone `Drawer`s with `createDrawer()` ones) that might be open at the same time.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, JSX } from 'react';
|
|
2
|
+
import { ReactNode, JSX, ComponentType } from 'react';
|
|
3
3
|
import { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
|
|
4
5
|
|
|
5
6
|
type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
|
|
7
|
+
type DrawerDimension = number | `${number}%`;
|
|
6
8
|
|
|
7
9
|
type DrawerActions = {
|
|
8
10
|
close: () => void;
|
|
11
|
+
expandProgress: SharedValue<number>;
|
|
9
12
|
isOpen: boolean;
|
|
10
13
|
isVisible: boolean;
|
|
11
14
|
open: () => void;
|
|
@@ -17,13 +20,16 @@ type CreateDrawerOptions = {
|
|
|
17
20
|
closeOnBackPress?: boolean;
|
|
18
21
|
contentSize?: boolean;
|
|
19
22
|
dismissible?: boolean;
|
|
20
|
-
|
|
23
|
+
edgeInset?: number;
|
|
24
|
+
height?: DrawerDimension;
|
|
25
|
+
maxHeight?: DrawerDimension;
|
|
26
|
+
maxWidth?: DrawerDimension;
|
|
21
27
|
showHandle?: boolean;
|
|
22
28
|
side?: DrawerSide;
|
|
23
|
-
width?:
|
|
29
|
+
width?: DrawerDimension;
|
|
24
30
|
zIndex?: number;
|
|
25
31
|
};
|
|
26
|
-
type
|
|
32
|
+
type DrawerInstanceProviderProps = {
|
|
27
33
|
backdropOpacity?: number;
|
|
28
34
|
blockingBackdrop?: boolean;
|
|
29
35
|
blur?: boolean;
|
|
@@ -37,12 +43,12 @@ type DrawerProviderProps = {
|
|
|
37
43
|
zIndex?: number;
|
|
38
44
|
};
|
|
39
45
|
type CreateDrawerResult = {
|
|
40
|
-
|
|
46
|
+
DrawerInstanceProvider: (props: DrawerInstanceProviderProps) => JSX.Element;
|
|
41
47
|
useDrawer: () => DrawerActions;
|
|
42
48
|
};
|
|
43
|
-
declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, height, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
|
|
44
|
-
type
|
|
45
|
-
declare const combineDrawerProviders: (...entries: [
|
|
49
|
+
declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
|
|
50
|
+
type DrawerInstanceProviderComponent = (props: DrawerInstanceProviderProps) => JSX.Element;
|
|
51
|
+
declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderComponent, Omit<DrawerInstanceProviderProps, "children">?][]) => ({ children }: {
|
|
46
52
|
children?: ReactNode;
|
|
47
53
|
}) => JSX.Element;
|
|
48
54
|
|
|
@@ -53,7 +59,10 @@ type DrawerProps = {
|
|
|
53
59
|
children?: ReactNode;
|
|
54
60
|
contentSize?: boolean;
|
|
55
61
|
dismissible?: boolean;
|
|
56
|
-
|
|
62
|
+
edgeInset?: number;
|
|
63
|
+
height?: DrawerDimension;
|
|
64
|
+
maxHeight?: DrawerDimension;
|
|
65
|
+
maxWidth?: DrawerDimension;
|
|
57
66
|
onClose: () => void;
|
|
58
67
|
onClosed?: () => void;
|
|
59
68
|
onMeasure?: (size: number) => void;
|
|
@@ -62,19 +71,41 @@ type DrawerProps = {
|
|
|
62
71
|
side?: DrawerSide;
|
|
63
72
|
showHandle?: boolean;
|
|
64
73
|
translateOffset?: SharedValue<number>;
|
|
65
|
-
width?:
|
|
74
|
+
width?: DrawerDimension;
|
|
66
75
|
zIndex?: number;
|
|
67
76
|
};
|
|
68
|
-
declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, height, onClose, onClosed, onMeasure, onOpened, open, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
|
|
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;
|
|
78
|
+
|
|
79
|
+
type AutoPaperModule = {
|
|
80
|
+
BlurView: ComponentType<{
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
onLayout?: (event: LayoutChangeEvent) => void;
|
|
83
|
+
style?: StyleProp<ViewStyle>;
|
|
84
|
+
}>;
|
|
85
|
+
useBlur: (override?: boolean) => boolean;
|
|
86
|
+
};
|
|
87
|
+
type DrawerConfig = {
|
|
88
|
+
/** Injects @rific/auto-paper so Drawer's panel renders a real frosted-glass backdrop via BlurView/useBlur instead of its solid-fill fallback. Pass `import * as AutoPaper from '@rific/auto-paper'`; omit to keep the solid fallback. */
|
|
89
|
+
autoPaper?: AutoPaperModule;
|
|
90
|
+
};
|
|
91
|
+
declare const configureDrawer: (next: DrawerConfig) => void;
|
|
92
|
+
declare const getDrawerConfig: () => DrawerConfig;
|
|
93
|
+
type DrawerProviderProps = DrawerConfig & {
|
|
94
|
+
children: ReactNode;
|
|
95
|
+
};
|
|
96
|
+
declare const DrawerProvider: ({ autoPaper, children }: DrawerProviderProps) => react.JSX.Element;
|
|
69
97
|
|
|
70
98
|
type DrawerEdgeSwipeProps = {
|
|
99
|
+
edgeInset?: number;
|
|
71
100
|
enabled?: boolean;
|
|
72
|
-
height?:
|
|
101
|
+
height?: DrawerDimension;
|
|
102
|
+
maxHeight?: DrawerDimension;
|
|
103
|
+
maxWidth?: DrawerDimension;
|
|
73
104
|
onOpen: () => void;
|
|
74
105
|
side?: DrawerSide;
|
|
75
106
|
translateOffset: SharedValue<number>;
|
|
76
|
-
width?:
|
|
107
|
+
width?: DrawerDimension;
|
|
77
108
|
};
|
|
78
|
-
declare const DrawerEdgeSwipe: ({ enabled, height, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
|
|
109
|
+
declare const DrawerEdgeSwipe: ({ edgeInset, enabled, height, maxHeight, maxWidth, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
|
|
79
110
|
|
|
80
|
-
export { type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type
|
|
111
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ReactNode, JSX } from 'react';
|
|
2
|
+
import { ReactNode, JSX, ComponentType } from 'react';
|
|
3
3
|
import { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { LayoutChangeEvent, StyleProp, ViewStyle } from 'react-native';
|
|
4
5
|
|
|
5
6
|
type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
|
|
7
|
+
type DrawerDimension = number | `${number}%`;
|
|
6
8
|
|
|
7
9
|
type DrawerActions = {
|
|
8
10
|
close: () => void;
|
|
11
|
+
expandProgress: SharedValue<number>;
|
|
9
12
|
isOpen: boolean;
|
|
10
13
|
isVisible: boolean;
|
|
11
14
|
open: () => void;
|
|
@@ -17,13 +20,16 @@ type CreateDrawerOptions = {
|
|
|
17
20
|
closeOnBackPress?: boolean;
|
|
18
21
|
contentSize?: boolean;
|
|
19
22
|
dismissible?: boolean;
|
|
20
|
-
|
|
23
|
+
edgeInset?: number;
|
|
24
|
+
height?: DrawerDimension;
|
|
25
|
+
maxHeight?: DrawerDimension;
|
|
26
|
+
maxWidth?: DrawerDimension;
|
|
21
27
|
showHandle?: boolean;
|
|
22
28
|
side?: DrawerSide;
|
|
23
|
-
width?:
|
|
29
|
+
width?: DrawerDimension;
|
|
24
30
|
zIndex?: number;
|
|
25
31
|
};
|
|
26
|
-
type
|
|
32
|
+
type DrawerInstanceProviderProps = {
|
|
27
33
|
backdropOpacity?: number;
|
|
28
34
|
blockingBackdrop?: boolean;
|
|
29
35
|
blur?: boolean;
|
|
@@ -37,12 +43,12 @@ type DrawerProviderProps = {
|
|
|
37
43
|
zIndex?: number;
|
|
38
44
|
};
|
|
39
45
|
type CreateDrawerResult = {
|
|
40
|
-
|
|
46
|
+
DrawerInstanceProvider: (props: DrawerInstanceProviderProps) => JSX.Element;
|
|
41
47
|
useDrawer: () => DrawerActions;
|
|
42
48
|
};
|
|
43
|
-
declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, height, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
|
|
44
|
-
type
|
|
45
|
-
declare const combineDrawerProviders: (...entries: [
|
|
49
|
+
declare const createDrawer: ({ backdropOpacity: factoryBackdropOpacity, blockingBackdrop: factoryBlockingBackdrop, blur: factoryBlur, closeOnBackPress: factoryCloseOnBackPress, contentSize: factoryContentSize, dismissible: factoryDismissible, edgeInset, height, maxHeight, maxWidth, showHandle: factoryShowHandle, side, width, zIndex: factoryZIndex }?: CreateDrawerOptions) => CreateDrawerResult;
|
|
50
|
+
type DrawerInstanceProviderComponent = (props: DrawerInstanceProviderProps) => JSX.Element;
|
|
51
|
+
declare const combineDrawerProviders: (...entries: [DrawerInstanceProviderComponent, Omit<DrawerInstanceProviderProps, "children">?][]) => ({ children }: {
|
|
46
52
|
children?: ReactNode;
|
|
47
53
|
}) => JSX.Element;
|
|
48
54
|
|
|
@@ -53,7 +59,10 @@ type DrawerProps = {
|
|
|
53
59
|
children?: ReactNode;
|
|
54
60
|
contentSize?: boolean;
|
|
55
61
|
dismissible?: boolean;
|
|
56
|
-
|
|
62
|
+
edgeInset?: number;
|
|
63
|
+
height?: DrawerDimension;
|
|
64
|
+
maxHeight?: DrawerDimension;
|
|
65
|
+
maxWidth?: DrawerDimension;
|
|
57
66
|
onClose: () => void;
|
|
58
67
|
onClosed?: () => void;
|
|
59
68
|
onMeasure?: (size: number) => void;
|
|
@@ -62,19 +71,41 @@ type DrawerProps = {
|
|
|
62
71
|
side?: DrawerSide;
|
|
63
72
|
showHandle?: boolean;
|
|
64
73
|
translateOffset?: SharedValue<number>;
|
|
65
|
-
width?:
|
|
74
|
+
width?: DrawerDimension;
|
|
66
75
|
zIndex?: number;
|
|
67
76
|
};
|
|
68
|
-
declare const Drawer: ({ backdropOpacity, blockingBackdrop, blur, children, contentSize, dismissible, height, onClose, onClosed, onMeasure, onOpened, open, side, showHandle, translateOffset: externalTranslateOffset, width, zIndex }: DrawerProps) => react.JSX.Element;
|
|
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;
|
|
78
|
+
|
|
79
|
+
type AutoPaperModule = {
|
|
80
|
+
BlurView: ComponentType<{
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
onLayout?: (event: LayoutChangeEvent) => void;
|
|
83
|
+
style?: StyleProp<ViewStyle>;
|
|
84
|
+
}>;
|
|
85
|
+
useBlur: (override?: boolean) => boolean;
|
|
86
|
+
};
|
|
87
|
+
type DrawerConfig = {
|
|
88
|
+
/** Injects @rific/auto-paper so Drawer's panel renders a real frosted-glass backdrop via BlurView/useBlur instead of its solid-fill fallback. Pass `import * as AutoPaper from '@rific/auto-paper'`; omit to keep the solid fallback. */
|
|
89
|
+
autoPaper?: AutoPaperModule;
|
|
90
|
+
};
|
|
91
|
+
declare const configureDrawer: (next: DrawerConfig) => void;
|
|
92
|
+
declare const getDrawerConfig: () => DrawerConfig;
|
|
93
|
+
type DrawerProviderProps = DrawerConfig & {
|
|
94
|
+
children: ReactNode;
|
|
95
|
+
};
|
|
96
|
+
declare const DrawerProvider: ({ autoPaper, children }: DrawerProviderProps) => react.JSX.Element;
|
|
69
97
|
|
|
70
98
|
type DrawerEdgeSwipeProps = {
|
|
99
|
+
edgeInset?: number;
|
|
71
100
|
enabled?: boolean;
|
|
72
|
-
height?:
|
|
101
|
+
height?: DrawerDimension;
|
|
102
|
+
maxHeight?: DrawerDimension;
|
|
103
|
+
maxWidth?: DrawerDimension;
|
|
73
104
|
onOpen: () => void;
|
|
74
105
|
side?: DrawerSide;
|
|
75
106
|
translateOffset: SharedValue<number>;
|
|
76
|
-
width?:
|
|
107
|
+
width?: DrawerDimension;
|
|
77
108
|
};
|
|
78
|
-
declare const DrawerEdgeSwipe: ({ enabled, height, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
|
|
109
|
+
declare const DrawerEdgeSwipe: ({ edgeInset, enabled, height, maxHeight, maxWidth, onOpen, side, translateOffset, width }: DrawerEdgeSwipeProps) => react.JSX.Element;
|
|
79
110
|
|
|
80
|
-
export { type CreateDrawerOptions, type CreateDrawerResult, Drawer, type DrawerActions, DrawerEdgeSwipe, type DrawerEdgeSwipeProps, type
|
|
111
|
+
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 };
|