@tamagui/sheet 1.88.12 → 1.89.0-1706308641099

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,91 @@
1
+ import { styled } from "@tamagui/core";
2
+ import { ThemeableStack, XStack, YStack } from "@tamagui/stacks";
3
+ import { SHEET_HANDLE_NAME, SHEET_NAME, SHEET_OVERLAY_NAME } from "./constants.mjs";
4
+ import { createSheet } from "./createSheet.mjs";
5
+ import { createSheetScope } from "./SheetContext.mjs";
6
+ export * from "./types.mjs";
7
+ const Handle = styled(XStack, {
8
+ name: SHEET_HANDLE_NAME,
9
+ variants: {
10
+ open: {
11
+ true: {
12
+ pointerEvents: "auto"
13
+ },
14
+ false: {
15
+ opacity: 0,
16
+ pointerEvents: "none"
17
+ }
18
+ },
19
+ unstyled: {
20
+ false: {
21
+ height: 10,
22
+ borderRadius: 100,
23
+ backgroundColor: "$background",
24
+ zIndex: 10,
25
+ marginHorizontal: "35%",
26
+ marginBottom: "$2",
27
+ opacity: 0.5,
28
+ hoverStyle: {
29
+ opacity: 0.7
30
+ }
31
+ }
32
+ }
33
+ },
34
+ defaultVariants: {
35
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
36
+ }
37
+ }),
38
+ Overlay = styled(ThemeableStack, {
39
+ name: SHEET_OVERLAY_NAME,
40
+ variants: {
41
+ open: {
42
+ true: {
43
+ opacity: 1,
44
+ pointerEvents: "auto"
45
+ },
46
+ false: {
47
+ opacity: 0,
48
+ pointerEvents: "none"
49
+ }
50
+ },
51
+ unstyled: {
52
+ false: {
53
+ fullscreen: !0,
54
+ position: "absolute",
55
+ backgrounded: !0,
56
+ zIndex: 99999,
57
+ pointerEvents: "auto"
58
+ }
59
+ }
60
+ },
61
+ defaultVariants: {
62
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
63
+ }
64
+ }),
65
+ Frame = styled(YStack, {
66
+ name: SHEET_NAME,
67
+ variants: {
68
+ unstyled: {
69
+ false: {
70
+ flex: 1,
71
+ backgroundColor: "$background",
72
+ borderTopLeftRadius: "$true",
73
+ borderTopRightRadius: "$true",
74
+ width: "100%",
75
+ maxHeight: "100%",
76
+ overflow: "hidden"
77
+ }
78
+ }
79
+ },
80
+ defaultVariants: {
81
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
82
+ }
83
+ }),
84
+ Sheet = createSheet({
85
+ Frame,
86
+ Handle,
87
+ Overlay
88
+ }),
89
+ SheetOverlayFrame = Overlay,
90
+ SheetHandleFrame = Handle;
91
+ export { Frame, Handle, Overlay, Sheet, SheetHandleFrame, SheetOverlayFrame, createSheetScope };
@@ -0,0 +1,5 @@
1
+ import { createContextScope } from "@tamagui/create-context";
2
+ import { SHEET_NAME } from "./constants.mjs";
3
+ const [createSheetContext, createSheetScope] = createContextScope(SHEET_NAME),
4
+ [SheetProvider, useSheetContext] = createSheetContext(SHEET_NAME, {});
5
+ export { SheetProvider, createSheetContext, createSheetScope, useSheetContext };
@@ -0,0 +1,22 @@
1
+ import { useEvent } from "@tamagui/core";
2
+ import { useMemo } from "react";
3
+ import { SheetControllerContext } from "./useSheetController.mjs";
4
+ import { jsx } from "react/jsx-runtime";
5
+ const SheetController = ({
6
+ children,
7
+ onOpenChange: onOpenChangeProp,
8
+ ...value
9
+ }) => {
10
+ const onOpenChange = useEvent(onOpenChangeProp),
11
+ memoValue = useMemo(() => ({
12
+ open: value.open,
13
+ hidden: value.hidden,
14
+ disableDrag: value.disableDrag,
15
+ onOpenChange
16
+ }), [onOpenChange, value.open, value.hidden, value.disableDrag]);
17
+ return /* @__PURE__ */jsx(SheetControllerContext.Provider, {
18
+ value: memoValue,
19
+ children
20
+ });
21
+ };
22
+ export { SheetController };
@@ -0,0 +1,313 @@
1
+ import { AdaptParentContext } from "@tamagui/adapt";
2
+ import { AnimatePresence } from "@tamagui/animate-presence";
3
+ import { useComposedRefs } from "@tamagui/compose-refs";
4
+ import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
5
+ import { Stack, Theme, getConfig, themeable, useConfiguration, useEvent, useThemeName } from "@tamagui/core";
6
+ import { Portal } from "@tamagui/portal";
7
+ import { useKeyboardVisible } from "@tamagui/use-keyboard-visible";
8
+ import { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
9
+ import { Dimensions, Keyboard, PanResponder, View } from "react-native-web";
10
+ import { SHEET_HIDDEN_STYLESHEET } from "./constants.mjs";
11
+ import { ParentSheetContext, SheetInsideSheetContext } from "./contexts.mjs";
12
+ import { resisted } from "./helpers.mjs";
13
+ import { SheetProvider } from "./SheetContext.mjs";
14
+ import { useSheetOpenState } from "./useSheetOpenState.mjs";
15
+ import { useSheetProviderProps } from "./useSheetProviderProps.mjs";
16
+ import { jsx, jsxs } from "react/jsx-runtime";
17
+ let hiddenSize = 10000.1;
18
+ const SheetImplementationCustom = themeable(forwardRef(function (props, forwardedRef) {
19
+ const parentSheet = useContext(ParentSheetContext),
20
+ {
21
+ animation,
22
+ animationConfig: animationConfigProp,
23
+ modal = !1,
24
+ zIndex = parentSheet.zIndex + 1,
25
+ moveOnKeyboardChange = !1,
26
+ unmountChildrenWhenHidden = !1,
27
+ portalProps
28
+ } = props,
29
+ keyboardIsVisible = useKeyboardVisible(),
30
+ state = useSheetOpenState(props),
31
+ [overlayComponent, setOverlayComponent] = useState(null),
32
+ providerProps = useSheetProviderProps(props, state, {
33
+ onOverlayComponent: setOverlayComponent
34
+ }),
35
+ {
36
+ frameSize,
37
+ setFrameSize,
38
+ snapPoints,
39
+ snapPointsMode,
40
+ hasFit,
41
+ position,
42
+ setPosition,
43
+ scrollBridge,
44
+ screenSize,
45
+ setMaxContentSize,
46
+ maxSnapPoint
47
+ } = providerProps,
48
+ {
49
+ open,
50
+ controller,
51
+ isHidden
52
+ } = state,
53
+ sheetRef = useRef(null),
54
+ ref = useComposedRefs(forwardedRef, sheetRef),
55
+ animationConfig = (() => {
56
+ const [animationProp, animationPropConfig] = animation ? Array.isArray(animation) ? animation : [animation] : [];
57
+ return animationConfigProp ?? (animationProp ? {
58
+ ...getConfig().animations.animations[animationProp],
59
+ ...animationPropConfig
60
+ } : null);
61
+ })(),
62
+ [isShowingInnerSheet, setIsShowingInnerSheet] = useState(!1),
63
+ shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet,
64
+ parentSheetContext = useContext(SheetInsideSheetContext),
65
+ onInnerSheet = useCallback(hasChild => {
66
+ setIsShowingInnerSheet(hasChild);
67
+ }, []),
68
+ positions = useMemo(() => snapPoints.map(point => getYPositions(snapPointsMode, point, screenSize, frameSize)), [screenSize, frameSize, snapPoints, snapPointsMode]),
69
+ {
70
+ animationDriver
71
+ } = useConfiguration(),
72
+ {
73
+ useAnimatedNumber,
74
+ useAnimatedNumberStyle,
75
+ useAnimatedNumberReaction
76
+ } = animationDriver,
77
+ AnimatedView = animationDriver.View ?? Stack;
78
+ useIsomorphicLayoutEffect(() => {
79
+ if (parentSheetContext && open) return parentSheetContext(!0), () => {
80
+ parentSheetContext(!1);
81
+ };
82
+ }, [parentSheetContext, open]);
83
+ const nextParentContext = useMemo(() => ({
84
+ zIndex
85
+ }), [zIndex]),
86
+ animatedNumber = useAnimatedNumber(hiddenSize),
87
+ at = useRef(hiddenSize);
88
+ useAnimatedNumberReaction({
89
+ value: animatedNumber,
90
+ hostRef: sheetRef
91
+ }, useCallback(value => {
92
+ at.current = value, scrollBridge.paneY = value;
93
+ }, [animationDriver]));
94
+ function stopSpring() {
95
+ animatedNumber.stop(), scrollBridge.onFinishAnimate && (scrollBridge.onFinishAnimate(), scrollBridge.onFinishAnimate = void 0);
96
+ }
97
+ const hasntMeasured = at.current === hiddenSize,
98
+ animateTo = useEvent(position2 => {
99
+ if (frameSize === 0) return;
100
+ let toValue = isHidden || position2 === -1 ? screenSize : positions[position2];
101
+ if (at.current !== toValue) {
102
+ if (at.current = toValue, stopSpring(), hasntMeasured || isHidden) {
103
+ if (animatedNumber.setValue(screenSize, {
104
+ type: "timing",
105
+ duration: 0
106
+ }), isHidden) return;
107
+ toValue = positions[position2], at.current = toValue;
108
+ }
109
+ animatedNumber.setValue(toValue, {
110
+ type: "spring",
111
+ ...animationConfig
112
+ });
113
+ }
114
+ });
115
+ useIsomorphicLayoutEffect(() => {
116
+ screenSize && hasntMeasured && animatedNumber.setValue(screenSize, {
117
+ type: "timing",
118
+ duration: 0
119
+ });
120
+ }, [hasntMeasured, screenSize]), useIsomorphicLayoutEffect(() => {
121
+ !frameSize || !screenSize || isHidden || hasntMeasured && !open || animateTo(position);
122
+ }, [isHidden, frameSize, screenSize, open, position]);
123
+ const disableDrag = props.disableDrag ?? controller?.disableDrag,
124
+ themeName = useThemeName(),
125
+ [isDragging, setIsDragging] = useState(!1),
126
+ panResponder = useMemo(() => {
127
+ if (disableDrag || !frameSize || isShowingInnerSheet) return;
128
+ const minY = positions[0];
129
+ scrollBridge.paneMinY = minY;
130
+ let startY = at.current;
131
+ function setPanning(val) {
132
+ setIsDragging(val), SHEET_HIDDEN_STYLESHEET && (val ? SHEET_HIDDEN_STYLESHEET.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }" : SHEET_HIDDEN_STYLESHEET.innerText = "");
133
+ }
134
+ const release = ({
135
+ vy,
136
+ dragAt
137
+ }) => {
138
+ isExternalDrag = !1, previouslyScrolling = !1, setPanning(!1);
139
+ const end = dragAt + startY + frameSize * vy * 0.2;
140
+ let closestPoint = 0,
141
+ dist = 1 / 0;
142
+ for (let i = 0; i < positions.length; i++) {
143
+ const position2 = positions[i],
144
+ curDist = end > position2 ? end - position2 : position2 - end;
145
+ curDist < dist && (dist = curDist, closestPoint = i);
146
+ }
147
+ setPosition(closestPoint), animateTo(closestPoint);
148
+ },
149
+ finish = (_e, state2) => {
150
+ release({
151
+ vy: state2.vy,
152
+ dragAt: state2.dy
153
+ });
154
+ };
155
+ let previouslyScrolling = !1;
156
+ const onMoveShouldSet = (_e, {
157
+ dy
158
+ }) => {
159
+ const isScrolled = scrollBridge.y !== 0,
160
+ isDraggingUp = dy < 0,
161
+ isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
162
+ return isScrolled ? (previouslyScrolling = !0, !1) : isNearTop && !isScrolled && isDraggingUp ? !1 : Math.abs(dy) > 5;
163
+ },
164
+ grant = () => {
165
+ setPanning(!0), stopSpring(), startY = at.current;
166
+ };
167
+ let isExternalDrag = !1;
168
+ return scrollBridge.drag = dy => {
169
+ isExternalDrag || (isExternalDrag = !0, grant());
170
+ const to = dy + startY;
171
+ animatedNumber.setValue(resisted(to, minY), {
172
+ type: "direct"
173
+ });
174
+ }, scrollBridge.release = release, PanResponder.create({
175
+ onMoveShouldSetPanResponder: onMoveShouldSet,
176
+ onPanResponderGrant: grant,
177
+ onPanResponderMove: (_e, {
178
+ dy
179
+ }) => {
180
+ const toFull = dy + startY,
181
+ to = resisted(toFull, minY);
182
+ animatedNumber.setValue(to, {
183
+ type: "direct"
184
+ });
185
+ },
186
+ onPanResponderEnd: finish,
187
+ onPanResponderTerminate: finish,
188
+ onPanResponderRelease: finish
189
+ });
190
+ },
191
+ // eslint-disable-next-line react-hooks/exhaustive-deps
192
+ [disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]),
193
+ handleAnimationViewLayout = useCallback(e => {
194
+ const next = Math.min(e.nativeEvent?.layout.height, Dimensions.get("window").height);
195
+ next && setFrameSize(next);
196
+ }, [keyboardIsVisible]),
197
+ handleMaxContentViewLayout = useCallback(e => {
198
+ const next = Math.min(e.nativeEvent?.layout.height, Dimensions.get("window").height);
199
+ next && setMaxContentSize(next);
200
+ }, [keyboardIsVisible]),
201
+ animatedStyle = useAnimatedNumberStyle(animatedNumber, val => {
202
+ "worklet";
203
+
204
+ return {
205
+ transform: [{
206
+ translateY: frameSize === 0 ? hiddenSize : val
207
+ }]
208
+ };
209
+ }),
210
+ sizeBeforeKeyboard = useRef(null);
211
+ useEffect(() => {
212
+ if (isWeb || !moveOnKeyboardChange) return;
213
+ const keyboardDidShowListener = Keyboard.addListener("keyboardDidShow", e => {
214
+ sizeBeforeKeyboard.current === null && (sizeBeforeKeyboard.current = animatedNumber.getValue(), animatedNumber.setValue(Math.max(animatedNumber.getValue() - e.endCoordinates.height, 0)));
215
+ }),
216
+ keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", () => {
217
+ sizeBeforeKeyboard.current !== null && (animatedNumber.setValue(sizeBeforeKeyboard.current), sizeBeforeKeyboard.current = null);
218
+ });
219
+ return () => {
220
+ keyboardDidHideListener.remove(), keyboardDidShowListener.remove();
221
+ };
222
+ }, [moveOnKeyboardChange]);
223
+ const [opacity, setOpacity] = useState(open ? 1 : 0);
224
+ open && opacity === 0 && setOpacity(1), useEffect(() => {
225
+ if (!open) {
226
+ const tm = setTimeout(() => {
227
+ setOpacity(0);
228
+ }, 400);
229
+ return () => {
230
+ clearTimeout(tm);
231
+ };
232
+ }
233
+ }, [open]);
234
+ const forcedContentHeight = hasFit ? void 0 : snapPointsMode === "percent" ? `${maxSnapPoint}%` : maxSnapPoint,
235
+ contents = /* @__PURE__ */jsx(ParentSheetContext.Provider, {
236
+ value: nextParentContext,
237
+ children: /* @__PURE__ */jsxs(SheetProvider, {
238
+ ...providerProps,
239
+ children: [/* @__PURE__ */jsx(AnimatePresence, {
240
+ enterExitVariant: "open",
241
+ children: shouldHideParentSheet || !open ? null : overlayComponent
242
+ }), snapPointsMode !== "percent" && /* @__PURE__ */jsx(View, {
243
+ style: {
244
+ opacity: 0,
245
+ position: "absolute",
246
+ top: 0,
247
+ left: 0,
248
+ right: 0,
249
+ bottom: 0,
250
+ pointerEvents: "none"
251
+ },
252
+ pointerEvents: "none",
253
+ onLayout: handleMaxContentViewLayout
254
+ }), /* @__PURE__ */jsx(AnimatedView, {
255
+ ref,
256
+ ...panResponder?.panHandlers,
257
+ onLayout: handleAnimationViewLayout,
258
+ pointerEvents: open && !shouldHideParentSheet ? "auto" : "none",
259
+ ...(!isDragging && {
260
+ // @ts-ignore for CSS driver this is necessary to attach the transition
261
+ animation
262
+ }),
263
+ style: [{
264
+ position: "absolute",
265
+ zIndex,
266
+ width: "100%",
267
+ height: forcedContentHeight,
268
+ minHeight: forcedContentHeight,
269
+ opacity
270
+ }, animatedStyle],
271
+ children: props.children
272
+ })]
273
+ })
274
+ }),
275
+ adaptContext = useContext(AdaptParentContext),
276
+ shouldMountChildren = !!(opacity || !unmountChildrenWhenHidden);
277
+ if (modal) {
278
+ const modalContents = /* @__PURE__ */jsx(Portal, {
279
+ zIndex,
280
+ ...portalProps,
281
+ children: shouldMountChildren && /* @__PURE__ */jsx(Theme, {
282
+ forceClassName: !0,
283
+ name: themeName,
284
+ children: /* @__PURE__ */jsx(AdaptParentContext.Provider, {
285
+ value: adaptContext,
286
+ children: contents
287
+ })
288
+ })
289
+ });
290
+ return isWeb ? modalContents : /* @__PURE__ */jsx(SheetInsideSheetContext.Provider, {
291
+ value: onInnerSheet,
292
+ children: modalContents
293
+ });
294
+ }
295
+ return contents;
296
+ }));
297
+ function getYPositions(mode, point, screenSize, frameSize) {
298
+ if (!screenSize || !frameSize) return 0;
299
+ if (mode === "mixed") {
300
+ if (typeof point == "number") return screenSize - Math.min(screenSize, Math.max(0, point));
301
+ if (point === "fit") return screenSize - Math.min(screenSize, frameSize);
302
+ if (point.endsWith("%")) {
303
+ const pct2 = Math.min(100, Math.max(0, Number(point.slice(0, -1)))) / 100;
304
+ return Number.isNaN(pct2) ? (console.warn("Invalid snapPoint percentage string"), 0) : Math.round(screenSize - pct2 * screenSize);
305
+ }
306
+ return console.warn("Invalid snapPoint unknown value"), 0;
307
+ }
308
+ if (mode === "fit") return point === 0 ? screenSize : screenSize - Math.min(screenSize, frameSize);
309
+ if (mode === "constant" && typeof point == "number") return screenSize - Math.min(screenSize, Math.max(0, point));
310
+ const pct = Math.min(100, Math.max(0, Number(point))) / 100;
311
+ return Number.isNaN(pct) ? (console.warn("Invalid snapPoint percentage"), 0) : Math.round(screenSize - pct * screenSize);
312
+ }
313
+ export { SheetImplementationCustom };
@@ -0,0 +1,57 @@
1
+ import { composeRefs } from "@tamagui/compose-refs";
2
+ import { ScrollView } from "@tamagui/scroll-view";
3
+ import { forwardRef, useMemo, useRef } from "react";
4
+ import { useSheetContext } from "./SheetContext.mjs";
5
+ import { jsx } from "react/jsx-runtime";
6
+ const SHEET_SCROLL_VIEW_NAME = "SheetScrollView",
7
+ SheetScrollView = forwardRef(({
8
+ __scopeSheet,
9
+ children,
10
+ onScroll,
11
+ ...props
12
+ }, ref) => {
13
+ const context = useSheetContext(SHEET_SCROLL_VIEW_NAME, __scopeSheet),
14
+ {
15
+ scrollBridge
16
+ } = context,
17
+ scrollRef = useRef(null),
18
+ state = useRef({
19
+ lastPageY: 0,
20
+ dragAt: 0,
21
+ dys: [],
22
+ // store a few recent dys to get velocity on release
23
+ isScrolling: !1,
24
+ isDragging: !1
25
+ }),
26
+ release = () => {
27
+ if (!state.current.isDragging) return;
28
+ state.current.isDragging = !1, scrollBridge.scrollStartY = -1, state.current.isScrolling = !1;
29
+ let vy = 0;
30
+ if (state.current.dys.length) {
31
+ const recentDys = state.current.dys.slice(-10);
32
+ vy = (recentDys.length ? recentDys.reduce((a, b) => a + b, 0) : 0) / recentDys.length * 0.04;
33
+ }
34
+ state.current.dys = [], scrollBridge.release({
35
+ dragAt: state.current.dragAt,
36
+ vy
37
+ });
38
+ };
39
+ return /* @__PURE__ */jsx(ScrollView, {
40
+ ref: composeRefs(scrollRef, ref),
41
+ flex: 1,
42
+ scrollEventThrottle: 8,
43
+ onScroll: e => {
44
+ const {
45
+ y
46
+ } = e.nativeEvent.contentOffset;
47
+ scrollBridge.y = y, y > 0 && (scrollBridge.scrollStartY = -1), onScroll?.(e);
48
+ },
49
+ onStartShouldSetResponder: () => (scrollBridge.scrollStartY = -1, state.current.isDragging = !0, !0),
50
+ onMoveShouldSetResponder: () => !1,
51
+ onResponderRelease: release,
52
+ className: "_ovs-contain",
53
+ ...props,
54
+ children: useMemo(() => children, [children])
55
+ });
56
+ });
57
+ export { SheetScrollView };
@@ -0,0 +1,8 @@
1
+ import { isClient } from "@tamagui/core";
2
+ const constants = {},
3
+ SHEET_NAME = "Sheet",
4
+ SHEET_HANDLE_NAME = "SheetHandle",
5
+ SHEET_OVERLAY_NAME = "SheetOverlay",
6
+ SHEET_HIDDEN_STYLESHEET = isClient ? document.createElement("style") : null;
7
+ SHEET_HIDDEN_STYLESHEET && document.head.appendChild(SHEET_HIDDEN_STYLESHEET);
8
+ export { SHEET_HANDLE_NAME, SHEET_HIDDEN_STYLESHEET, SHEET_NAME, SHEET_OVERLAY_NAME, constants };
@@ -0,0 +1,6 @@
1
+ import { createContext } from "react";
2
+ const ParentSheetContext = createContext({
3
+ zIndex: 1e5
4
+ }),
5
+ SheetInsideSheetContext = createContext(null);
6
+ export { ParentSheetContext, SheetInsideSheetContext };
@@ -0,0 +1,138 @@
1
+ import { useComposedRefs } from "@tamagui/compose-refs";
2
+ import { useIsomorphicLayoutEffect } from "@tamagui/constants";
3
+ import { Stack } from "@tamagui/core";
4
+ import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
5
+ import { RemoveScroll } from "@tamagui/remove-scroll";
6
+ import { useDidFinishSSR } from "@tamagui/use-did-finish-ssr";
7
+ import { forwardRef, memo, useMemo } from "react";
8
+ import { Platform } from "react-native-web";
9
+ import { SHEET_HANDLE_NAME, SHEET_NAME, SHEET_OVERLAY_NAME } from "./constants.mjs";
10
+ import { useSheetContext } from "./SheetContext.mjs";
11
+ import { SheetImplementationCustom } from "./SheetImplementationCustom.mjs";
12
+ import { SheetScrollView } from "./SheetScrollView.mjs";
13
+ import { useSheetController } from "./useSheetController.mjs";
14
+ import { useSheetOffscreenSize } from "./useSheetOffscreenSize.mjs";
15
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ function createSheet({
17
+ Handle,
18
+ Frame,
19
+ Overlay
20
+ }) {
21
+ const SheetHandle = Handle.extractable(({
22
+ __scopeSheet,
23
+ ...props
24
+ }) => {
25
+ const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet);
26
+ return context.onlyShowFrame ? null :
27
+ // @ts-ignore
28
+ /* @__PURE__ */
29
+ jsx(Handle, {
30
+ onPress: () => {
31
+ const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0),
32
+ nextPos = (context.position + 1) % max;
33
+ context.setPosition(nextPos);
34
+ },
35
+ open: context.open,
36
+ ...props
37
+ });
38
+ }),
39
+ SheetOverlay = Overlay.extractable(memo(propsIn => {
40
+ const {
41
+ __scopeSheet,
42
+ ...props
43
+ } = propsIn,
44
+ context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet),
45
+ element = useMemo(() =>
46
+ // @ts-ignore
47
+ /* @__PURE__ */
48
+ jsx(Overlay, {
49
+ ...props,
50
+ onPress: composeEventHandlers(props.onPress, context.dismissOnOverlayPress ? () => {
51
+ context.setOpen(!1);
52
+ } : void 0)
53
+ }), [props.onPress, context.dismissOnOverlayPress]);
54
+ return useIsomorphicLayoutEffect(() => {
55
+ context.onOverlayComponent?.(element);
56
+ }, [element]), context.onlyShowFrame, null;
57
+ })),
58
+ SheetFrame = Frame.extractable(forwardRef(({
59
+ __scopeSheet,
60
+ adjustPaddingForOffscreenContent,
61
+ disableHideBottomOverflow,
62
+ children,
63
+ ...props
64
+ }, forwardedRef) => {
65
+ const context = useSheetContext(SHEET_NAME, __scopeSheet),
66
+ {
67
+ hasFit,
68
+ removeScrollEnabled,
69
+ frameSize,
70
+ contentRef
71
+ } = context,
72
+ composedContentRef = useComposedRefs(forwardedRef, contentRef),
73
+ offscreenSize = useSheetOffscreenSize(context),
74
+ sheetContents = useMemo(() =>
75
+ // @ts-ignore
76
+ /* @__PURE__ */
77
+ jsxs(Frame, {
78
+ ref: composedContentRef,
79
+ flex: hasFit ? 0 : 1,
80
+ height: hasFit ? void 0 : frameSize,
81
+ ...props,
82
+ children: [children, adjustPaddingForOffscreenContent && /* @__PURE__ */jsx(Stack, {
83
+ "data-sheet-offscreen-pad": !0,
84
+ height: offscreenSize,
85
+ width: "100%"
86
+ })]
87
+ }), [props, frameSize, offscreenSize, adjustPaddingForOffscreenContent, hasFit]);
88
+ return /* @__PURE__ */jsxs(Fragment, {
89
+ children: [/* @__PURE__ */jsx(RemoveScroll, {
90
+ forwardProps: !0,
91
+ enabled: removeScrollEnabled,
92
+ allowPinchZoom: !0,
93
+ shards: [contentRef],
94
+ removeScrollBar: !1,
95
+ children: sheetContents
96
+ }), !disableHideBottomOverflow &&
97
+ // @ts-ignore
98
+ /* @__PURE__ */
99
+ jsx(Frame, {
100
+ ...props,
101
+ componentName: "SheetCover",
102
+ children: null,
103
+ position: "absolute",
104
+ bottom: "-50%",
105
+ zIndex: -1,
106
+ height: context.frameSize,
107
+ left: 0,
108
+ right: 0,
109
+ borderWidth: 0,
110
+ borderRadius: 0,
111
+ shadowOpacity: 0
112
+ })]
113
+ });
114
+ })),
115
+ Sheet = forwardRef(function (props, ref) {
116
+ const hydrated = useDidFinishSSR(),
117
+ {
118
+ isShowingNonSheet
119
+ } = useSheetController();
120
+ let SheetImplementation = SheetImplementationCustom;
121
+ return props.native && Platform.OS, isShowingNonSheet || !hydrated ? null : /* @__PURE__ */jsx(SheetImplementation, {
122
+ ref,
123
+ ...props
124
+ });
125
+ }),
126
+ components = {
127
+ Frame: SheetFrame,
128
+ Overlay: SheetOverlay,
129
+ Handle: SheetHandle,
130
+ ScrollView: SheetScrollView
131
+ },
132
+ Controlled = withStaticProperties(Sheet, components);
133
+ return withStaticProperties(Sheet, {
134
+ ...components,
135
+ Controlled
136
+ });
137
+ }
138
+ export { createSheet };
@@ -0,0 +1,9 @@
1
+ function resisted(y, minY, maxOverflow = 25) {
2
+ if (y < minY) {
3
+ const past = minY - y,
4
+ extra = -(1.1 - 0.1 ** (Math.min(maxOverflow, past) / maxOverflow)) * maxOverflow;
5
+ return minY + extra;
6
+ }
7
+ return y;
8
+ }
9
+ export { resisted };
@@ -0,0 +1,7 @@
1
+ export * from "./Sheet.mjs";
2
+ export * from "./useSheet.mjs";
3
+ export * from "./createSheet.mjs";
4
+ export * from "./SheetController.mjs";
5
+ export * from "./useSheetController.mjs";
6
+ import { setupNativeSheet } from "./nativeSheet.mjs";
7
+ export { setupNativeSheet };