@swmansion/react-native-bottom-sheet 0.13.0 → 0.14.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -8
- package/lib/module/BottomSheet.js +15 -6
- package/lib/module/BottomSheet.js.map +1 -1
- package/lib/module/ModalBottomSheet.js +5 -1
- package/lib/module/ModalBottomSheet.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/BottomSheet.d.ts +27 -5
- package/lib/typescript/src/BottomSheet.d.ts.map +1 -1
- package/lib/typescript/src/ModalBottomSheet.d.ts +5 -2
- package/lib/typescript/src/ModalBottomSheet.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BottomSheet.tsx +33 -13
- package/src/ModalBottomSheet.tsx +12 -3
- package/src/index.tsx +5 -1
package/README.md
CHANGED
|
@@ -301,24 +301,27 @@ drag snapping but can still be targeted via `index` updates.
|
|
|
301
301
|
|
|
302
302
|
### Position tracking
|
|
303
303
|
|
|
304
|
-
Use `onPositionChange` to observe the sheet’s current position
|
|
305
|
-
pixels from the bottom of the screen to the
|
|
304
|
+
Use `onPositionChange` to observe the sheet’s current position. It is a standard
|
|
305
|
+
native event; read the distance in pixels from the bottom of the screen to the
|
|
306
|
+
top of the sheet from `event.nativeEvent.position`.
|
|
306
307
|
|
|
307
308
|
```tsx
|
|
308
309
|
<BottomSheet // Or `ModalBottomSheet`.
|
|
309
310
|
index={index}
|
|
310
311
|
onIndexChange={setIndex}
|
|
311
312
|
surface={/* ... */}
|
|
312
|
-
onPositionChange={(
|
|
313
|
-
console.log(position);
|
|
313
|
+
onPositionChange={(event) => {
|
|
314
|
+
console.log(event.nativeEvent.position);
|
|
314
315
|
}}
|
|
315
316
|
>
|
|
316
317
|
{/* ... */}
|
|
317
318
|
</BottomSheet>
|
|
318
319
|
```
|
|
319
320
|
|
|
320
|
-
|
|
321
|
-
|
|
321
|
+
#### With Reanimated
|
|
322
|
+
|
|
323
|
+
To keep the latest position in a Reanimated shared value, update it from
|
|
324
|
+
the callback:
|
|
322
325
|
|
|
323
326
|
```tsx
|
|
324
327
|
const position = useSharedValue(0);
|
|
@@ -329,14 +332,58 @@ const position = useSharedValue(0);
|
|
|
329
332
|
index={index}
|
|
330
333
|
onIndexChange={setIndex}
|
|
331
334
|
surface={/* ... */}
|
|
332
|
-
onPositionChange={(
|
|
333
|
-
position.value =
|
|
335
|
+
onPositionChange={(event) => {
|
|
336
|
+
position.value = event.nativeEvent.position;
|
|
334
337
|
}}
|
|
335
338
|
>
|
|
336
339
|
{/* ... */}
|
|
337
340
|
</BottomSheet>
|
|
338
341
|
```
|
|
339
342
|
|
|
343
|
+
Because `onPositionChange` is a native event, you can also handle it on the UI
|
|
344
|
+
thread by wrapping the component with Reanimated’s `createAnimatedComponent` and
|
|
345
|
+
passing a worklet handler from `useEvent`:
|
|
346
|
+
|
|
347
|
+
```tsx
|
|
348
|
+
import type { NativeSyntheticEvent } from 'react-native';
|
|
349
|
+
import Animated, { useEvent, useSharedValue } from 'react-native-reanimated';
|
|
350
|
+
import {
|
|
351
|
+
BottomSheet,
|
|
352
|
+
type PositionChangeEventData,
|
|
353
|
+
} from '@swmansion/react-native-bottom-sheet';
|
|
354
|
+
|
|
355
|
+
const AnimatedBottomSheet = Animated.createAnimatedComponent(BottomSheet);
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
```tsx
|
|
359
|
+
const position = useSharedValue(0);
|
|
360
|
+
|
|
361
|
+
const onPositionChange = useEvent<
|
|
362
|
+
NativeSyntheticEvent<PositionChangeEventData>
|
|
363
|
+
>(
|
|
364
|
+
(event) => {
|
|
365
|
+
'worklet';
|
|
366
|
+
position.value = event.position;
|
|
367
|
+
},
|
|
368
|
+
['onPositionChange']
|
|
369
|
+
);
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
```tsx
|
|
373
|
+
<AnimatedBottomSheet
|
|
374
|
+
index={index}
|
|
375
|
+
onIndexChange={setIndex}
|
|
376
|
+
surface={/* ... */}
|
|
377
|
+
onPositionChange={onPositionChange}
|
|
378
|
+
>
|
|
379
|
+
{/* ... */}
|
|
380
|
+
</AnimatedBottomSheet>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Inside the worklet, Reanimated unwraps the native event, so you read
|
|
384
|
+
`event.position` directly rather than `event.nativeEvent.position`. The handler
|
|
385
|
+
runs on the UI thread on every frame the sheet moves.
|
|
386
|
+
|
|
340
387
|
## By [Software Mansion](https://swmansion.com)
|
|
341
388
|
|
|
342
389
|
Founded in 2012, [Software Mansion](https://swmansion.com) is a software agency
|
|
@@ -8,6 +8,17 @@ import { Portal } from "./BottomSheetProvider.js";
|
|
|
8
8
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
9
|
export { programmatic } from "./bottomSheetUtils.js";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Imperative handle for a `BottomSheet`. It resolves to the underlying native
|
|
13
|
+
* sheet view—the one that emits `onPositionChange`—so it plugs straight into
|
|
14
|
+
* Reanimated’s `createAnimatedComponent`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
19
|
+
* `event.nativeEvent`.
|
|
20
|
+
*/
|
|
21
|
+
|
|
11
22
|
/**
|
|
12
23
|
* Props for the inline bottom-sheet component.
|
|
13
24
|
*/
|
|
@@ -26,7 +37,8 @@ export const BottomSheet = ({
|
|
|
26
37
|
modal = false,
|
|
27
38
|
disableScrollableNegotiation = false,
|
|
28
39
|
scrimColor,
|
|
29
|
-
scrimOpacities
|
|
40
|
+
scrimOpacities,
|
|
41
|
+
ref
|
|
30
42
|
}) => {
|
|
31
43
|
const {
|
|
32
44
|
height: windowHeight
|
|
@@ -62,10 +74,6 @@ export const BottomSheet = ({
|
|
|
62
74
|
const handleSettle = event => {
|
|
63
75
|
onSettle?.(event.nativeEvent.index);
|
|
64
76
|
};
|
|
65
|
-
const handlePositionChange = event => {
|
|
66
|
-
const height = event.nativeEvent.position;
|
|
67
|
-
onPositionChange?.(height);
|
|
68
|
-
};
|
|
69
77
|
const sheet = /*#__PURE__*/_jsx(View, {
|
|
70
78
|
style: StyleSheet.absoluteFill,
|
|
71
79
|
pointerEvents: modal ? isCollapsed ? 'none' : 'auto' : 'box-none',
|
|
@@ -73,6 +81,7 @@ export const BottomSheet = ({
|
|
|
73
81
|
pointerEvents: "box-none",
|
|
74
82
|
style: StyleSheet.absoluteFill,
|
|
75
83
|
children: /*#__PURE__*/_jsxs(BottomSheetNativeComponent, {
|
|
84
|
+
ref: ref,
|
|
76
85
|
pointerEvents: "box-none",
|
|
77
86
|
style: [{
|
|
78
87
|
position: 'absolute',
|
|
@@ -94,7 +103,7 @@ export const BottomSheet = ({
|
|
|
94
103
|
scrimOpacities: resolvedScrimOpacity,
|
|
95
104
|
onIndexChange: handleIndexChange,
|
|
96
105
|
onSettle: handleSettle,
|
|
97
|
-
onPositionChange:
|
|
106
|
+
onPositionChange: onPositionChange,
|
|
98
107
|
children: [surface != null && /*#__PURE__*/_jsx(BottomSheetSurfaceNativeComponent, {
|
|
99
108
|
collapsable: false,
|
|
100
109
|
pointerEvents: "box-none",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StyleSheet","View","useWindowDimensions","useSafeAreaInsets","BottomSheetNativeComponent","BottomSheetSurfaceNativeComponent","Portal","jsx","_jsx","jsxs","_jsxs","programmatic","BottomSheet","children","surface","style","detents","index","animateIn","onIndexChange","onSettle","onPositionChange","modal","disableScrollableNegotiation","scrimColor","scrimOpacities","height","windowHeight","insets","maxHeight","top","nativeDetents","map","detent","isDetentProgrammatic","value","resolveDetentValue","kind","Math","max","min","clampedIndex","length","selectedDetentValue","isCollapsed","resolvedScrimOpacity","handleIndexChange","event","nativeEvent","handleSettle","
|
|
1
|
+
{"version":3,"names":["StyleSheet","View","useWindowDimensions","useSafeAreaInsets","BottomSheetNativeComponent","BottomSheetSurfaceNativeComponent","Portal","jsx","_jsx","jsxs","_jsxs","programmatic","BottomSheet","children","surface","style","detents","index","animateIn","onIndexChange","onSettle","onPositionChange","modal","disableScrollableNegotiation","scrimColor","scrimOpacities","ref","height","windowHeight","insets","maxHeight","top","nativeDetents","map","detent","isDetentProgrammatic","value","resolveDetentValue","kind","Math","max","min","clampedIndex","length","selectedDetentValue","isCollapsed","resolvedScrimOpacity","handleIndexChange","event","nativeEvent","handleSettle","sheet","absoluteFill","pointerEvents","position","left","right","bottom","maxDetentHeight","collapsable","flex"],"sourceRoot":"../../src","sources":["BottomSheet.tsx"],"mappings":";;AAEA,SAASA,UAAU,EAAEC,IAAI,EAAEC,mBAAmB,QAAQ,cAAc;AACpE,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,iCAAiC,MAAM,qCAAqC;AACnF,SAASC,MAAM,QAAQ,0BAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAG/C,SAASC,YAAY,QAAQ,uBAAoB;;AAEjD;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;;AAMA;AACA;AACA;;AAoEA;AACA,OAAO,MAAMC,WAAW,GAAGA,CAAC;EAC1BC,QAAQ;EACRC,OAAO;EACPC,KAAK;EACLC,OAAO,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC;EACxBC,KAAK;EACLC,SAAS,GAAG,IAAI;EAChBC,aAAa;EACbC,QAAQ;EACRC,gBAAgB;EAChBC,KAAK,GAAG,KAAK;EACbC,4BAA4B,GAAG,KAAK;EACpCC,UAAU;EACVC,cAAc;EACdC;AACqD,CAAC,KAAK;EAC3D,MAAM;IAAEC,MAAM,EAAEC;EAAa,CAAC,GAAG1B,mBAAmB,CAAC,CAAC;EACtD,MAAM2B,MAAM,GAAG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E;UAAAjB,QAAA,GACrDA,QAAQ,eACTL,IAAA,CAACP,IAAI;YAAC0D,WAAW,EAAE,KAAM;YAACN,aAAa,EAAC;UAAM,CAAE,CAAC;QAAA,CAC7C,CAAC;MAAA,CACmB;IAAC,CACzB;EAAC,CACH,CACP;EAED,IAAI/B,KAAK,EAAE;IACT,oBAAOd,IAAA,CAACF,MAAM;MAAAO,QAAA,EAAEsC;IAAK,CAAS,CAAC;EACjC;EAEA,OAAOA,KAAK;AACd,CAAC;AAED,SAAShB,oBAAoBA,CAACD,MAAc,EAAW;EACrD,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,KAAK,IAAI,EAAE;IACjD,OAAOA,MAAM,CAACvB,YAAY,KAAK,IAAI;EACrC;EACA,OAAO,KAAK;AACd;AAEA,SAAS0B,kBAAkBA,CAACH,MAAc,EAAE;EAC1C,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,KAAK,IAAI,EAAE;IACjD,OAAOA,MAAM,CAACE,KAAK;EACrB;EACA,OAAOF,MAAM;AACf","ignoreList":[]}
|
|
@@ -5,8 +5,12 @@ import { BottomSheet } from "./BottomSheet.js";
|
|
|
5
5
|
/** Props for the modal bottom-sheet variant rendered through the provider portal. */
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
/** Bottom sheet presented above the current UI with a scrim. */
|
|
8
|
-
export const ModalBottomSheet =
|
|
8
|
+
export const ModalBottomSheet = ({
|
|
9
|
+
ref,
|
|
10
|
+
...props
|
|
11
|
+
}) => /*#__PURE__*/_jsx(BottomSheet, {
|
|
9
12
|
...props,
|
|
13
|
+
ref: ref,
|
|
10
14
|
modal: true
|
|
11
15
|
});
|
|
12
16
|
//# sourceMappingURL=ModalBottomSheet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BottomSheet","jsx","_jsx","ModalBottomSheet","props","modal"],"sourceRoot":"../../src","sources":["ModalBottomSheet.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["BottomSheet","jsx","_jsx","ModalBottomSheet","ref","props","modal"],"sourceRoot":"../../src","sources":["ModalBottomSheet.tsx"],"mappings":";;AAEA,SACEA,WAAW,QAGN,kBAAe;;AAEtB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAMA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,GAAG;EACH,GAAGC;AACuD,CAAC,kBAC3DH,IAAA,CAACF,WAAW;EAAA,GAAKK,KAAK;EAAED,GAAG,EAAEA,GAAI;EAACE,KAAK;AAAA,CAAE,CAC1C","ignoreList":[]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BottomSheet","ModalBottomSheet","BottomSheetProvider","programmatic"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,kBAAe;
|
|
1
|
+
{"version":3,"names":["BottomSheet","ModalBottomSheet","BottomSheetProvider","programmatic"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,kBAAe;AAM3C,SAASC,gBAAgB,QAAQ,uBAAoB;AAErD,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,YAAY,QAAQ,uBAAoB","ignoreList":[]}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import type { StyleProp, ViewStyle } from 'react-native';
|
|
1
|
+
import { type ComponentRef, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import type { NativeSyntheticEvent, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import BottomSheetNativeComponent from './BottomSheetNativeComponent';
|
|
3
4
|
import { type Detent } from './bottomSheetUtils';
|
|
4
5
|
export type { Detent, DetentValue } from './bottomSheetUtils';
|
|
5
6
|
export { programmatic } from './bottomSheetUtils';
|
|
7
|
+
/**
|
|
8
|
+
* Imperative handle for a `BottomSheet`. It resolves to the underlying native
|
|
9
|
+
* sheet view—the one that emits `onPositionChange`—so it plugs straight into
|
|
10
|
+
* Reanimated’s `createAnimatedComponent`.
|
|
11
|
+
*/
|
|
12
|
+
export type BottomSheetInstance = ComponentRef<typeof BottomSheetNativeComponent>;
|
|
13
|
+
/**
|
|
14
|
+
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
15
|
+
* `event.nativeEvent`.
|
|
16
|
+
*/
|
|
17
|
+
export type PositionChangeEventData = Readonly<{
|
|
18
|
+
/** Sheet position, in points from the bottom. */
|
|
19
|
+
position: number;
|
|
20
|
+
}>;
|
|
6
21
|
/**
|
|
7
22
|
* Props for the inline bottom-sheet component.
|
|
8
23
|
*/
|
|
@@ -38,8 +53,13 @@ export interface BottomSheetProps {
|
|
|
38
53
|
onIndexChange?: (index: number) => void;
|
|
39
54
|
/** Called when a snap animation settles, including programmatic changes. */
|
|
40
55
|
onSettle?: (index: number) => void;
|
|
41
|
-
/**
|
|
42
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Called as the sheet position changes. A standard native direct event; read
|
|
58
|
+
* `event.nativeEvent.position` (points from the bottom). Because it is a real
|
|
59
|
+
* native event, it also works on the UI thread when the component is wrapped
|
|
60
|
+
* with Reanimated’s `createAnimatedComponent` and given a worklet handler.
|
|
61
|
+
*/
|
|
62
|
+
onPositionChange?: (event: NativeSyntheticEvent<PositionChangeEventData>) => void;
|
|
43
63
|
/** Internal flag used by `ModalBottomSheet`. */
|
|
44
64
|
modal?: boolean;
|
|
45
65
|
/**
|
|
@@ -66,5 +86,7 @@ export interface BottomSheetProps {
|
|
|
66
86
|
scrimOpacities?: number[];
|
|
67
87
|
}
|
|
68
88
|
/** Native bottom sheet that renders inline within the current screen layout. */
|
|
69
|
-
export declare const BottomSheet: ({ children, surface, style, detents, index, animateIn, onIndexChange, onSettle, onPositionChange, modal, disableScrollableNegotiation, scrimColor, scrimOpacities, }: BottomSheetProps
|
|
89
|
+
export declare const BottomSheet: ({ children, surface, style, detents, index, animateIn, onIndexChange, onSettle, onPositionChange, modal, disableScrollableNegotiation, scrimColor, scrimOpacities, ref, }: BottomSheetProps & {
|
|
90
|
+
ref?: Ref<BottomSheetInstance>;
|
|
91
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
70
92
|
//# sourceMappingURL=BottomSheet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../src/BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../src/BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AAGtE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAC5C,OAAO,0BAA0B,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,CACjB,KAAK,EAAE,oBAAoB,CAAC,uBAAuB,CAAC,KACjD,IAAI,CAAC;IACV,gDAAgD;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,gFAAgF;AAChF,eAAO,MAAM,WAAW,GAAI,2KAezB,gBAAgB,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAA;CAAE,4CAkGvD,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
import { type BottomSheetInstance, type BottomSheetProps } from './BottomSheet';
|
|
2
3
|
/** Props for the modal bottom-sheet variant rendered through the provider portal. */
|
|
3
4
|
export interface ModalBottomSheetProps extends Omit<BottomSheetProps, 'modal'> {
|
|
4
5
|
}
|
|
5
6
|
/** Bottom sheet presented above the current UI with a scrim. */
|
|
6
|
-
export declare const ModalBottomSheet: (props: ModalBottomSheetProps
|
|
7
|
+
export declare const ModalBottomSheet: ({ ref, ...props }: ModalBottomSheetProps & {
|
|
8
|
+
ref?: Ref<BottomSheetInstance>;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
10
|
//# sourceMappingURL=ModalBottomSheet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModalBottomSheet.d.ts","sourceRoot":"","sources":["../../../src/ModalBottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ModalBottomSheet.d.ts","sourceRoot":"","sources":["../../../src/ModalBottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AAEvB,qFAAqF;AACrF,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CACjD,gBAAgB,EAChB,OAAO,CACR;CAAG;AAEJ,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,GAAI,mBAG9B,qBAAqB,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAA;CAAE,4CAE5D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BottomSheet } from './BottomSheet';
|
|
2
|
-
export type { BottomSheetProps } from './BottomSheet';
|
|
2
|
+
export type { BottomSheetInstance, BottomSheetProps, PositionChangeEventData, } from './BottomSheet';
|
|
3
3
|
export { ModalBottomSheet } from './ModalBottomSheet';
|
|
4
4
|
export type { ModalBottomSheetProps } from './ModalBottomSheet';
|
|
5
5
|
export { BottomSheetProvider } from './BottomSheetProvider';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
package/src/BottomSheet.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import type { StyleProp, ViewStyle } from 'react-native';
|
|
1
|
+
import { type ComponentRef, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import type { NativeSyntheticEvent, StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
import { StyleSheet, View, useWindowDimensions } from 'react-native';
|
|
4
4
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
5
|
|
|
@@ -10,6 +10,24 @@ import { type Detent } from './bottomSheetUtils';
|
|
|
10
10
|
export type { Detent, DetentValue } from './bottomSheetUtils';
|
|
11
11
|
export { programmatic } from './bottomSheetUtils';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Imperative handle for a `BottomSheet`. It resolves to the underlying native
|
|
15
|
+
* sheet view—the one that emits `onPositionChange`—so it plugs straight into
|
|
16
|
+
* Reanimated’s `createAnimatedComponent`.
|
|
17
|
+
*/
|
|
18
|
+
export type BottomSheetInstance = ComponentRef<
|
|
19
|
+
typeof BottomSheetNativeComponent
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
24
|
+
* `event.nativeEvent`.
|
|
25
|
+
*/
|
|
26
|
+
export type PositionChangeEventData = Readonly<{
|
|
27
|
+
/** Sheet position, in points from the bottom. */
|
|
28
|
+
position: number;
|
|
29
|
+
}>;
|
|
30
|
+
|
|
13
31
|
/**
|
|
14
32
|
* Props for the inline bottom-sheet component.
|
|
15
33
|
*/
|
|
@@ -45,8 +63,15 @@ export interface BottomSheetProps {
|
|
|
45
63
|
onIndexChange?: (index: number) => void;
|
|
46
64
|
/** Called when a snap animation settles, including programmatic changes. */
|
|
47
65
|
onSettle?: (index: number) => void;
|
|
48
|
-
/**
|
|
49
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Called as the sheet position changes. A standard native direct event; read
|
|
68
|
+
* `event.nativeEvent.position` (points from the bottom). Because it is a real
|
|
69
|
+
* native event, it also works on the UI thread when the component is wrapped
|
|
70
|
+
* with Reanimated’s `createAnimatedComponent` and given a worklet handler.
|
|
71
|
+
*/
|
|
72
|
+
onPositionChange?: (
|
|
73
|
+
event: NativeSyntheticEvent<PositionChangeEventData>
|
|
74
|
+
) => void;
|
|
50
75
|
/** Internal flag used by `ModalBottomSheet`. */
|
|
51
76
|
modal?: boolean;
|
|
52
77
|
/**
|
|
@@ -88,7 +113,8 @@ export const BottomSheet = ({
|
|
|
88
113
|
disableScrollableNegotiation = false,
|
|
89
114
|
scrimColor,
|
|
90
115
|
scrimOpacities,
|
|
91
|
-
|
|
116
|
+
ref,
|
|
117
|
+
}: BottomSheetProps & { ref?: Ref<BottomSheetInstance> }) => {
|
|
92
118
|
const { height: windowHeight } = useWindowDimensions();
|
|
93
119
|
const insets = useSafeAreaInsets();
|
|
94
120
|
const maxHeight = windowHeight - insets.top;
|
|
@@ -129,13 +155,6 @@ export const BottomSheet = ({
|
|
|
129
155
|
onSettle?.(event.nativeEvent.index);
|
|
130
156
|
};
|
|
131
157
|
|
|
132
|
-
const handlePositionChange = (event: {
|
|
133
|
-
nativeEvent: { position: number };
|
|
134
|
-
}) => {
|
|
135
|
-
const height = event.nativeEvent.position;
|
|
136
|
-
onPositionChange?.(height);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
158
|
const sheet = (
|
|
140
159
|
<View
|
|
141
160
|
style={StyleSheet.absoluteFill}
|
|
@@ -143,6 +162,7 @@ export const BottomSheet = ({
|
|
|
143
162
|
>
|
|
144
163
|
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
|
|
145
164
|
<BottomSheetNativeComponent
|
|
165
|
+
ref={ref}
|
|
146
166
|
pointerEvents="box-none"
|
|
147
167
|
style={[
|
|
148
168
|
{
|
|
@@ -167,7 +187,7 @@ export const BottomSheet = ({
|
|
|
167
187
|
scrimOpacities={resolvedScrimOpacity}
|
|
168
188
|
onIndexChange={handleIndexChange}
|
|
169
189
|
onSettle={handleSettle}
|
|
170
|
-
onPositionChange={
|
|
190
|
+
onPositionChange={onPositionChange}
|
|
171
191
|
>
|
|
172
192
|
{surface != null && (
|
|
173
193
|
<BottomSheetSurfaceNativeComponent
|
package/src/ModalBottomSheet.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BottomSheet,
|
|
5
|
+
type BottomSheetInstance,
|
|
6
|
+
type BottomSheetProps,
|
|
7
|
+
} from './BottomSheet';
|
|
2
8
|
|
|
3
9
|
/** Props for the modal bottom-sheet variant rendered through the provider portal. */
|
|
4
10
|
export interface ModalBottomSheetProps extends Omit<
|
|
@@ -7,6 +13,9 @@ export interface ModalBottomSheetProps extends Omit<
|
|
|
7
13
|
> {}
|
|
8
14
|
|
|
9
15
|
/** Bottom sheet presented above the current UI with a scrim. */
|
|
10
|
-
export const ModalBottomSheet = (
|
|
11
|
-
|
|
16
|
+
export const ModalBottomSheet = ({
|
|
17
|
+
ref,
|
|
18
|
+
...props
|
|
19
|
+
}: ModalBottomSheetProps & { ref?: Ref<BottomSheetInstance> }) => (
|
|
20
|
+
<BottomSheet {...props} ref={ref} modal />
|
|
12
21
|
);
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { BottomSheet } from './BottomSheet';
|
|
2
|
-
export type {
|
|
2
|
+
export type {
|
|
3
|
+
BottomSheetInstance,
|
|
4
|
+
BottomSheetProps,
|
|
5
|
+
PositionChangeEventData,
|
|
6
|
+
} from './BottomSheet';
|
|
3
7
|
export { ModalBottomSheet } from './ModalBottomSheet';
|
|
4
8
|
export type { ModalBottomSheetProps } from './ModalBottomSheet';
|
|
5
9
|
export { BottomSheetProvider } from './BottomSheetProvider';
|