@swmansion/react-native-bottom-sheet 0.14.0-next.2 → 0.14.0-next.3
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 +11 -6
- package/lib/module/BottomSheet.js +17 -24
- package/lib/module/BottomSheet.js.map +1 -1
- package/lib/module/ModalBottomSheet.js +1 -5
- package/lib/module/ModalBottomSheet.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/BottomSheet.d.ts +18 -14
- package/lib/typescript/src/BottomSheet.d.ts.map +1 -1
- package/lib/typescript/src/ModalBottomSheet.d.ts +2 -5
- 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 +41 -39
- package/src/ModalBottomSheet.tsx +3 -12
- package/src/index.tsx +1 -5
package/README.md
CHANGED
|
@@ -341,8 +341,9 @@ const position = useSharedValue(0);
|
|
|
341
341
|
```
|
|
342
342
|
|
|
343
343
|
Because `onPositionChange` is a native event, you can also handle it on the UI
|
|
344
|
-
thread
|
|
345
|
-
|
|
344
|
+
thread. Pass `Animated.createAnimatedComponent` to `wrapNativeView`—the library
|
|
345
|
+
applies it to the native sheet view—and give `onPositionChange` a worklet
|
|
346
|
+
handler from `useEvent`:
|
|
346
347
|
|
|
347
348
|
```tsx
|
|
348
349
|
import type { NativeSyntheticEvent } from 'react-native';
|
|
@@ -351,8 +352,6 @@ import {
|
|
|
351
352
|
BottomSheet,
|
|
352
353
|
type PositionChangeEventData,
|
|
353
354
|
} from '@swmansion/react-native-bottom-sheet';
|
|
354
|
-
|
|
355
|
-
const AnimatedBottomSheet = Animated.createAnimatedComponent(BottomSheet);
|
|
356
355
|
```
|
|
357
356
|
|
|
358
357
|
```tsx
|
|
@@ -370,16 +369,22 @@ const onPositionChange = useEvent<
|
|
|
370
369
|
```
|
|
371
370
|
|
|
372
371
|
```tsx
|
|
373
|
-
<
|
|
372
|
+
<BottomSheet // Or `ModalBottomSheet`.
|
|
374
373
|
index={index}
|
|
375
374
|
onIndexChange={setIndex}
|
|
376
375
|
surface={/* ... */}
|
|
376
|
+
wrapNativeView={Animated.createAnimatedComponent}
|
|
377
377
|
onPositionChange={onPositionChange}
|
|
378
378
|
>
|
|
379
379
|
{/* ... */}
|
|
380
|
-
</
|
|
380
|
+
</BottomSheet>
|
|
381
381
|
```
|
|
382
382
|
|
|
383
|
+
`wrapNativeView` keeps the animated wrapper on the native sheet view itself, so
|
|
384
|
+
the worklet binds on first render—for both inline and modal sheets—without the
|
|
385
|
+
library depending on Reanimated. Pass a stable function (such as
|
|
386
|
+
`Animated.createAnimatedComponent`), not an inline lambda.
|
|
387
|
+
|
|
383
388
|
Inside the worklet, Reanimated unwraps the native event, so you read
|
|
384
389
|
`event.position` directly rather than `event.nativeEvent.position`. The handler
|
|
385
390
|
runs on the UI thread on every frame the sheet moves.
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { useState } from 'react';
|
|
3
4
|
import { StyleSheet, View, useWindowDimensions } from 'react-native';
|
|
4
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
|
-
import
|
|
6
|
+
import BottomSheetNativeView from './BottomSheetNativeComponent';
|
|
6
7
|
import BottomSheetSurfaceNativeComponent from './BottomSheetSurfaceNativeComponent';
|
|
7
8
|
import { Portal } from "./BottomSheetProvider.js";
|
|
8
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
10
|
export { programmatic } from "./bottomSheetUtils.js";
|
|
10
11
|
|
|
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
12
|
/**
|
|
18
13
|
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
19
14
|
* `event.nativeEvent`.
|
|
@@ -34,11 +29,11 @@ export const BottomSheet = ({
|
|
|
34
29
|
onIndexChange,
|
|
35
30
|
onSettle,
|
|
36
31
|
onPositionChange,
|
|
32
|
+
wrapNativeView,
|
|
37
33
|
modal = false,
|
|
38
34
|
disableScrollableNegotiation = false,
|
|
39
35
|
scrimColor,
|
|
40
|
-
scrimOpacities
|
|
41
|
-
ref
|
|
36
|
+
scrimOpacities
|
|
42
37
|
}) => {
|
|
43
38
|
const {
|
|
44
39
|
height: windowHeight
|
|
@@ -74,14 +69,22 @@ export const BottomSheet = ({
|
|
|
74
69
|
const handleSettle = event => {
|
|
75
70
|
onSettle?.(event.nativeEvent.index);
|
|
76
71
|
};
|
|
72
|
+
|
|
73
|
+
// The native sheet view, optionally wrapped (e.g. with
|
|
74
|
+
// `Animated.createAnimatedComponent`) so a Reanimated worklet can handle
|
|
75
|
+
// `onPositionChange` on the UI thread. Wrapping the leaf native view (rather
|
|
76
|
+
// than this whole component) keeps the animated boundary on the host that
|
|
77
|
+
// emits events—so it resolves at mount, inline or inside the modal portal
|
|
78
|
+
// alike. Computed once: a fresh wrapped component each render would remount
|
|
79
|
+
// the native sheet.
|
|
80
|
+
const [NativeView] = useState(() => wrapNativeView?.(BottomSheetNativeView) ?? BottomSheetNativeView);
|
|
77
81
|
const sheet = /*#__PURE__*/_jsx(View, {
|
|
78
82
|
style: StyleSheet.absoluteFill,
|
|
79
83
|
pointerEvents: modal ? isCollapsed ? 'none' : 'auto' : 'box-none',
|
|
80
84
|
children: /*#__PURE__*/_jsx(View, {
|
|
81
85
|
pointerEvents: "box-none",
|
|
82
86
|
style: StyleSheet.absoluteFill,
|
|
83
|
-
children: /*#__PURE__*/_jsxs(
|
|
84
|
-
ref: ref,
|
|
87
|
+
children: /*#__PURE__*/_jsxs(NativeView, {
|
|
85
88
|
pointerEvents: "box-none",
|
|
86
89
|
style: [{
|
|
87
90
|
position: 'absolute',
|
|
@@ -124,18 +127,8 @@ export const BottomSheet = ({
|
|
|
124
127
|
})
|
|
125
128
|
});
|
|
126
129
|
if (modal) {
|
|
127
|
-
return /*#__PURE__*/
|
|
128
|
-
children:
|
|
129
|
-
collapsable: false,
|
|
130
|
-
pointerEvents: "none",
|
|
131
|
-
style: {
|
|
132
|
-
position: 'absolute',
|
|
133
|
-
width: 0,
|
|
134
|
-
height: 0
|
|
135
|
-
}
|
|
136
|
-
}), /*#__PURE__*/_jsx(Portal, {
|
|
137
|
-
children: sheet
|
|
138
|
-
})]
|
|
130
|
+
return /*#__PURE__*/_jsx(Portal, {
|
|
131
|
+
children: sheet
|
|
139
132
|
});
|
|
140
133
|
}
|
|
141
134
|
return sheet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StyleSheet","View","useWindowDimensions","useSafeAreaInsets","
|
|
1
|
+
{"version":3,"names":["useState","StyleSheet","View","useWindowDimensions","useSafeAreaInsets","BottomSheetNativeView","BottomSheetSurfaceNativeComponent","Portal","jsx","_jsx","jsxs","_jsxs","programmatic","BottomSheet","children","surface","style","detents","index","animateIn","onIndexChange","onSettle","onPositionChange","wrapNativeView","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","NativeView","sheet","absoluteFill","pointerEvents","position","left","right","bottom","maxDetentHeight","collapsable","flex"],"sourceRoot":"../../src","sources":["BottomSheet.tsx"],"mappings":";;AAAA,SAASA,QAAQ,QAA4C,OAAO;AAEpE,SAASC,UAAU,EAAEC,IAAI,EAAEC,mBAAmB,QAAQ,cAAc;AACpE,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,OAAOC,qB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;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,12 +5,8 @@ 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 = ({
|
|
9
|
-
ref,
|
|
10
|
-
...props
|
|
11
|
-
}) => /*#__PURE__*/_jsx(BottomSheet, {
|
|
8
|
+
export const ModalBottomSheet = props => /*#__PURE__*/_jsx(BottomSheet, {
|
|
12
9
|
...props,
|
|
13
|
-
ref: ref,
|
|
14
10
|
modal: true
|
|
15
11
|
});
|
|
16
12
|
//# sourceMappingURL=ModalBottomSheet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BottomSheet","jsx","_jsx","ModalBottomSheet","
|
|
1
|
+
{"version":3,"names":["BottomSheet","jsx","_jsx","ModalBottomSheet","props","modal"],"sourceRoot":"../../src","sources":["ModalBottomSheet.tsx"],"mappings":";;AAAA,SAASA,WAAW,QAA+B,kBAAe;;AAElE;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAMA;AACA,OAAO,MAAMC,gBAAgB,GAAIC,KAA4B,iBAC3DF,IAAA,CAACF,WAAW;EAAA,GAAKI,KAAK;EAAEC,KAAK;AAAA,CAAE,CAChC","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;AAE3C,SAASC,gBAAgB,QAAQ,uBAAoB;AAErD,SAASC,mBAAmB,QAAQ,0BAAuB;AAE3D,SAASC,YAAY,QAAQ,uBAAoB","ignoreList":[]}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
2
|
import type { NativeSyntheticEvent, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import { type NativeProps } from './BottomSheetNativeComponent';
|
|
4
4
|
import { type Detent } from './bottomSheetUtils';
|
|
5
5
|
export type { Detent, DetentValue } from './bottomSheetUtils';
|
|
6
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
7
|
/**
|
|
14
8
|
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
15
9
|
* `event.nativeEvent`.
|
|
@@ -55,11 +49,23 @@ export interface BottomSheetProps {
|
|
|
55
49
|
onSettle?: (index: number) => void;
|
|
56
50
|
/**
|
|
57
51
|
* Called as the sheet position changes. A standard native direct event; read
|
|
58
|
-
* `event.nativeEvent.position` (points from the bottom).
|
|
59
|
-
*
|
|
60
|
-
* with Reanimated’s `createAnimatedComponent` and given a worklet handler.
|
|
52
|
+
* `event.nativeEvent.position` (points from the bottom). To handle it on the
|
|
53
|
+
* UI thread, see `wrapNativeView`.
|
|
61
54
|
*/
|
|
62
55
|
onPositionChange?: (event: NativeSyntheticEvent<PositionChangeEventData>) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Wraps the native sheet view—the one that emits `onPositionChange`—before it
|
|
58
|
+
* is rendered. Pass `Animated.createAnimatedComponent` to handle
|
|
59
|
+
* `onPositionChange` on the UI thread with a Reanimated worklet (e.g., from
|
|
60
|
+
* `useEvent`): Because the animated wrapper sits directly on the native view,
|
|
61
|
+
* the worklet binds to the sheet at mount, for both inline and modal sheets,
|
|
62
|
+
* without the library depending on Reanimated.
|
|
63
|
+
*
|
|
64
|
+
* Called once; pass a stable function (a module-level reference such as
|
|
65
|
+
* `Animated.createAnimatedComponent`, not an inline lambda recreated each
|
|
66
|
+
* render).
|
|
67
|
+
*/
|
|
68
|
+
wrapNativeView?: (component: ComponentType<NativeProps>) => ComponentType<NativeProps>;
|
|
63
69
|
/** Internal flag used by `ModalBottomSheet`. */
|
|
64
70
|
modal?: boolean;
|
|
65
71
|
/**
|
|
@@ -86,7 +92,5 @@ export interface BottomSheetProps {
|
|
|
86
92
|
scrimOpacities?: number[];
|
|
87
93
|
}
|
|
88
94
|
/** Native bottom sheet that renders inline within the current screen layout. */
|
|
89
|
-
export declare const BottomSheet: ({ children, surface, style, detents, index, animateIn, onIndexChange, onSettle, onPositionChange, modal, disableScrollableNegotiation, scrimColor, scrimOpacities,
|
|
90
|
-
ref?: Ref<BottomSheetInstance>;
|
|
91
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
95
|
+
export declare const BottomSheet: ({ children, surface, style, detents, index, animateIn, onIndexChange, onSettle, onPositionChange, wrapNativeView, modal, disableScrollableNegotiation, scrimColor, scrimOpacities, }: BottomSheetProps) => import("react/jsx-runtime").JSX.Element;
|
|
92
96
|
//# sourceMappingURL=BottomSheet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../src/BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.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CAAC,EAAE,CACf,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,KAClC,aAAa,CAAC,WAAW,CAAC,CAAC;IAChC,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,sLAezB,gBAAgB,4CAgHlB,CAAC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type BottomSheetInstance, type BottomSheetProps } from './BottomSheet';
|
|
1
|
+
import { type BottomSheetProps } from './BottomSheet';
|
|
3
2
|
/** Props for the modal bottom-sheet variant rendered through the provider portal. */
|
|
4
3
|
export interface ModalBottomSheetProps extends Omit<BottomSheetProps, 'modal'> {
|
|
5
4
|
}
|
|
6
5
|
/** Bottom sheet presented above the current UI with a scrim. */
|
|
7
|
-
export declare const ModalBottomSheet: (
|
|
8
|
-
ref?: Ref<BottomSheetInstance>;
|
|
9
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const ModalBottomSheet: (props: ModalBottomSheetProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
7
|
//# 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,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEnE,qFAAqF;AACrF,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CACjD,gBAAgB,EAChB,OAAO,CACR;CAAG;AAEJ,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,4CAE5D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BottomSheet } from './BottomSheet';
|
|
2
|
-
export type {
|
|
2
|
+
export type { 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,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC/E,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,24 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState, type ComponentType, type ReactNode } from 'react';
|
|
2
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
|
|
|
6
|
-
import
|
|
6
|
+
import BottomSheetNativeView, {
|
|
7
|
+
type NativeProps,
|
|
8
|
+
} from './BottomSheetNativeComponent';
|
|
7
9
|
import BottomSheetSurfaceNativeComponent from './BottomSheetSurfaceNativeComponent';
|
|
8
10
|
import { Portal } from './BottomSheetProvider';
|
|
9
11
|
import { type Detent } from './bottomSheetUtils';
|
|
10
12
|
export type { Detent, DetentValue } from './bottomSheetUtils';
|
|
11
13
|
export { programmatic } from './bottomSheetUtils';
|
|
12
14
|
|
|
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
15
|
/**
|
|
23
16
|
* Payload of the {@link BottomSheetProps.onPositionChange} event, accessed as
|
|
24
17
|
* `event.nativeEvent`.
|
|
@@ -65,13 +58,27 @@ export interface BottomSheetProps {
|
|
|
65
58
|
onSettle?: (index: number) => void;
|
|
66
59
|
/**
|
|
67
60
|
* Called as the sheet position changes. A standard native direct event; read
|
|
68
|
-
* `event.nativeEvent.position` (points from the bottom).
|
|
69
|
-
*
|
|
70
|
-
* with Reanimated’s `createAnimatedComponent` and given a worklet handler.
|
|
61
|
+
* `event.nativeEvent.position` (points from the bottom). To handle it on the
|
|
62
|
+
* UI thread, see `wrapNativeView`.
|
|
71
63
|
*/
|
|
72
64
|
onPositionChange?: (
|
|
73
65
|
event: NativeSyntheticEvent<PositionChangeEventData>
|
|
74
66
|
) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Wraps the native sheet view—the one that emits `onPositionChange`—before it
|
|
69
|
+
* is rendered. Pass `Animated.createAnimatedComponent` to handle
|
|
70
|
+
* `onPositionChange` on the UI thread with a Reanimated worklet (e.g., from
|
|
71
|
+
* `useEvent`): Because the animated wrapper sits directly on the native view,
|
|
72
|
+
* the worklet binds to the sheet at mount, for both inline and modal sheets,
|
|
73
|
+
* without the library depending on Reanimated.
|
|
74
|
+
*
|
|
75
|
+
* Called once; pass a stable function (a module-level reference such as
|
|
76
|
+
* `Animated.createAnimatedComponent`, not an inline lambda recreated each
|
|
77
|
+
* render).
|
|
78
|
+
*/
|
|
79
|
+
wrapNativeView?: (
|
|
80
|
+
component: ComponentType<NativeProps>
|
|
81
|
+
) => ComponentType<NativeProps>;
|
|
75
82
|
/** Internal flag used by `ModalBottomSheet`. */
|
|
76
83
|
modal?: boolean;
|
|
77
84
|
/**
|
|
@@ -109,12 +116,12 @@ export const BottomSheet = ({
|
|
|
109
116
|
onIndexChange,
|
|
110
117
|
onSettle,
|
|
111
118
|
onPositionChange,
|
|
119
|
+
wrapNativeView,
|
|
112
120
|
modal = false,
|
|
113
121
|
disableScrollableNegotiation = false,
|
|
114
122
|
scrimColor,
|
|
115
123
|
scrimOpacities,
|
|
116
|
-
|
|
117
|
-
}: BottomSheetProps & { ref?: Ref<BottomSheetInstance> }) => {
|
|
124
|
+
}: BottomSheetProps) => {
|
|
118
125
|
const { height: windowHeight } = useWindowDimensions();
|
|
119
126
|
const insets = useSafeAreaInsets();
|
|
120
127
|
const maxHeight = windowHeight - insets.top;
|
|
@@ -155,14 +162,28 @@ export const BottomSheet = ({
|
|
|
155
162
|
onSettle?.(event.nativeEvent.index);
|
|
156
163
|
};
|
|
157
164
|
|
|
165
|
+
// The native sheet view, optionally wrapped (e.g. with
|
|
166
|
+
// `Animated.createAnimatedComponent`) so a Reanimated worklet can handle
|
|
167
|
+
// `onPositionChange` on the UI thread. Wrapping the leaf native view (rather
|
|
168
|
+
// than this whole component) keeps the animated boundary on the host that
|
|
169
|
+
// emits events—so it resolves at mount, inline or inside the modal portal
|
|
170
|
+
// alike. Computed once: a fresh wrapped component each render would remount
|
|
171
|
+
// the native sheet.
|
|
172
|
+
const [NativeView] = useState(
|
|
173
|
+
() =>
|
|
174
|
+
(wrapNativeView?.(BottomSheetNativeView) ??
|
|
175
|
+
BottomSheetNativeView) as ComponentType<
|
|
176
|
+
NativeProps & { children?: ReactNode }
|
|
177
|
+
>
|
|
178
|
+
);
|
|
179
|
+
|
|
158
180
|
const sheet = (
|
|
159
181
|
<View
|
|
160
182
|
style={StyleSheet.absoluteFill}
|
|
161
183
|
pointerEvents={modal ? (isCollapsed ? 'none' : 'auto') : 'box-none'}
|
|
162
184
|
>
|
|
163
185
|
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
|
|
164
|
-
<
|
|
165
|
-
ref={ref}
|
|
186
|
+
<NativeView
|
|
166
187
|
pointerEvents="box-none"
|
|
167
188
|
style={[
|
|
168
189
|
{
|
|
@@ -202,32 +223,13 @@ export const BottomSheet = ({
|
|
|
202
223
|
{children}
|
|
203
224
|
<View collapsable={false} pointerEvents="none" />
|
|
204
225
|
</View>
|
|
205
|
-
</
|
|
226
|
+
</NativeView>
|
|
206
227
|
</View>
|
|
207
228
|
</View>
|
|
208
229
|
);
|
|
209
230
|
|
|
210
231
|
if (modal) {
|
|
211
|
-
return
|
|
212
|
-
<>
|
|
213
|
-
{/*
|
|
214
|
-
A zero-size host view kept in place so anything that resolves a host
|
|
215
|
-
instance from this component finds one synchronously. The sheet itself
|
|
216
|
-
is teleported into the provider's portal and mounts a commit later, so
|
|
217
|
-
at mount this component otherwise renders nothing here. Reanimated's
|
|
218
|
-
`createAnimatedComponent` calls `findHostInstance` on mount and would
|
|
219
|
-
throw "Cannot find host instance for this component"; the anchor lets
|
|
220
|
-
`createAnimatedComponent(ModalBottomSheet)` mount, after which the
|
|
221
|
-
forwarded `ref` resolves to the real sheet view.
|
|
222
|
-
*/}
|
|
223
|
-
<View
|
|
224
|
-
collapsable={false}
|
|
225
|
-
pointerEvents="none"
|
|
226
|
-
style={{ position: 'absolute', width: 0, height: 0 }}
|
|
227
|
-
/>
|
|
228
|
-
<Portal>{sheet}</Portal>
|
|
229
|
-
</>
|
|
230
|
-
);
|
|
232
|
+
return <Portal>{sheet}</Portal>;
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
return sheet;
|
package/src/ModalBottomSheet.tsx
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
BottomSheet,
|
|
5
|
-
type BottomSheetInstance,
|
|
6
|
-
type BottomSheetProps,
|
|
7
|
-
} from './BottomSheet';
|
|
1
|
+
import { BottomSheet, type BottomSheetProps } from './BottomSheet';
|
|
8
2
|
|
|
9
3
|
/** Props for the modal bottom-sheet variant rendered through the provider portal. */
|
|
10
4
|
export interface ModalBottomSheetProps extends Omit<
|
|
@@ -13,9 +7,6 @@ export interface ModalBottomSheetProps extends Omit<
|
|
|
13
7
|
> {}
|
|
14
8
|
|
|
15
9
|
/** Bottom sheet presented above the current UI with a scrim. */
|
|
16
|
-
export const ModalBottomSheet = (
|
|
17
|
-
|
|
18
|
-
...props
|
|
19
|
-
}: ModalBottomSheetProps & { ref?: Ref<BottomSheetInstance> }) => (
|
|
20
|
-
<BottomSheet {...props} ref={ref} modal />
|
|
10
|
+
export const ModalBottomSheet = (props: ModalBottomSheetProps) => (
|
|
11
|
+
<BottomSheet {...props} modal />
|
|
21
12
|
);
|
package/src/index.tsx
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export { BottomSheet } from './BottomSheet';
|
|
2
|
-
export type {
|
|
3
|
-
BottomSheetInstance,
|
|
4
|
-
BottomSheetProps,
|
|
5
|
-
PositionChangeEventData,
|
|
6
|
-
} from './BottomSheet';
|
|
2
|
+
export type { BottomSheetProps, PositionChangeEventData } from './BottomSheet';
|
|
7
3
|
export { ModalBottomSheet } from './ModalBottomSheet';
|
|
8
4
|
export type { ModalBottomSheetProps } from './ModalBottomSheet';
|
|
9
5
|
export { BottomSheetProvider } from './BottomSheetProvider';
|