@delacour/react-native-bottom-sheet 0.3.0-alpha.20261023075443 → 0.3.0-alpha.20261024103119
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/package.json +1 -1
- package/src/components/bottom-sheet.types.ts +1 -1
- package/src/core/AGENTS.md +3 -2
- package/src/core/keyboard/keyboard-lift.test.ts +39 -1
- package/src/core/keyboard/keyboard-lift.ts +8 -1
- package/src/core/sheet.types.ts +3 -1
- package/src/scrollable/create-bottom-sheet-scrollable.tsx +5 -1
- package/src/state/use-sheet-geometry.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-bottom-sheet",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.20261024103119",
|
|
4
4
|
"description": "Headless bottom sheet engine for React Native — no tokens, no className",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -104,7 +104,7 @@ export type BottomSheetProps = SheetHaptics & {
|
|
|
104
104
|
keyboardBehavior?: KeyboardBehavior;
|
|
105
105
|
/** @default "restore" */
|
|
106
106
|
keyboardBlurBehavior?: KeyboardBlurBehavior;
|
|
107
|
-
/**
|
|
107
|
+
/** Where the keyboard's lift stops — the container's top, `maxDynamicContentSize`, or the highest snap point. @default "container" */
|
|
108
108
|
keyboardLiftLimit?: KeyboardLiftLimit;
|
|
109
109
|
/** @default "inside" */
|
|
110
110
|
keyboardScope?: KeyboardScope;
|
package/src/core/AGENTS.md
CHANGED
|
@@ -33,7 +33,7 @@ at the moment a view needs it, by `geometry/position.ts`, and nowhere else.
|
|
|
33
33
|
| `snap-points/select-snap-height.ts` | W `selectSnapHeight` — nearest candidate to `height + projection · velocity`; closes only when given a closed height |
|
|
34
34
|
| `snap-points/over-drag.ts` | W `resistOverDrag` — slope 1 at the edge, square-root beyond; factor 0 clamps |
|
|
35
35
|
| `snap-points/sheet-state.ts` | W `sheetState` — closed / opened / extended / overExtended / fill |
|
|
36
|
-
| `keyboard/keyboard-lift.ts` | W `keyboardInContainer`, W `keyboardLift` — the lift, band and gap subtracted in step with progress, stopped at the ceiling; W `keyboardCeiling` — a capped dynamic sheet is lifted no higher than its cap |
|
|
36
|
+
| `keyboard/keyboard-lift.ts` | W `keyboardInContainer`, W `keyboardLift` — the lift, band and gap subtracted in step with progress, stopped at the ceiling; W `keyboardCeiling` — a capped dynamic sheet is lifted no higher than its cap, and under `highestSnapPoint` no sheet past its highest snap point |
|
|
37
37
|
| `keyboard/keyboard-owner.ts` | W `isInputInsideSheet` — the `keyboardScope: "inside"` geometry test |
|
|
38
38
|
| `keyboard/content-area.ts` | W `contentArea` — what the body may fill, never negative |
|
|
39
39
|
| `keyboard/container-layout-guard.ts` | `acceptContainerLayout` — refuses Android's adjustResize double-count |
|
|
@@ -71,7 +71,8 @@ band = detached ? 0 : inset bandNow = band · (
|
|
|
71
71
|
footerHeight = hasFooter ? footerContent + bandNow : 0
|
|
72
72
|
dynamicSnapPoint = min(handle + content + (hasFooter ? footerContent : 0) + band, maxDynamicContentSize, available)
|
|
73
73
|
snapPoints = sortAsc(unique(normalize(spec, available) ∪ {dynamicSnapPoint if dynamicSizing}))
|
|
74
|
-
ceiling = keyboardLiftLimit = maxDynamicContentSize && dynamicSizing && maxDynamicContentSize ? min(maxDynamicContentSize, maxHeight)
|
|
74
|
+
ceiling = keyboardLiftLimit = maxDynamicContentSize && dynamicSizing && maxDynamicContentSize ? min(maxDynamicContentSize, maxHeight)
|
|
75
|
+
: keyboardLiftLimit = highestSnapPoint && highest > 0 ? min(highest, maxHeight) : maxHeight
|
|
75
76
|
keyboardLift = behavior ∈ {interactive, extend} ? clamp(kb − band · p − (detached ? restingBottom : 0), 0, ceiling − base) : 0
|
|
76
77
|
height = clamp(base + keyboardLift, closedHeight, maxHeight)
|
|
77
78
|
translateY = C − restingBottom − height
|
|
@@ -78,7 +78,7 @@ describe("keyboardLift under a ceiling", () => {
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
describe("keyboardCeiling", () => {
|
|
81
|
-
const capped = { limit: "maxDynamicContentSize", dynamicSizing: true, maxHeight: 852 } as const;
|
|
81
|
+
const capped = { limit: "maxDynamicContentSize", dynamicSizing: true, maxHeight: 852, highest: 0 } as const;
|
|
82
82
|
|
|
83
83
|
test("a dynamic sheet with a cap is lifted no higher than the cap", () => {
|
|
84
84
|
expect(keyboardCeiling({ ...capped, maxDynamicContentSize: 724 })).toBe(724);
|
|
@@ -96,4 +96,42 @@ describe("keyboardCeiling", () => {
|
|
|
96
96
|
test("the default limit is the container, cap or no cap", () => {
|
|
97
97
|
expect(keyboardCeiling({ ...capped, limit: "container", maxDynamicContentSize: 724 })).toBe(852);
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
test("highestSnapPoint stops the lift at the highest snap point, explicit or dynamic", () => {
|
|
101
|
+
const held = { ...capped, limit: "highestSnapPoint", maxDynamicContentSize: undefined } as const;
|
|
102
|
+
expect(keyboardCeiling({ ...held, dynamicSizing: false, highest: 772 })).toBe(772);
|
|
103
|
+
expect(keyboardCeiling({ ...held, highest: 400 })).toBe(400);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("highestSnapPoint never lifts past the container, and an unmeasured one falls back to it", () => {
|
|
107
|
+
const held = {
|
|
108
|
+
...capped,
|
|
109
|
+
limit: "highestSnapPoint",
|
|
110
|
+
dynamicSizing: false,
|
|
111
|
+
maxDynamicContentSize: undefined,
|
|
112
|
+
} as const;
|
|
113
|
+
expect(keyboardCeiling({ ...held, highest: 900 })).toBe(852);
|
|
114
|
+
expect(keyboardCeiling({ ...held, highest: 0 })).toBe(852);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a sheet resting at its highest snap point under highestSnapPoint is not lifted at all", () => {
|
|
118
|
+
const ceiling = keyboardCeiling({
|
|
119
|
+
...capped,
|
|
120
|
+
limit: "highestSnapPoint",
|
|
121
|
+
dynamicSizing: false,
|
|
122
|
+
maxDynamicContentSize: undefined,
|
|
123
|
+
highest: 772,
|
|
124
|
+
});
|
|
125
|
+
expect(
|
|
126
|
+
keyboardLift({
|
|
127
|
+
keyboardHeight: 336,
|
|
128
|
+
progress: 1,
|
|
129
|
+
band: 34,
|
|
130
|
+
behavior: "interactive",
|
|
131
|
+
gapBelow: 0,
|
|
132
|
+
base: 772,
|
|
133
|
+
ceiling,
|
|
134
|
+
})
|
|
135
|
+
).toBe(0);
|
|
136
|
+
});
|
|
99
137
|
});
|
|
@@ -60,6 +60,8 @@ export type KeyboardCeilingInput = {
|
|
|
60
60
|
maxDynamicContentSize: number | undefined;
|
|
61
61
|
/** The container's available height. */
|
|
62
62
|
maxHeight: number;
|
|
63
|
+
/** The highest snap point; read only under `highestSnapPoint`. */
|
|
64
|
+
highest: number;
|
|
63
65
|
};
|
|
64
66
|
|
|
65
67
|
/**
|
|
@@ -68,12 +70,17 @@ export type KeyboardCeilingInput = {
|
|
|
68
70
|
* The container's top, unless `limit` is `maxDynamicContentSize` and the sheet
|
|
69
71
|
* sizes to its content under that cap: then the lift stops at the cap and the
|
|
70
72
|
* keyboard covers the sheet's bottom instead, the body shrinking by it as
|
|
71
|
-
* always.
|
|
73
|
+
* always. `highestSnapPoint` does the same at the highest snap point, explicit
|
|
74
|
+
* or dynamic, so a sheet opened there holds still while a keyboard comes and
|
|
75
|
+
* goes. Decided on the UI thread, in the frame the keyboard moves — a caller
|
|
72
76
|
* shrinking the cap from a JS keyboard event lands a few frames late, and the
|
|
73
77
|
* sheet overshoots to the container's top before settling.
|
|
74
78
|
*/
|
|
75
79
|
export function keyboardCeiling(input: KeyboardCeilingInput): number {
|
|
76
80
|
"worklet";
|
|
81
|
+
if (input.limit === "highestSnapPoint") {
|
|
82
|
+
return input.highest > 0 && input.highest < input.maxHeight ? input.highest : input.maxHeight;
|
|
83
|
+
}
|
|
77
84
|
const cap = input.maxDynamicContentSize;
|
|
78
85
|
if (input.limit !== "maxDynamicContentSize" || !input.dynamicSizing || cap === undefined) return input.maxHeight;
|
|
79
86
|
const bounded = cap > 0 ? cap : 0;
|
package/src/core/sheet.types.ts
CHANGED
|
@@ -28,8 +28,10 @@ export type KeyboardBlurBehavior = "none" | "restore";
|
|
|
28
28
|
* `container` — to the container's top. `maxDynamicContentSize` — a sheet
|
|
29
29
|
* sized to its content stops at that cap, and the keyboard covers its bottom
|
|
30
30
|
* instead; for a caller whose cap already keeps the page in view.
|
|
31
|
+
* `highestSnapPoint` — the same at the highest snap point, so a sheet resting
|
|
32
|
+
* there is never lifted and its body shrinks by the keyboard instead.
|
|
31
33
|
*/
|
|
32
|
-
export type KeyboardLiftLimit = "container" | "maxDynamicContentSize";
|
|
34
|
+
export type KeyboardLiftLimit = "container" | "maxDynamicContentSize" | "highestSnapPoint";
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* Which focused inputs count as the sheet's own.
|
|
@@ -87,6 +87,9 @@ function footerElement(footer: ScrollableListFooter | undefined): ReactElement |
|
|
|
87
87
|
* list: a virtualised list measures its content container, and an array style
|
|
88
88
|
* makes that measurement lag a frame behind the layout.
|
|
89
89
|
*
|
|
90
|
+
* `keyboardDismissMode` defaults to `interactive` and is the caller's to
|
|
91
|
+
* change — a search list keeps its keyboard up while it scrolls with `none`.
|
|
92
|
+
*
|
|
90
93
|
* Refresh control is out of scope here — a `refreshControl` prop passes
|
|
91
94
|
* through untouched, but a pull-to-refresh at the top of a locked list fights
|
|
92
95
|
* the sheet's own pull-down, and no rule for that is written yet.
|
|
@@ -117,6 +120,7 @@ export function createBottomSheetScrollable<P extends object>(
|
|
|
117
120
|
decelerationRate,
|
|
118
121
|
children,
|
|
119
122
|
ListFooterComponent,
|
|
123
|
+
keyboardDismissMode = "interactive",
|
|
120
124
|
...rest
|
|
121
125
|
}: ScrollableProps): ReactElement {
|
|
122
126
|
const { state, geometry, pans, enableContentPanningGesture, setScrollableRef, removeScrollableRef } =
|
|
@@ -215,7 +219,7 @@ export function createBottomSheetScrollable<P extends object>(
|
|
|
215
219
|
{...rest}
|
|
216
220
|
animatedProps={animatedProps}
|
|
217
221
|
contentContainerStyle={StyleSheet.flatten(contentContainerStyle)}
|
|
218
|
-
keyboardDismissMode=
|
|
222
|
+
keyboardDismissMode={keyboardDismissMode}
|
|
219
223
|
ListFooterComponent={listFooter}
|
|
220
224
|
onContentSizeChange={handleContentSizeChange}
|
|
221
225
|
onScroll={scrollHandler}
|
|
@@ -58,14 +58,16 @@ export function useSheetGeometry(state: SheetSharedState): SheetGeometry {
|
|
|
58
58
|
state.keyboardOwned.value && state.config.value.keyboardBehavior !== "none" ? state.keyboardHeight.value : 0
|
|
59
59
|
);
|
|
60
60
|
// Under `keyboardLiftLimit="maxDynamicContentSize"` a capped dynamic sheet is
|
|
61
|
-
// lifted no higher than its cap
|
|
62
|
-
// from the keyboard's first
|
|
61
|
+
// lifted no higher than its cap, and under `"highestSnapPoint"` no higher than
|
|
62
|
+
// that — decided here, on the UI thread, so it holds from the keyboard's first
|
|
63
|
+
// frame.
|
|
63
64
|
const ceiling = useDerivedValue(() =>
|
|
64
65
|
keyboardCeiling({
|
|
65
66
|
limit: state.config.value.keyboardLiftLimit,
|
|
66
67
|
dynamicSizing: state.config.value.dynamicSizing,
|
|
67
68
|
maxDynamicContentSize: state.config.value.maxDynamicContentSize,
|
|
68
69
|
maxHeight: maxHeight.value,
|
|
70
|
+
highest: highest.value,
|
|
69
71
|
})
|
|
70
72
|
);
|
|
71
73
|
const lift = useDerivedValue(() =>
|