@asaddevworld/sheet-stack 0.0.0-stage → 0.1.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/LICENSE +20 -0
- package/README.md +150 -2
- package/lib/module/Backdrop.js +30 -0
- package/lib/module/Backdrop.js.map +1 -0
- package/lib/module/Sheet.js +303 -0
- package/lib/module/Sheet.js.map +1 -0
- package/lib/module/SheetHost.js +94 -0
- package/lib/module/SheetHost.js.map +1 -0
- package/lib/module/SheetProvider.js +76 -0
- package/lib/module/SheetProvider.js.map +1 -0
- package/lib/module/SheetScrollView.js +51 -0
- package/lib/module/SheetScrollView.js.map +1 -0
- package/lib/module/context.js +33 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/defaults.js +34 -0
- package/lib/module/defaults.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/snap.js +93 -0
- package/lib/module/utils/snap.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Backdrop.d.ts +9 -0
- package/lib/typescript/src/Backdrop.d.ts.map +1 -0
- package/lib/typescript/src/Sheet.d.ts +18 -0
- package/lib/typescript/src/Sheet.d.ts.map +1 -0
- package/lib/typescript/src/SheetHost.d.ts +2 -0
- package/lib/typescript/src/SheetHost.d.ts.map +1 -0
- package/lib/typescript/src/SheetProvider.d.ts +10 -0
- package/lib/typescript/src/SheetProvider.d.ts.map +1 -0
- package/lib/typescript/src/SheetScrollView.d.ts +7 -0
- package/lib/typescript/src/SheetScrollView.d.ts.map +1 -0
- package/lib/typescript/src/context.d.ts +20 -0
- package/lib/typescript/src/context.d.ts.map +1 -0
- package/lib/typescript/src/defaults.d.ts +13 -0
- package/lib/typescript/src/defaults.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +66 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/snap.d.ts +28 -0
- package/lib/typescript/src/utils/snap.d.ts.map +1 -0
- package/package.json +163 -4
- package/src/Backdrop.tsx +32 -0
- package/src/Sheet.tsx +404 -0
- package/src/SheetHost.tsx +132 -0
- package/src/SheetProvider.tsx +76 -0
- package/src/SheetScrollView.tsx +50 -0
- package/src/context.tsx +52 -0
- package/src/defaults.ts +38 -0
- package/src/index.tsx +13 -0
- package/src/types.ts +78 -0
- package/src/utils/snap.ts +101 -0
package/package.json
CHANGED
|
@@ -1,6 +1,165 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asaddevworld/sheet-stack",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Stackable bottom sheets for React Native: one provider, one hook, card-stack animation, snap points, gestures",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"rn-sheet-stack-source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace rn-sheet-stack-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"react-native",
|
|
44
|
+
"expo",
|
|
45
|
+
"bottom-sheet",
|
|
46
|
+
"sheet",
|
|
47
|
+
"modal",
|
|
48
|
+
"stack",
|
|
49
|
+
"reanimated",
|
|
50
|
+
"gesture-handler",
|
|
51
|
+
"animation",
|
|
52
|
+
"ios",
|
|
53
|
+
"android"
|
|
54
|
+
],
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/asadDevWorld/rn-sheet-stack.git"
|
|
58
|
+
},
|
|
59
|
+
"author": "Asad Ali <sadali3690@gmail.com> (https://github.com/asadDevWorld)",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/asadDevWorld/rn-sheet-stack/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/asadDevWorld/rn-sheet-stack#readme",
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"registry": "https://registry.npmjs.org/",
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@eslint/compat": "^2.1.1",
|
|
71
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
72
|
+
"@eslint/js": "^9.39.5",
|
|
73
|
+
"@jest/globals": "^29.7.0",
|
|
74
|
+
"@react-native/babel-preset": "0.88.1",
|
|
75
|
+
"@react-native/eslint-config": "0.88.1",
|
|
76
|
+
"@react-native/jest-preset": "0.88.1",
|
|
77
|
+
"@testing-library/react-native": "^13.3.3",
|
|
78
|
+
"@types/react": "^19.2.0",
|
|
79
|
+
"@types/react-test-renderer": "^19",
|
|
80
|
+
"del-cli": "^8.0.1",
|
|
81
|
+
"eslint": "^9.39.5",
|
|
82
|
+
"eslint-config-prettier": "^10.1.8",
|
|
83
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
84
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
85
|
+
"jest": "^29.7.0",
|
|
86
|
+
"prettier": "^3.9.10",
|
|
87
|
+
"react": "19.3.0",
|
|
88
|
+
"react-native": "0.88.1",
|
|
89
|
+
"react-native-builder-bob": "^0.44.1",
|
|
90
|
+
"react-native-gesture-handler": "~3.3.0",
|
|
91
|
+
"react-native-reanimated": "4.7.1",
|
|
92
|
+
"react-native-safe-area-context": "~5.10.1",
|
|
93
|
+
"react-native-worklets": "0.13.0",
|
|
94
|
+
"react-test-renderer": "19.3.0",
|
|
95
|
+
"turbo": "^2.11.10",
|
|
96
|
+
"typescript": "^6.0.3"
|
|
97
|
+
},
|
|
98
|
+
"peerDependencies": {
|
|
99
|
+
"react": "*",
|
|
100
|
+
"react-native": "*",
|
|
101
|
+
"react-native-gesture-handler": ">=3.0.0",
|
|
102
|
+
"react-native-reanimated": ">=4.0.0",
|
|
103
|
+
"react-native-safe-area-context": ">=4.0.0",
|
|
104
|
+
"react-native-worklets": "*"
|
|
105
|
+
},
|
|
106
|
+
"workspaces": [
|
|
107
|
+
"example"
|
|
108
|
+
],
|
|
109
|
+
"packageManager": "yarn@4.18.1",
|
|
110
|
+
"react-native-builder-bob": {
|
|
111
|
+
"source": "src",
|
|
112
|
+
"output": "lib",
|
|
113
|
+
"targets": [
|
|
114
|
+
[
|
|
115
|
+
"module",
|
|
116
|
+
{
|
|
117
|
+
"esm": true
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
"typescript",
|
|
122
|
+
{
|
|
123
|
+
"project": "tsconfig.build.json"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
"prettier": {
|
|
129
|
+
"quoteProps": "consistent",
|
|
130
|
+
"singleQuote": true,
|
|
131
|
+
"tabWidth": 2,
|
|
132
|
+
"trailingComma": "es5",
|
|
133
|
+
"useTabs": false
|
|
134
|
+
},
|
|
135
|
+
"jest": {
|
|
136
|
+
"preset": "@react-native/jest-preset",
|
|
137
|
+
"testEnvironmentOptions": {
|
|
138
|
+
"customExportConditions": [
|
|
139
|
+
"require",
|
|
140
|
+
"react-native",
|
|
141
|
+
"rn-sheet-stack-source"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
"modulePathIgnorePatterns": [
|
|
145
|
+
"<rootDir>/example/node_modules",
|
|
146
|
+
"<rootDir>/lib/"
|
|
147
|
+
],
|
|
148
|
+
"setupFiles": [
|
|
149
|
+
"<rootDir>/jest.setup.js"
|
|
150
|
+
],
|
|
151
|
+
"transformIgnorePatterns": [
|
|
152
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|react-native-reanimated|react-native-worklets|react-native-gesture-handler|react-native-safe-area-context)/)"
|
|
153
|
+
],
|
|
154
|
+
"resolver": "react-native-reanimated/jest/resolver"
|
|
155
|
+
},
|
|
156
|
+
"create-react-native-library": {
|
|
157
|
+
"type": "library",
|
|
158
|
+
"languages": "js",
|
|
159
|
+
"tools": [
|
|
160
|
+
"eslint",
|
|
161
|
+
"jest"
|
|
162
|
+
],
|
|
163
|
+
"version": "0.64.0"
|
|
164
|
+
}
|
|
165
|
+
}
|
package/src/Backdrop.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Pressable, StyleSheet } from 'react-native';
|
|
2
|
+
import Animated, {
|
|
3
|
+
useAnimatedStyle,
|
|
4
|
+
type SharedValue,
|
|
5
|
+
} from 'react-native-reanimated';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
opacity: SharedValue<number>;
|
|
9
|
+
active: boolean;
|
|
10
|
+
onPress: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Backdrop({ opacity, active, onPress }: Props) {
|
|
14
|
+
const style = useAnimatedStyle(() => ({ opacity: opacity.value }));
|
|
15
|
+
return (
|
|
16
|
+
<Animated.View
|
|
17
|
+
style={[StyleSheet.absoluteFill, styles.backdrop, style]}
|
|
18
|
+
pointerEvents={active ? 'auto' : 'none'}
|
|
19
|
+
>
|
|
20
|
+
<Pressable
|
|
21
|
+
style={StyleSheet.absoluteFill}
|
|
22
|
+
onPress={onPress}
|
|
23
|
+
accessibilityRole="button"
|
|
24
|
+
accessibilityLabel="Close sheet"
|
|
25
|
+
/>
|
|
26
|
+
</Animated.View>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const styles = StyleSheet.create({
|
|
31
|
+
backdrop: { backgroundColor: '#000' },
|
|
32
|
+
});
|
package/src/Sheet.tsx
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
View,
|
|
5
|
+
type LayoutChangeEvent,
|
|
6
|
+
type ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import {
|
|
9
|
+
GestureDetector,
|
|
10
|
+
useNativeGesture,
|
|
11
|
+
usePanGesture,
|
|
12
|
+
} from 'react-native-gesture-handler';
|
|
13
|
+
import Animated, {
|
|
14
|
+
Extrapolation,
|
|
15
|
+
ReduceMotion,
|
|
16
|
+
cancelAnimation,
|
|
17
|
+
interpolate,
|
|
18
|
+
runOnJS,
|
|
19
|
+
useAnimatedStyle,
|
|
20
|
+
useSharedValue,
|
|
21
|
+
withSpring,
|
|
22
|
+
type SharedValue,
|
|
23
|
+
} from 'react-native-reanimated';
|
|
24
|
+
import { SheetInstanceContext, type SheetInstance } from './context';
|
|
25
|
+
import type { SheetEntry, SheetId, SheetRenderContext } from './types';
|
|
26
|
+
import { pickSnapTarget, resolveSnapHeights, rubberBand } from './utils/snap';
|
|
27
|
+
|
|
28
|
+
export const HANDLE_HEIGHT = 24;
|
|
29
|
+
const NO_HANDLE_HEIGHT = 8;
|
|
30
|
+
/** Extra background below the sheet so a rubber-band pull never shows a gap. */
|
|
31
|
+
const OVERSHOOT = 160;
|
|
32
|
+
const ACTIVATE_DISTANCE = 6;
|
|
33
|
+
|
|
34
|
+
const OPEN_SPRING = {
|
|
35
|
+
damping: 34,
|
|
36
|
+
stiffness: 340,
|
|
37
|
+
mass: 1,
|
|
38
|
+
reduceMotion: ReduceMotion.System,
|
|
39
|
+
};
|
|
40
|
+
const CLOSE_SPRING = {
|
|
41
|
+
damping: 40,
|
|
42
|
+
stiffness: 420,
|
|
43
|
+
mass: 1,
|
|
44
|
+
overshootClamping: true,
|
|
45
|
+
reduceMotion: ReduceMotion.System,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
interface Props {
|
|
49
|
+
entry: SheetEntry;
|
|
50
|
+
index: number;
|
|
51
|
+
depth: number;
|
|
52
|
+
isTop: boolean;
|
|
53
|
+
containerHeight: number;
|
|
54
|
+
topInset: number;
|
|
55
|
+
bottomInset: number;
|
|
56
|
+
keyboardHeight: SharedValue<number>;
|
|
57
|
+
onClosed: (id: SheetId) => void;
|
|
58
|
+
requestDismiss: (id: SheetId) => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function Sheet({
|
|
62
|
+
entry,
|
|
63
|
+
index,
|
|
64
|
+
depth,
|
|
65
|
+
isTop,
|
|
66
|
+
containerHeight,
|
|
67
|
+
topInset,
|
|
68
|
+
bottomInset,
|
|
69
|
+
keyboardHeight,
|
|
70
|
+
onClosed,
|
|
71
|
+
requestDismiss,
|
|
72
|
+
}: Props) {
|
|
73
|
+
const { options } = entry;
|
|
74
|
+
const handleHeight = options.handle ? HANDLE_HEIGHT : NO_HANDLE_HEIGHT;
|
|
75
|
+
const needsMeasure = options.snapPoints.includes('auto');
|
|
76
|
+
const [contentHeight, setContentHeight] = useState(0);
|
|
77
|
+
const [measured, setMeasured] = useState(!needsMeasure);
|
|
78
|
+
const maxHeight = Math.max(0, containerHeight - topInset);
|
|
79
|
+
|
|
80
|
+
const snapHeights = useMemo(
|
|
81
|
+
() =>
|
|
82
|
+
resolveSnapHeights(
|
|
83
|
+
options.snapPoints,
|
|
84
|
+
containerHeight,
|
|
85
|
+
maxHeight,
|
|
86
|
+
contentHeight + handleHeight + bottomInset
|
|
87
|
+
),
|
|
88
|
+
[
|
|
89
|
+
options.snapPoints,
|
|
90
|
+
containerHeight,
|
|
91
|
+
maxHeight,
|
|
92
|
+
contentHeight,
|
|
93
|
+
handleHeight,
|
|
94
|
+
bottomInset,
|
|
95
|
+
]
|
|
96
|
+
);
|
|
97
|
+
const maxSnapHeight = snapHeights[snapHeights.length - 1] ?? 0;
|
|
98
|
+
const closedY = containerHeight;
|
|
99
|
+
const snapYs = useMemo(
|
|
100
|
+
() => snapHeights.map((h) => containerHeight - h),
|
|
101
|
+
[snapHeights, containerHeight]
|
|
102
|
+
);
|
|
103
|
+
const lowestY = snapYs[0] ?? closedY;
|
|
104
|
+
const topY = snapYs[snapYs.length - 1] ?? closedY;
|
|
105
|
+
const ready = containerHeight > 0 && measured;
|
|
106
|
+
const isOpen = entry.status === 'open';
|
|
107
|
+
|
|
108
|
+
const y = useSharedValue(closedY);
|
|
109
|
+
const depthSv = useSharedValue(depth);
|
|
110
|
+
const dragStartY = useSharedValue(0);
|
|
111
|
+
const moved = useSharedValue(false);
|
|
112
|
+
const dragging = useSharedValue(false);
|
|
113
|
+
const scrollY = useSharedValue(0);
|
|
114
|
+
const hasScroll = useSharedValue(false);
|
|
115
|
+
const snapYsSv = useSharedValue<number[]>(snapYs);
|
|
116
|
+
const topYSv = useSharedValue(topY);
|
|
117
|
+
const lowestYSv = useSharedValue(lowestY);
|
|
118
|
+
const closedYSv = useSharedValue(closedY);
|
|
119
|
+
const dismissibleSv = useSharedValue(options.dismissible);
|
|
120
|
+
const currentSnap = useSharedValue(options.initialSnap);
|
|
121
|
+
const opened = useRef(false);
|
|
122
|
+
const closing = useRef(false);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
snapYsSv.value = snapYs;
|
|
126
|
+
topYSv.value = topY;
|
|
127
|
+
lowestYSv.value = lowestY;
|
|
128
|
+
closedYSv.value = closedY;
|
|
129
|
+
dismissibleSv.value = options.dismissible;
|
|
130
|
+
}, [
|
|
131
|
+
snapYs,
|
|
132
|
+
topY,
|
|
133
|
+
lowestY,
|
|
134
|
+
closedY,
|
|
135
|
+
options.dismissible,
|
|
136
|
+
snapYsSv,
|
|
137
|
+
topYSv,
|
|
138
|
+
lowestYSv,
|
|
139
|
+
closedYSv,
|
|
140
|
+
dismissibleSv,
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
const onSnapRef = useRef(options.onSnap);
|
|
144
|
+
onSnapRef.current = options.onSnap;
|
|
145
|
+
const notifySnap = useCallback((snapIndex: number) => {
|
|
146
|
+
onSnapRef.current?.(snapIndex);
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
// Open on first ready render, then keep the sheet on its snap point if the points change.
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (!ready || !isOpen) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!opened.current) {
|
|
155
|
+
opened.current = true;
|
|
156
|
+
const initial = options.initialSnap;
|
|
157
|
+
currentSnap.value = initial;
|
|
158
|
+
y.value = withSpring(
|
|
159
|
+
snapYs[initial] ?? lowestY,
|
|
160
|
+
OPEN_SPRING,
|
|
161
|
+
(finished) => {
|
|
162
|
+
if (finished) {
|
|
163
|
+
runOnJS(notifySnap)(initial);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (dragging.value) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const snapIndex = Math.min(currentSnap.value, snapYs.length - 1);
|
|
173
|
+
y.value = withSpring(snapYs[snapIndex] ?? lowestY, OPEN_SPRING);
|
|
174
|
+
}, [
|
|
175
|
+
ready,
|
|
176
|
+
isOpen,
|
|
177
|
+
snapYs,
|
|
178
|
+
lowestY,
|
|
179
|
+
options.initialSnap,
|
|
180
|
+
y,
|
|
181
|
+
currentSnap,
|
|
182
|
+
dragging,
|
|
183
|
+
notifySnap,
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
// Close when the provider marks the entry as closing.
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (isOpen || closing.current) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
closing.current = true;
|
|
192
|
+
const finish = () => {
|
|
193
|
+
onClosed(entry.id);
|
|
194
|
+
options.onDismiss?.();
|
|
195
|
+
};
|
|
196
|
+
y.value = withSpring(closedY, CLOSE_SPRING, () => {
|
|
197
|
+
runOnJS(finish)();
|
|
198
|
+
});
|
|
199
|
+
}, [isOpen, closedY, entry.id, options, onClosed, y]);
|
|
200
|
+
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
depthSv.value = withSpring(depth, OPEN_SPRING);
|
|
203
|
+
}, [depth, depthSv]);
|
|
204
|
+
|
|
205
|
+
const scrollGesture = useNativeGesture();
|
|
206
|
+
|
|
207
|
+
const pan = usePanGesture({
|
|
208
|
+
enabled: ready && isOpen,
|
|
209
|
+
activeOffsetY: [-ACTIVATE_DISTANCE, ACTIVATE_DISTANCE],
|
|
210
|
+
simultaneousWith: scrollGesture,
|
|
211
|
+
onBegin: () => {
|
|
212
|
+
'worklet';
|
|
213
|
+
cancelAnimation(y);
|
|
214
|
+
dragStartY.value = y.value;
|
|
215
|
+
moved.value = false;
|
|
216
|
+
dragging.value = true;
|
|
217
|
+
},
|
|
218
|
+
onUpdate: (e) => {
|
|
219
|
+
'worklet';
|
|
220
|
+
// The scroll view owns the gesture while it has content scrolled away from the top.
|
|
221
|
+
if (hasScroll.value && !moved.value && scrollY.value > 0.5) {
|
|
222
|
+
dragStartY.value = y.value - e.translationY;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let next = dragStartY.value + e.translationY;
|
|
226
|
+
if (next < topYSv.value) {
|
|
227
|
+
if (hasScroll.value && !moved.value) {
|
|
228
|
+
// At the top with a scroll view: an upward drag scrolls content instead.
|
|
229
|
+
dragStartY.value = y.value - e.translationY;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
next = topYSv.value - rubberBand(topYSv.value - next, containerHeight);
|
|
233
|
+
}
|
|
234
|
+
if (!dismissibleSv.value && next > lowestYSv.value) {
|
|
235
|
+
next =
|
|
236
|
+
lowestYSv.value +
|
|
237
|
+
rubberBand(next - lowestYSv.value, containerHeight, 0.3);
|
|
238
|
+
}
|
|
239
|
+
if (Math.abs(next - y.value) > 0.01) {
|
|
240
|
+
moved.value = true;
|
|
241
|
+
}
|
|
242
|
+
y.value = next;
|
|
243
|
+
},
|
|
244
|
+
onDeactivate: (e) => {
|
|
245
|
+
'worklet';
|
|
246
|
+
dragging.value = false;
|
|
247
|
+
if (!moved.value) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const target = pickSnapTarget({
|
|
251
|
+
y: y.value,
|
|
252
|
+
velocityY: e.velocityY,
|
|
253
|
+
snapYs: snapYsSv.value,
|
|
254
|
+
closedY: closedYSv.value,
|
|
255
|
+
dismissible: dismissibleSv.value,
|
|
256
|
+
});
|
|
257
|
+
if (target.index === -1) {
|
|
258
|
+
y.value = withSpring(closedYSv.value, CLOSE_SPRING);
|
|
259
|
+
runOnJS(requestDismiss)(entry.id);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
currentSnap.value = target.index;
|
|
263
|
+
y.value = withSpring(
|
|
264
|
+
target.y,
|
|
265
|
+
{ ...OPEN_SPRING, velocity: e.velocityY },
|
|
266
|
+
(finished) => {
|
|
267
|
+
if (finished) {
|
|
268
|
+
runOnJS(notifySnap)(target.index);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
},
|
|
273
|
+
onFinalize: () => {
|
|
274
|
+
'worklet';
|
|
275
|
+
dragging.value = false;
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const keyboardPadding = options.keyboardBehavior === 'padding';
|
|
280
|
+
const { stackOffset, stackScale } = options;
|
|
281
|
+
|
|
282
|
+
const sheetStyle = useAnimatedStyle(() => {
|
|
283
|
+
const d = depthSv.value;
|
|
284
|
+
const progress = interpolate(
|
|
285
|
+
y.value,
|
|
286
|
+
[closedY, lowestY],
|
|
287
|
+
[0, 1],
|
|
288
|
+
Extrapolation.CLAMP
|
|
289
|
+
);
|
|
290
|
+
const lift = keyboardPadding ? keyboardHeight.value * progress : 0;
|
|
291
|
+
const base = Math.max(topInset, y.value - lift);
|
|
292
|
+
return {
|
|
293
|
+
height: maxSnapHeight + OVERSHOOT,
|
|
294
|
+
opacity: d > 2.5 ? 0 : 1,
|
|
295
|
+
transform: [
|
|
296
|
+
{ translateY: base - stackOffset * d },
|
|
297
|
+
{ scale: Math.pow(stackScale, d) },
|
|
298
|
+
],
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const dimStyle = useAnimatedStyle(() => ({
|
|
303
|
+
opacity: interpolate(
|
|
304
|
+
depthSv.value,
|
|
305
|
+
[0, 1, 2],
|
|
306
|
+
[0, 0.18, 0.3],
|
|
307
|
+
Extrapolation.CLAMP
|
|
308
|
+
),
|
|
309
|
+
}));
|
|
310
|
+
|
|
311
|
+
const onContentLayout = useCallback((e: LayoutChangeEvent) => {
|
|
312
|
+
const h = Math.round(e.nativeEvent.layout.height);
|
|
313
|
+
setContentHeight((prev) => (prev === h ? prev : h));
|
|
314
|
+
setMeasured(true);
|
|
315
|
+
}, []);
|
|
316
|
+
|
|
317
|
+
const contentStyle: ViewStyle = needsMeasure
|
|
318
|
+
? { maxHeight: Math.max(0, maxHeight - handleHeight - bottomInset) }
|
|
319
|
+
: { height: Math.max(0, maxSnapHeight - handleHeight - bottomInset) };
|
|
320
|
+
|
|
321
|
+
const renderContext = useMemo<SheetRenderContext>(
|
|
322
|
+
() => ({
|
|
323
|
+
id: entry.id,
|
|
324
|
+
index,
|
|
325
|
+
isTop,
|
|
326
|
+
dismiss: () => requestDismiss(entry.id),
|
|
327
|
+
}),
|
|
328
|
+
[entry.id, index, isTop, requestDismiss]
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const instance = useMemo<SheetInstance>(
|
|
332
|
+
() => ({
|
|
333
|
+
...renderContext,
|
|
334
|
+
y,
|
|
335
|
+
topY: topYSv,
|
|
336
|
+
scrollY,
|
|
337
|
+
hasScroll,
|
|
338
|
+
scrollGesture,
|
|
339
|
+
}),
|
|
340
|
+
[renderContext, y, topYSv, scrollY, hasScroll, scrollGesture]
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<SheetInstanceContext.Provider value={instance}>
|
|
345
|
+
<GestureDetector gesture={pan}>
|
|
346
|
+
<Animated.View
|
|
347
|
+
style={[
|
|
348
|
+
styles.sheet,
|
|
349
|
+
{ paddingBottom: bottomInset + OVERSHOOT },
|
|
350
|
+
options.style,
|
|
351
|
+
sheetStyle,
|
|
352
|
+
]}
|
|
353
|
+
accessibilityViewIsModal={isTop}
|
|
354
|
+
importantForAccessibility={isTop ? 'yes' : 'no-hide-descendants'}
|
|
355
|
+
>
|
|
356
|
+
{options.handle ? (
|
|
357
|
+
<View style={styles.handleRow}>
|
|
358
|
+
<View style={styles.handle} />
|
|
359
|
+
</View>
|
|
360
|
+
) : (
|
|
361
|
+
<View style={styles.noHandle} />
|
|
362
|
+
)}
|
|
363
|
+
<View
|
|
364
|
+
style={contentStyle}
|
|
365
|
+
onLayout={needsMeasure ? onContentLayout : undefined}
|
|
366
|
+
>
|
|
367
|
+
{options.render(renderContext)}
|
|
368
|
+
</View>
|
|
369
|
+
<Animated.View
|
|
370
|
+
pointerEvents="none"
|
|
371
|
+
style={[StyleSheet.absoluteFill, styles.dim, dimStyle]}
|
|
372
|
+
/>
|
|
373
|
+
</Animated.View>
|
|
374
|
+
</GestureDetector>
|
|
375
|
+
</SheetInstanceContext.Provider>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const styles = StyleSheet.create({
|
|
380
|
+
sheet: {
|
|
381
|
+
position: 'absolute',
|
|
382
|
+
left: 0,
|
|
383
|
+
right: 0,
|
|
384
|
+
top: 0,
|
|
385
|
+
backgroundColor: '#ffffff',
|
|
386
|
+
borderTopLeftRadius: 24,
|
|
387
|
+
borderTopRightRadius: 24,
|
|
388
|
+
overflow: 'hidden',
|
|
389
|
+
transformOrigin: 'top center',
|
|
390
|
+
},
|
|
391
|
+
handleRow: {
|
|
392
|
+
height: HANDLE_HEIGHT,
|
|
393
|
+
alignItems: 'center',
|
|
394
|
+
justifyContent: 'center',
|
|
395
|
+
},
|
|
396
|
+
handle: {
|
|
397
|
+
width: 36,
|
|
398
|
+
height: 5,
|
|
399
|
+
borderRadius: 3,
|
|
400
|
+
backgroundColor: 'rgba(0,0,0,0.2)',
|
|
401
|
+
},
|
|
402
|
+
noHandle: { height: NO_HANDLE_HEIGHT },
|
|
403
|
+
dim: { backgroundColor: '#000' },
|
|
404
|
+
});
|