@tamagui/sheet 1.14.0 → 1.14.2
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/dist/cjs/Sheet.js +659 -1
- package/dist/cjs/Sheet.js.map +2 -2
- package/dist/cjs/SheetContext.js +40 -1
- package/dist/cjs/SheetContext.js.map +2 -2
- package/dist/cjs/SheetScrollView.js +104 -1
- package/dist/cjs/SheetScrollView.js.map +2 -2
- package/dist/cjs/constants.js +34 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/esm/Sheet.js +643 -1
- package/dist/esm/Sheet.js.map +2 -2
- package/dist/esm/Sheet.mjs +643 -1
- package/dist/esm/Sheet.mjs.map +2 -2
- package/dist/esm/SheetContext.js +13 -1
- package/dist/esm/SheetContext.js.map +2 -2
- package/dist/esm/SheetContext.mjs +13 -1
- package/dist/esm/SheetContext.mjs.map +2 -2
- package/dist/esm/SheetScrollView.js +80 -1
- package/dist/esm/SheetScrollView.js.map +2 -2
- package/dist/esm/SheetScrollView.mjs +80 -1
- package/dist/esm/SheetScrollView.mjs.map +2 -2
- package/dist/esm/constants.js +8 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +8 -1
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Sheet.js +621 -1
- package/dist/jsx/Sheet.js.map +2 -2
- package/dist/jsx/Sheet.mjs +621 -1
- package/dist/jsx/Sheet.mjs.map +2 -2
- package/dist/jsx/SheetContext.js +13 -1
- package/dist/jsx/SheetContext.js.map +2 -2
- package/dist/jsx/SheetContext.mjs +13 -1
- package/dist/jsx/SheetContext.mjs.map +2 -2
- package/dist/jsx/SheetScrollView.js +75 -1
- package/dist/jsx/SheetScrollView.js.map +2 -2
- package/dist/jsx/SheetScrollView.mjs +75 -1
- package/dist/jsx/SheetScrollView.mjs.map +2 -2
- package/dist/jsx/constants.js +8 -1
- package/dist/jsx/constants.js.map +2 -2
- package/dist/jsx/constants.mjs +8 -1
- package/dist/jsx/constants.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/jsx/Sheet.mjs
CHANGED
|
@@ -1,2 +1,622 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AdaptParentContext } from "@tamagui/adapt";
|
|
2
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
+
import {
|
|
4
|
+
Theme,
|
|
5
|
+
isClient,
|
|
6
|
+
isTouchable,
|
|
7
|
+
isWeb,
|
|
8
|
+
mergeEvent,
|
|
9
|
+
styled,
|
|
10
|
+
themeable,
|
|
11
|
+
useAnimationDriver,
|
|
12
|
+
useDidFinishSSR,
|
|
13
|
+
useEvent,
|
|
14
|
+
useIsomorphicLayoutEffect,
|
|
15
|
+
useThemeName,
|
|
16
|
+
withStaticProperties
|
|
17
|
+
} from "@tamagui/core";
|
|
18
|
+
import { Portal } from "@tamagui/portal";
|
|
19
|
+
import { RemoveScroll } from "@tamagui/remove-scroll";
|
|
20
|
+
import { ThemeableStack, XStack, YStack } from "@tamagui/stacks";
|
|
21
|
+
import { useConstant } from "@tamagui/use-constant";
|
|
22
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
23
|
+
import { useKeyboardVisible } from "@tamagui/use-keyboard-visible";
|
|
24
|
+
import React, {
|
|
25
|
+
createContext,
|
|
26
|
+
forwardRef,
|
|
27
|
+
isValidElement,
|
|
28
|
+
useCallback,
|
|
29
|
+
useContext,
|
|
30
|
+
useEffect,
|
|
31
|
+
useMemo,
|
|
32
|
+
useRef,
|
|
33
|
+
useState
|
|
34
|
+
} from "react";
|
|
35
|
+
import {
|
|
36
|
+
Keyboard,
|
|
37
|
+
PanResponder
|
|
38
|
+
} from "react-native";
|
|
39
|
+
import { SHEET_HANDLE_NAME, SHEET_NAME } from "./constants";
|
|
40
|
+
import { SheetProvider, useSheetContext } from "./SheetContext";
|
|
41
|
+
import { SheetScrollView } from "./SheetScrollView";
|
|
42
|
+
import { createSheetScope } from "./SheetContext";
|
|
43
|
+
const SheetHandleFrame = styled(XStack, {
|
|
44
|
+
name: SHEET_HANDLE_NAME,
|
|
45
|
+
height: 10,
|
|
46
|
+
borderRadius: 100,
|
|
47
|
+
backgroundColor: "$background",
|
|
48
|
+
zIndex: 10,
|
|
49
|
+
marginHorizontal: "35%",
|
|
50
|
+
marginBottom: "$2",
|
|
51
|
+
opacity: 0.5,
|
|
52
|
+
hoverStyle: {
|
|
53
|
+
opacity: 0.7
|
|
54
|
+
},
|
|
55
|
+
variants: {
|
|
56
|
+
open: {
|
|
57
|
+
true: {
|
|
58
|
+
pointerEvents: "auto"
|
|
59
|
+
},
|
|
60
|
+
false: {
|
|
61
|
+
opacity: 0,
|
|
62
|
+
pointerEvents: "none"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const SheetHandle = SheetHandleFrame.extractable(
|
|
68
|
+
({ __scopeSheet, ...props }) => {
|
|
69
|
+
const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet);
|
|
70
|
+
return <SheetHandleFrame
|
|
71
|
+
onPress={() => {
|
|
72
|
+
const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0);
|
|
73
|
+
const nextPos = (context.position + 1) % max;
|
|
74
|
+
context.setPosition(nextPos);
|
|
75
|
+
}}
|
|
76
|
+
open={context.open}
|
|
77
|
+
{...props}
|
|
78
|
+
/>;
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
const SHEET_OVERLAY_NAME = "SheetOverlay";
|
|
82
|
+
const SheetOverlayFrame = styled(ThemeableStack, {
|
|
83
|
+
name: SHEET_OVERLAY_NAME,
|
|
84
|
+
fullscreen: true,
|
|
85
|
+
backgrounded: true,
|
|
86
|
+
opacity: 0.5,
|
|
87
|
+
zIndex: 0,
|
|
88
|
+
variants: {
|
|
89
|
+
closed: {
|
|
90
|
+
true: {
|
|
91
|
+
opacity: 0,
|
|
92
|
+
pointerEvents: "none"
|
|
93
|
+
},
|
|
94
|
+
false: {
|
|
95
|
+
pointerEvents: "auto"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const SheetOverlay = SheetOverlayFrame.extractable(
|
|
101
|
+
({ __scopeSheet, ...props }) => {
|
|
102
|
+
const context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet);
|
|
103
|
+
return <SheetOverlayFrame
|
|
104
|
+
closed={!context.open || context.hidden}
|
|
105
|
+
{...props}
|
|
106
|
+
onPress={mergeEvent(
|
|
107
|
+
props.onPress,
|
|
108
|
+
context.dismissOnOverlayPress ? () => {
|
|
109
|
+
context.setOpen(false);
|
|
110
|
+
} : void 0
|
|
111
|
+
)}
|
|
112
|
+
/>;
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
const selectionStyleSheet = isClient ? document.createElement("style") : null;
|
|
116
|
+
if (selectionStyleSheet) {
|
|
117
|
+
document.head.appendChild(selectionStyleSheet);
|
|
118
|
+
}
|
|
119
|
+
const SheetFrameFrame = styled(YStack, {
|
|
120
|
+
name: SHEET_NAME,
|
|
121
|
+
flex: 1,
|
|
122
|
+
backgroundColor: "$background",
|
|
123
|
+
borderTopLeftRadius: "$true",
|
|
124
|
+
borderTopRightRadius: "$true",
|
|
125
|
+
width: "100%",
|
|
126
|
+
maxHeight: "100%",
|
|
127
|
+
overflow: "hidden",
|
|
128
|
+
pointerEvents: "auto"
|
|
129
|
+
});
|
|
130
|
+
const SheetFrame = SheetFrameFrame.extractable(
|
|
131
|
+
forwardRef(
|
|
132
|
+
({ __scopeSheet, ...props }, forwardedRef) => {
|
|
133
|
+
const context = useSheetContext(SHEET_NAME, __scopeSheet);
|
|
134
|
+
const composedContentRef = useComposedRefs(forwardedRef, context.contentRef);
|
|
135
|
+
return <SheetFrameFrame ref={composedContentRef} {...props} />;
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
const HIDDEN_SIZE = 1e4;
|
|
140
|
+
const sheetComponents = {
|
|
141
|
+
Handle: SheetHandle,
|
|
142
|
+
Frame: SheetFrame,
|
|
143
|
+
Overlay: SheetOverlay,
|
|
144
|
+
ScrollView: SheetScrollView
|
|
145
|
+
};
|
|
146
|
+
const ParentSheetContext = createContext({
|
|
147
|
+
zIndex: 40
|
|
148
|
+
});
|
|
149
|
+
const useSheetContoller = () => {
|
|
150
|
+
const controller = useContext(SheetControllerContext);
|
|
151
|
+
const isHidden = controller?.hidden;
|
|
152
|
+
const isShowingNonSheet = isHidden && controller?.open;
|
|
153
|
+
return {
|
|
154
|
+
controller,
|
|
155
|
+
isHidden,
|
|
156
|
+
isShowingNonSheet
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const Sheet = withStaticProperties(
|
|
160
|
+
forwardRef(function Sheet2(props, ref) {
|
|
161
|
+
const hydrated = useDidFinishSSR();
|
|
162
|
+
const { isShowingNonSheet } = useSheetContoller();
|
|
163
|
+
if (isShowingNonSheet || !hydrated) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return <SheetImplementation ref={ref} {...props} />;
|
|
167
|
+
}),
|
|
168
|
+
sheetComponents
|
|
169
|
+
);
|
|
170
|
+
const SheetImplementation = themeable(
|
|
171
|
+
forwardRef(function SheetImplementation2(props, forwardedRef) {
|
|
172
|
+
const parentSheet = useContext(ParentSheetContext);
|
|
173
|
+
const { isHidden, controller } = useSheetContoller();
|
|
174
|
+
const {
|
|
175
|
+
__scopeSheet,
|
|
176
|
+
snapPoints: snapPointsProp = [80],
|
|
177
|
+
open: openProp,
|
|
178
|
+
defaultOpen,
|
|
179
|
+
children: childrenProp,
|
|
180
|
+
position: positionProp,
|
|
181
|
+
onPositionChange,
|
|
182
|
+
onOpenChange,
|
|
183
|
+
defaultPosition,
|
|
184
|
+
dismissOnOverlayPress = true,
|
|
185
|
+
animationConfig,
|
|
186
|
+
dismissOnSnapToBottom = false,
|
|
187
|
+
forceRemoveScrollEnabled = null,
|
|
188
|
+
disableDrag: disableDragProp,
|
|
189
|
+
modal = false,
|
|
190
|
+
zIndex = parentSheet.zIndex + 1,
|
|
191
|
+
moveOnKeyboardChange = false,
|
|
192
|
+
portalProps
|
|
193
|
+
} = props;
|
|
194
|
+
if (process.env.NODE_ENV === "development") {
|
|
195
|
+
if (snapPointsProp.some((p) => p < 0 || p > 100)) {
|
|
196
|
+
console.warn(
|
|
197
|
+
"\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame"
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const sheetRef = useRef(null);
|
|
202
|
+
const ref = useComposedRefs(forwardedRef, sheetRef);
|
|
203
|
+
const driver = useAnimationDriver();
|
|
204
|
+
if (!driver) {
|
|
205
|
+
throw new Error("Must set animations in tamagui.config.ts");
|
|
206
|
+
}
|
|
207
|
+
const disableDrag = disableDragProp ?? controller?.disableDrag;
|
|
208
|
+
const keyboardIsVisible = useKeyboardVisible();
|
|
209
|
+
const themeName = useThemeName();
|
|
210
|
+
const contentRef = React.useRef(null);
|
|
211
|
+
const scrollBridge = useConstant(() => ({
|
|
212
|
+
enabled: false,
|
|
213
|
+
y: 0,
|
|
214
|
+
paneY: 0,
|
|
215
|
+
paneMinY: 0,
|
|
216
|
+
scrollStartY: -1,
|
|
217
|
+
drag: () => {
|
|
218
|
+
},
|
|
219
|
+
release: () => {
|
|
220
|
+
},
|
|
221
|
+
scrollLock: false
|
|
222
|
+
}));
|
|
223
|
+
const onOpenChangeInternal = (val) => {
|
|
224
|
+
controller?.onOpenChange?.(val);
|
|
225
|
+
onOpenChange?.(val);
|
|
226
|
+
};
|
|
227
|
+
const [open, setOpen] = useControllableState({
|
|
228
|
+
prop: controller?.open ?? openProp,
|
|
229
|
+
defaultProp: true,
|
|
230
|
+
onChange: onOpenChangeInternal,
|
|
231
|
+
strategy: "most-recent-wins",
|
|
232
|
+
transition: true
|
|
233
|
+
});
|
|
234
|
+
const [frameSize, setFrameSize] = useState(0);
|
|
235
|
+
const snapPoints = useMemo(
|
|
236
|
+
() => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp,
|
|
237
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
238
|
+
[JSON.stringify(snapPointsProp), dismissOnSnapToBottom]
|
|
239
|
+
);
|
|
240
|
+
const [position_, setPosition_] = useControllableState({
|
|
241
|
+
prop: positionProp,
|
|
242
|
+
defaultProp: defaultPosition || (open ? 0 : -1),
|
|
243
|
+
onChange: onPositionChange,
|
|
244
|
+
strategy: "most-recent-wins",
|
|
245
|
+
transition: true
|
|
246
|
+
});
|
|
247
|
+
const position = open === false ? -1 : position_;
|
|
248
|
+
if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
|
|
249
|
+
setPosition_(0);
|
|
250
|
+
}
|
|
251
|
+
const setPosition = useCallback(
|
|
252
|
+
(next) => {
|
|
253
|
+
if (dismissOnSnapToBottom && next === snapPoints.length - 1) {
|
|
254
|
+
setOpen(false);
|
|
255
|
+
} else {
|
|
256
|
+
setPosition_(next);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
[dismissOnSnapToBottom, snapPoints.length, setPosition_, setOpen]
|
|
260
|
+
);
|
|
261
|
+
const { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle } = driver;
|
|
262
|
+
const animatedNumber = useAnimatedNumber(HIDDEN_SIZE);
|
|
263
|
+
const at = useRef(0);
|
|
264
|
+
useAnimatedNumberReaction(
|
|
265
|
+
{
|
|
266
|
+
value: animatedNumber,
|
|
267
|
+
hostRef: sheetRef
|
|
268
|
+
},
|
|
269
|
+
(value) => {
|
|
270
|
+
if (!driver.isReactNative)
|
|
271
|
+
return;
|
|
272
|
+
at.current = value;
|
|
273
|
+
scrollBridge.paneY = value;
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
function stopSpring() {
|
|
277
|
+
animatedNumber.stop();
|
|
278
|
+
if (scrollBridge.onFinishAnimate) {
|
|
279
|
+
scrollBridge.onFinishAnimate();
|
|
280
|
+
scrollBridge.onFinishAnimate = void 0;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const shouldSetPositionOpen = open && position < 0;
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (shouldSetPositionOpen) {
|
|
286
|
+
setPosition(0);
|
|
287
|
+
}
|
|
288
|
+
}, [setPosition, shouldSetPositionOpen]);
|
|
289
|
+
const positions = useMemo(
|
|
290
|
+
() => snapPoints.map((point) => getPercentSize(point, frameSize)),
|
|
291
|
+
[frameSize, snapPoints]
|
|
292
|
+
);
|
|
293
|
+
const [opacity, setOpacity] = useState(open ? 1 : 0);
|
|
294
|
+
if (open && opacity === 0) {
|
|
295
|
+
setOpacity(1);
|
|
296
|
+
}
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
if (!open) {
|
|
299
|
+
const tm = setTimeout(() => {
|
|
300
|
+
setOpacity(0);
|
|
301
|
+
}, 400);
|
|
302
|
+
return () => {
|
|
303
|
+
clearTimeout(tm);
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}, [open]);
|
|
307
|
+
const animateTo = useEvent((position2) => {
|
|
308
|
+
const current = animatedNumber.getValue();
|
|
309
|
+
if (isHidden && open)
|
|
310
|
+
return;
|
|
311
|
+
if (!current)
|
|
312
|
+
return;
|
|
313
|
+
if (frameSize === 0)
|
|
314
|
+
return;
|
|
315
|
+
const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : frameSize;
|
|
316
|
+
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
317
|
+
if (at.current === toValue)
|
|
318
|
+
return;
|
|
319
|
+
stopSpring();
|
|
320
|
+
if (isHidden) {
|
|
321
|
+
animatedNumber.setValue(toValue, {
|
|
322
|
+
type: "timing",
|
|
323
|
+
duration: 0
|
|
324
|
+
});
|
|
325
|
+
at.current = toValue;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const overshootClamping = at.current === HIDDEN_SIZE;
|
|
329
|
+
animatedNumber.setValue(toValue, {
|
|
330
|
+
...animationConfig,
|
|
331
|
+
type: "spring",
|
|
332
|
+
overshootClamping
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
useIsomorphicLayoutEffect(() => {
|
|
336
|
+
animateTo(position);
|
|
337
|
+
}, [isHidden, frameSize, position, animateTo]);
|
|
338
|
+
const [isShowingInnerSheet, setIsShowingInnerSheet] = useState(false);
|
|
339
|
+
const shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet;
|
|
340
|
+
const parentSheetContext = useContext(SheetInsideSheetContext);
|
|
341
|
+
const onInnerSheet = useCallback((hasChild) => {
|
|
342
|
+
setIsShowingInnerSheet(hasChild);
|
|
343
|
+
}, []);
|
|
344
|
+
const panResponder = useMemo(
|
|
345
|
+
() => {
|
|
346
|
+
if (disableDrag)
|
|
347
|
+
return;
|
|
348
|
+
if (!frameSize)
|
|
349
|
+
return;
|
|
350
|
+
if (isShowingInnerSheet)
|
|
351
|
+
return;
|
|
352
|
+
const minY = positions[0];
|
|
353
|
+
scrollBridge.paneMinY = minY;
|
|
354
|
+
let startY = at.current;
|
|
355
|
+
function makeUnselectable(val) {
|
|
356
|
+
if (!selectionStyleSheet)
|
|
357
|
+
return;
|
|
358
|
+
if (!val) {
|
|
359
|
+
selectionStyleSheet.innerText = "";
|
|
360
|
+
} else {
|
|
361
|
+
selectionStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }";
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const release = ({ vy, dragAt }) => {
|
|
365
|
+
isExternalDrag = false;
|
|
366
|
+
previouslyScrolling = false;
|
|
367
|
+
makeUnselectable(false);
|
|
368
|
+
const at2 = dragAt + startY;
|
|
369
|
+
const end = at2 + frameSize * vy * 0.2;
|
|
370
|
+
let closestPoint = 0;
|
|
371
|
+
let dist = Infinity;
|
|
372
|
+
for (let i = 0; i < positions.length; i++) {
|
|
373
|
+
const position2 = positions[i];
|
|
374
|
+
const curDist = end > position2 ? end - position2 : position2 - end;
|
|
375
|
+
if (curDist < dist) {
|
|
376
|
+
dist = curDist;
|
|
377
|
+
closestPoint = i;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
setPosition(closestPoint);
|
|
381
|
+
animateTo(closestPoint);
|
|
382
|
+
};
|
|
383
|
+
const finish = (_e, state) => {
|
|
384
|
+
release({
|
|
385
|
+
vy: state.vy,
|
|
386
|
+
dragAt: state.dy
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
let previouslyScrolling = false;
|
|
390
|
+
const onMoveShouldSet = (_e, { dy }) => {
|
|
391
|
+
const isScrolled = scrollBridge.y !== 0;
|
|
392
|
+
const isDraggingUp = dy < 0;
|
|
393
|
+
const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
|
|
394
|
+
if (isScrolled) {
|
|
395
|
+
previouslyScrolling = true;
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
if (isNearTop) {
|
|
399
|
+
if (!isScrolled && isDraggingUp) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return Math.abs(dy) > 5;
|
|
404
|
+
};
|
|
405
|
+
const grant = () => {
|
|
406
|
+
makeUnselectable(true);
|
|
407
|
+
stopSpring();
|
|
408
|
+
startY = at.current;
|
|
409
|
+
};
|
|
410
|
+
let isExternalDrag = false;
|
|
411
|
+
scrollBridge.drag = (dy) => {
|
|
412
|
+
if (!isExternalDrag) {
|
|
413
|
+
isExternalDrag = true;
|
|
414
|
+
grant();
|
|
415
|
+
}
|
|
416
|
+
const to = dy + startY;
|
|
417
|
+
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
418
|
+
};
|
|
419
|
+
scrollBridge.release = release;
|
|
420
|
+
return PanResponder.create({
|
|
421
|
+
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
422
|
+
onPanResponderGrant: grant,
|
|
423
|
+
onPanResponderMove: (_e, { dy }) => {
|
|
424
|
+
const toFull = dy + startY;
|
|
425
|
+
const to = resisted(toFull, minY);
|
|
426
|
+
animatedNumber.setValue(to, { type: "direct" });
|
|
427
|
+
},
|
|
428
|
+
onPanResponderEnd: finish,
|
|
429
|
+
onPanResponderTerminate: finish,
|
|
430
|
+
onPanResponderRelease: finish
|
|
431
|
+
});
|
|
432
|
+
},
|
|
433
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
434
|
+
[disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]
|
|
435
|
+
);
|
|
436
|
+
let handleComponent = null;
|
|
437
|
+
let overlayComponent = null;
|
|
438
|
+
let frameComponent = null;
|
|
439
|
+
React.Children.forEach(childrenProp, (child) => {
|
|
440
|
+
if (isValidElement(child)) {
|
|
441
|
+
const name = child.type?.["staticConfig"]?.componentName;
|
|
442
|
+
switch (name) {
|
|
443
|
+
case "SheetHandle":
|
|
444
|
+
handleComponent = child;
|
|
445
|
+
break;
|
|
446
|
+
case "Sheet":
|
|
447
|
+
frameComponent = child;
|
|
448
|
+
break;
|
|
449
|
+
case "SheetOverlay":
|
|
450
|
+
overlayComponent = child;
|
|
451
|
+
break;
|
|
452
|
+
default:
|
|
453
|
+
console.warn("Warning: passed invalid child to Sheet", child);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
const animatedStyle = useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
458
|
+
const translateY = frameSize === 0 ? HIDDEN_SIZE : val;
|
|
459
|
+
return {
|
|
460
|
+
transform: [{ translateY }]
|
|
461
|
+
};
|
|
462
|
+
});
|
|
463
|
+
const sizeBeforeKeyboard = useRef(null);
|
|
464
|
+
useEffect(() => {
|
|
465
|
+
if (isWeb || !moveOnKeyboardChange)
|
|
466
|
+
return;
|
|
467
|
+
const keyboardDidShowListener = Keyboard.addListener("keyboardDidShow", (e) => {
|
|
468
|
+
if (sizeBeforeKeyboard.current !== null)
|
|
469
|
+
return;
|
|
470
|
+
sizeBeforeKeyboard.current = animatedNumber.getValue();
|
|
471
|
+
animatedNumber.setValue(
|
|
472
|
+
Math.max(animatedNumber.getValue() - e.endCoordinates.height, 0)
|
|
473
|
+
);
|
|
474
|
+
});
|
|
475
|
+
const keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", () => {
|
|
476
|
+
if (sizeBeforeKeyboard.current === null)
|
|
477
|
+
return;
|
|
478
|
+
animatedNumber.setValue(sizeBeforeKeyboard.current);
|
|
479
|
+
sizeBeforeKeyboard.current = null;
|
|
480
|
+
});
|
|
481
|
+
return () => {
|
|
482
|
+
keyboardDidHideListener.remove();
|
|
483
|
+
keyboardDidShowListener.remove();
|
|
484
|
+
};
|
|
485
|
+
}, []);
|
|
486
|
+
const AnimatedView = driver["NumberView"] ?? driver.View;
|
|
487
|
+
useIsomorphicLayoutEffect(() => {
|
|
488
|
+
if (!(parentSheetContext && open))
|
|
489
|
+
return;
|
|
490
|
+
parentSheetContext(true);
|
|
491
|
+
return () => {
|
|
492
|
+
parentSheetContext(false);
|
|
493
|
+
};
|
|
494
|
+
}, [parentSheetContext, open]);
|
|
495
|
+
const nextParentContext = useMemo(
|
|
496
|
+
() => ({
|
|
497
|
+
zIndex
|
|
498
|
+
}),
|
|
499
|
+
[zIndex]
|
|
500
|
+
);
|
|
501
|
+
const handleLayout = useCallback(
|
|
502
|
+
(e) => {
|
|
503
|
+
let next = e.nativeEvent?.layout.height;
|
|
504
|
+
if (isWeb && isTouchable && !open) {
|
|
505
|
+
next += 100;
|
|
506
|
+
}
|
|
507
|
+
if (!next)
|
|
508
|
+
return;
|
|
509
|
+
setFrameSize(() => next);
|
|
510
|
+
},
|
|
511
|
+
[keyboardIsVisible]
|
|
512
|
+
);
|
|
513
|
+
const removeScrollEnabled = forceRemoveScrollEnabled ?? (open && modal);
|
|
514
|
+
const contents = <ParentSheetContext.Provider value={nextParentContext}><SheetProvider
|
|
515
|
+
modal={modal}
|
|
516
|
+
contentRef={contentRef}
|
|
517
|
+
frameSize={frameSize}
|
|
518
|
+
dismissOnOverlayPress={dismissOnOverlayPress}
|
|
519
|
+
dismissOnSnapToBottom={dismissOnSnapToBottom}
|
|
520
|
+
open={open}
|
|
521
|
+
hidden={!!isHidden}
|
|
522
|
+
scope={__scopeSheet}
|
|
523
|
+
position={position}
|
|
524
|
+
snapPoints={snapPoints}
|
|
525
|
+
setPosition={setPosition}
|
|
526
|
+
setOpen={setOpen}
|
|
527
|
+
scrollBridge={scrollBridge}
|
|
528
|
+
>
|
|
529
|
+
{shouldHideParentSheet ? null : overlayComponent}
|
|
530
|
+
<AnimatedView
|
|
531
|
+
ref={ref}
|
|
532
|
+
{...panResponder?.panHandlers}
|
|
533
|
+
onLayout={handleLayout}
|
|
534
|
+
pointerEvents={open && !shouldHideParentSheet ? "auto" : "none"}
|
|
535
|
+
animation={props.animation}
|
|
536
|
+
style={[
|
|
537
|
+
{
|
|
538
|
+
position: "absolute",
|
|
539
|
+
zIndex,
|
|
540
|
+
width: "100%",
|
|
541
|
+
height: "100%",
|
|
542
|
+
opacity
|
|
543
|
+
},
|
|
544
|
+
animatedStyle
|
|
545
|
+
]}
|
|
546
|
+
>
|
|
547
|
+
{handleComponent}
|
|
548
|
+
<RemoveScroll
|
|
549
|
+
forwardProps
|
|
550
|
+
enabled={removeScrollEnabled}
|
|
551
|
+
allowPinchZoom
|
|
552
|
+
shards={[contentRef]}
|
|
553
|
+
removeScrollBar={false}
|
|
554
|
+
>{frameComponent}</RemoveScroll>
|
|
555
|
+
</AnimatedView>
|
|
556
|
+
</SheetProvider></ParentSheetContext.Provider>;
|
|
557
|
+
const adaptContext = useContext(AdaptParentContext);
|
|
558
|
+
if (modal) {
|
|
559
|
+
const modalContents = <Portal zIndex={zIndex} {...portalProps}><Theme forceClassName name={themeName}><AdaptParentContext.Provider value={adaptContext}>{contents}</AdaptParentContext.Provider></Theme></Portal>;
|
|
560
|
+
if (isWeb) {
|
|
561
|
+
return modalContents;
|
|
562
|
+
}
|
|
563
|
+
return <SheetInsideSheetContext.Provider value={onInnerSheet}>{modalContents}</SheetInsideSheetContext.Provider>;
|
|
564
|
+
}
|
|
565
|
+
return contents;
|
|
566
|
+
}),
|
|
567
|
+
{ componentName: "Sheet" }
|
|
568
|
+
);
|
|
569
|
+
const SheetInsideSheetContext = createContext(null);
|
|
570
|
+
const ControlledSheet = Sheet;
|
|
571
|
+
function getPercentSize(point, frameSize) {
|
|
572
|
+
if (!frameSize)
|
|
573
|
+
return 0;
|
|
574
|
+
if (point === void 0) {
|
|
575
|
+
console.warn("No snapPoint");
|
|
576
|
+
return 0;
|
|
577
|
+
}
|
|
578
|
+
const pct = point / 100;
|
|
579
|
+
const next = Math.round(frameSize - pct * frameSize);
|
|
580
|
+
return next;
|
|
581
|
+
}
|
|
582
|
+
function resisted(y, minY, maxOverflow = 25) {
|
|
583
|
+
if (y < minY) {
|
|
584
|
+
const past = minY - y;
|
|
585
|
+
const pctPast = Math.min(maxOverflow, past) / maxOverflow;
|
|
586
|
+
const diminishBy = 1.1 - Math.pow(0.1, pctPast);
|
|
587
|
+
const extra = -diminishBy * maxOverflow;
|
|
588
|
+
return minY + extra;
|
|
589
|
+
}
|
|
590
|
+
return y;
|
|
591
|
+
}
|
|
592
|
+
const SheetControllerContext = createContext(null);
|
|
593
|
+
const SheetController = ({
|
|
594
|
+
children,
|
|
595
|
+
onOpenChange: onOpenChangeProp,
|
|
596
|
+
...value
|
|
597
|
+
}) => {
|
|
598
|
+
const onOpenChange = useEvent(onOpenChangeProp);
|
|
599
|
+
const memoValue = useMemo(
|
|
600
|
+
() => ({
|
|
601
|
+
open: value.open,
|
|
602
|
+
hidden: value.hidden,
|
|
603
|
+
disableDrag: value.disableDrag,
|
|
604
|
+
onOpenChange
|
|
605
|
+
}),
|
|
606
|
+
[onOpenChange, value.open, value.hidden, value.disableDrag]
|
|
607
|
+
);
|
|
608
|
+
return <SheetControllerContext.Provider value={memoValue}>{children}</SheetControllerContext.Provider>;
|
|
609
|
+
};
|
|
610
|
+
export {
|
|
611
|
+
ControlledSheet,
|
|
612
|
+
Sheet,
|
|
613
|
+
SheetController,
|
|
614
|
+
SheetFrame,
|
|
615
|
+
SheetFrameFrame,
|
|
616
|
+
SheetHandle,
|
|
617
|
+
SheetHandleFrame,
|
|
618
|
+
SheetOverlay,
|
|
619
|
+
SheetOverlayFrame,
|
|
620
|
+
createSheetScope
|
|
621
|
+
};
|
|
2
622
|
//# sourceMappingURL=Sheet.mjs.map
|