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