@tamagui/sheet 1.13.2 → 1.13.4
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 +1 -659
- package/dist/cjs/Sheet.js.map +2 -2
- package/dist/cjs/SheetContext.js +1 -40
- package/dist/cjs/SheetContext.js.map +2 -2
- package/dist/cjs/SheetScrollView.js +1 -104
- package/dist/cjs/SheetScrollView.js.map +2 -2
- package/dist/cjs/constants.js +1 -34
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -16
- package/dist/cjs/types.js.map +2 -2
- package/dist/esm/Sheet.js +1 -643
- package/dist/esm/Sheet.js.map +2 -2
- package/dist/esm/Sheet.mjs +1 -643
- package/dist/esm/Sheet.mjs.map +2 -2
- package/dist/esm/SheetContext.js +1 -13
- package/dist/esm/SheetContext.js.map +2 -2
- package/dist/esm/SheetContext.mjs +1 -13
- package/dist/esm/SheetContext.mjs.map +2 -2
- package/dist/esm/SheetScrollView.js +1 -80
- package/dist/esm/SheetScrollView.js.map +2 -2
- package/dist/esm/SheetScrollView.mjs +1 -80
- package/dist/esm/SheetScrollView.mjs.map +2 -2
- package/dist/esm/constants.js +1 -8
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +1 -8
- 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 +1 -621
- package/dist/jsx/Sheet.js.map +2 -2
- package/dist/jsx/Sheet.mjs +1 -621
- package/dist/jsx/Sheet.mjs.map +2 -2
- package/dist/jsx/SheetContext.js +1 -13
- package/dist/jsx/SheetContext.js.map +2 -2
- package/dist/jsx/SheetContext.mjs +1 -13
- package/dist/jsx/SheetContext.mjs.map +2 -2
- package/dist/jsx/SheetScrollView.js +1 -75
- package/dist/jsx/SheetScrollView.js.map +2 -2
- package/dist/jsx/SheetScrollView.mjs +1 -75
- package/dist/jsx/SheetScrollView.mjs.map +2 -2
- package/dist/jsx/constants.js +1 -8
- package/dist/jsx/constants.js.map +2 -2
- package/dist/jsx/constants.mjs +1 -8
- 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,644 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
-
};
|
|
1
|
+
import{jsx as h,jsxs as Me}from"react/jsx-runtime";import{AdaptParentContext as be}from"@tamagui/adapt";import{useComposedRefs as ge}from"@tamagui/compose-refs";import{Theme as pt,isClient as mt,isTouchable as ht,isWeb as F,mergeEvent as ft,styled as W,themeable as St,useAnimationDriver as Pt,useDidFinishSSR as bt,useEvent as ve,useIsomorphicLayoutEffect as ye,useThemeName as gt,withStaticProperties as vt}from"@tamagui/core";import{Portal as yt}from"@tamagui/portal";import{RemoveScroll as Ct}from"@tamagui/remove-scroll";import{ThemeableStack as xt,XStack as Rt,YStack as Et}from"@tamagui/stacks";import{useConstant as wt}from"@tamagui/use-constant";import{useControllableState as Ce}from"@tamagui/use-controllable-state";import{useKeyboardVisible as Vt}from"@tamagui/use-keyboard-visible";import xe,{createContext as Z,forwardRef as q,isValidElement as Ot,useCallback as J,useContext as _,useEffect as Q,useMemo as k,useRef as j,useState as ee}from"react";import{Keyboard as Re,PanResponder as kt}from"react-native";import{SHEET_HANDLE_NAME as Ee,SHEET_NAME as we}from"./constants";import{SheetProvider as Nt,useSheetContext as te}from"./SheetContext";import{SheetScrollView as At}from"./SheetScrollView";import{createSheetScope as vn}from"./SheetContext";const Ve=W(Rt,{name:Ee,height:10,borderRadius:100,backgroundColor:"$background",zIndex:10,marginHorizontal:"35%",marginBottom:"$2",opacity:.5,hoverStyle:{opacity:.7},variants:{open:{true:{pointerEvents:"auto"},false:{opacity:0,pointerEvents:"none"}}}}),Dt=Ve.extractable(({__scopeSheet:n,...o})=>{const t=te(Ee,n);return h(Ve,{onPress:()=>{const i=t.snapPoints.length+(t.dismissOnSnapToBottom?-1:0),s=(t.position+1)%i;t.setPosition(s)},open:t.open,...o})}),Oe="SheetOverlay",ke=W(xt,{name:Oe,fullscreen:!0,backgrounded:!0,opacity:.5,zIndex:0,variants:{closed:{true:{opacity:0,pointerEvents:"none"},false:{pointerEvents:"auto"}}}}),Tt=ke.extractable(({__scopeSheet:n,...o})=>{const t=te(Oe,n);return h(ke,{closed:!t.open||t.hidden,...o,onPress:ft(o.onPress,t.dismissOnOverlayPress?()=>{t.setOpen(!1)}:void 0)})}),N=mt?document.createElement("style"):null;N&&document.head.appendChild(N);const Ne=W(Et,{name:we,flex:1,backgroundColor:"$background",borderTopLeftRadius:"$true",borderTopRightRadius:"$true",width:"100%",maxHeight:"100%",overflow:"hidden",pointerEvents:"auto"}),It=Ne.extractable(q(({__scopeSheet:n,...o},t)=>{const i=te(we,n),s=ge(t,i.contentRef);return h(Ne,{ref:s,...o})})),Y=1e4,Ht={Handle:Dt,Frame:It,Overlay:Tt,ScrollView:At},Ae=Z({zIndex:40}),De=()=>{const n=_(He),o=n==null?void 0:n.hidden,t=o&&(n==null?void 0:n.open);return{controller:n,isHidden:o,isShowingNonSheet:t}},Mt=vt(q(function(o,t){const i=bt(),{isShowingNonSheet:s}=De();return s||!i?null:h(Ft,{ref:t,...o})}),Ht),Ft=St(q(function(o,t){const i=_(Ae),{isHidden:s,controller:l}=De(),{__scopeSheet:B,snapPoints:A=[80],open:Fe,defaultOpen:Yt,children:_e,position:Ye,onPositionChange:Be,onOpenChange:L,defaultPosition:Le,dismissOnOverlayPress:ze=!0,animationConfig:Ge,dismissOnSnapToBottom:b=!1,forceRemoveScrollEnabled:$e=null,disableDrag:Ke,modal:D=!1,zIndex:T=i.zIndex+1,moveOnKeyboardChange:Xe=!1,portalProps:Ue}=o;process.env.NODE_ENV==="development"&&A.some(e=>e<0||e>100)&&console.warn("\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame");const ne=j(null),We=ge(t,ne),y=Pt();if(!y)throw new Error("Must set animations in tamagui.config.ts");const oe=Ke??(l==null?void 0:l.disableDrag),Ze=Vt(),qe=gt(),re=xe.useRef(null),u=wt(()=>({enabled:!1,y:0,paneY:0,paneMinY:0,scrollStartY:-1,drag:()=>{},release:()=>{},scrollLock:!1})),Je=e=>{var r;(r=l==null?void 0:l.onOpenChange)==null||r.call(l,e),L==null||L(e)},[a,z]=Ce({prop:(l==null?void 0:l.open)??Fe,defaultProp:!0,onChange:Je,strategy:"most-recent-wins",transition:!0}),[d,Qe]=ee(0),g=k(()=>b?[...A,0]:A,[JSON.stringify(A),b]),[je,G]=Ce({prop:Ye,defaultProp:Le||(a?0:-1),onChange:Be,strategy:"most-recent-wins",transition:!0}),C=a===!1?-1:je;a&&b&&C===g.length-1&&G(0);const x=J(e=>{b&&e===g.length-1?z(!1):G(e)},[b,g.length,G,z]),{useAnimatedNumber:et,useAnimatedNumberReaction:tt,useAnimatedNumberStyle:nt}=y,c=et(Y),v=j(0);tt({value:c,hostRef:ne},e=>{y.isReactNative&&(v.current=e,u.paneY=e)});function se(){c.stop(),u.onFinishAnimate&&(u.onFinishAnimate(),u.onFinishAnimate=void 0)}const ae=a&&C<0;Q(()=>{ae&&x(0)},[x,ae]);const R=k(()=>g.map(e=>_t(e,d)),[d,g]),[ie,le]=ee(a?1:0);a&&ie===0&&le(1),Q(()=>{if(!a){const e=setTimeout(()=>{le(0)},400);return()=>{clearTimeout(e)}}},[a]);const I=ve(e=>{const r=c.getValue();if(s&&a||!r||d===0)return;const f=s||e===-1?d===0?Y:d:R[e];if(v.current===f)return;if(se(),s){c.setValue(f,{type:"timing",duration:0}),v.current=f;return}const w=v.current===Y;c.setValue(f,{...Ge,type:"spring",overshootClamping:w})});ye(()=>{I(C)},[s,d,C,I]);const[$,ot]=ee(!1),ce=!F&&D&&$,H=_(Te),rt=J(e=>{ot(e)},[]),K=k(()=>{if(oe||!d||$)return;const e=R[0];u.paneMinY=e;let r=v.current;function p(S){N&&(S?N.innerText=":root * { user-select: none !important; -webkit-user-select: none !important; }":N.innerText="")}const f=({vy:S,dragAt:m})=>{X=!1,he=!1,p(!1);const P=m+r+d*S*.2;let O=0,Se=1/0;for(let M=0;M<R.length;M++){const U=R[M],Pe=P>U?P-U:U-P;Pe<Se&&(Se=Pe,O=M)}x(O),I(O)},w=(S,m)=>{f({vy:m.vy,dragAt:m.dy})};let he=!1;const dt=(S,{dy:m})=>{const V=u.y!==0,P=m<0,O=u.paneY-5<=u.paneMinY;return V?(he=!0,!1):O&&!V&&P?!1:Math.abs(m)>5},fe=()=>{p(!0),se(),r=v.current};let X=!1;return u.drag=S=>{X||(X=!0,fe());const m=S+r;c.setValue(Ie(m,e),{type:"direct"})},u.release=f,kt.create({onMoveShouldSetPanResponder:dt,onPanResponderGrant:fe,onPanResponderMove:(S,{dy:m})=>{const V=m+r,P=Ie(V,e);c.setValue(P,{type:"direct"})},onPanResponderEnd:w,onPanResponderTerminate:w,onPanResponderRelease:w})},[oe,$,I,d,R,x]);let ue=null,de=null,pe=null;xe.Children.forEach(_e,e=>{var r,p;if(Ot(e))switch((p=(r=e.type)==null?void 0:r.staticConfig)==null?void 0:p.componentName){case"SheetHandle":ue=e;break;case"Sheet":pe=e;break;case"SheetOverlay":de=e;break;default:console.warn("Warning: passed invalid child to Sheet",e)}});const st=nt(c,e=>({transform:[{translateY:d===0?Y:e}]})),E=j(null);Q(()=>{if(F||!Xe)return;const e=Re.addListener("keyboardDidShow",p=>{E.current===null&&(E.current=c.getValue(),c.setValue(Math.max(c.getValue()-p.endCoordinates.height,0)))}),r=Re.addListener("keyboardDidHide",()=>{E.current!==null&&(c.setValue(E.current),E.current=null)});return()=>{r.remove(),e.remove()}},[]);const at=y.NumberView??y.View;ye(()=>{if(H&&a)return H(!0),()=>{H(!1)}},[H,a]);const it=k(()=>({zIndex:T}),[T]),lt=J(e=>{var p;let r=(p=e.nativeEvent)==null?void 0:p.layout.height;F&&ht&&!a&&(r+=100),r&&Qe(()=>r)},[Ze]),ct=$e??(a&&D),me=h(Ae.Provider,{value:it,children:Me(Nt,{modal:D,contentRef:re,frameSize:d,dismissOnOverlayPress:ze,dismissOnSnapToBottom:b,open:a,hidden:!!s,scope:B,position:C,snapPoints:g,setPosition:x,setOpen:z,scrollBridge:u,children:[ce?null:de,Me(at,{ref:We,...K==null?void 0:K.panHandlers,onLayout:lt,pointerEvents:a&&!ce?"auto":"none",animation:o.animation,style:[{position:"absolute",zIndex:T,width:"100%",height:"100%",opacity:ie},st],children:[ue,h(Ct,{forwardProps:!0,enabled:ct,allowPinchZoom:!0,shards:[re],removeScrollBar:!1,children:pe})]})]})}),ut=_(be);if(D){const e=h(yt,{zIndex:T,...Ue,children:h(pt,{forceClassName:!0,name:qe,children:h(be.Provider,{value:ut,children:me})})});return F?e:h(Te.Provider,{value:rt,children:e})}return me}),{componentName:"Sheet"}),Te=Z(null),Sn=Mt;function _t(n,o){if(!o)return 0;if(n===void 0)return console.warn("No snapPoint"),0;const t=n/100;return Math.round(o-t*o)}function Ie(n,o,t=25){if(n<o){const i=o-n,s=Math.min(t,i)/t,B=-(1.1-Math.pow(.1,s))*t;return o+B}return n}const He=Z(null),Pn=({children:n,onOpenChange:o,...t})=>{const i=ve(o),s=k(()=>({open:t.open,hidden:t.hidden,disableDrag:t.disableDrag,onOpenChange:i}),[i,t.open,t.hidden,t.disableDrag]);return h(He.Provider,{value:s,children:n})};export{Sn as ControlledSheet,Mt as Sheet,Pn as SheetController,It as SheetFrame,Ne as SheetFrameFrame,Dt as SheetHandle,Ve as SheetHandleFrame,Tt as SheetOverlay,ke as SheetOverlayFrame,vn as createSheetScope};
|
|
644
2
|
//# sourceMappingURL=Sheet.js.map
|