@tamagui/sheet 1.26.1 → 1.27.0
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 +23 -425
- package/dist/cjs/Sheet.js.map +2 -2
- package/dist/cjs/StyledSheet.js +132 -0
- package/dist/cjs/StyledSheet.js.map +6 -0
- package/dist/cjs/constants.js +3 -0
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/createSheet.js +439 -0
- package/dist/cjs/createSheet.js.map +6 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Sheet.js +20 -447
- package/dist/esm/Sheet.js.map +2 -2
- package/dist/esm/StyledSheet.js +100 -0
- package/dist/esm/StyledSheet.js.map +6 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/createSheet.js +441 -0
- package/dist/esm/createSheet.js.map +6 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Sheet.js +20 -434
- package/dist/jsx/Sheet.js.map +2 -2
- package/dist/jsx/Sheet.mjs +20 -434
- package/dist/jsx/Sheet.mjs.map +2 -2
- package/dist/jsx/StyledSheet.js +100 -0
- package/dist/jsx/StyledSheet.js.map +6 -0
- package/dist/jsx/StyledSheet.mjs +100 -0
- package/dist/jsx/StyledSheet.mjs.map +6 -0
- package/dist/jsx/constants.js +2 -0
- package/dist/jsx/constants.js.map +1 -1
- package/dist/jsx/constants.mjs +2 -0
- package/dist/jsx/constants.mjs.map +1 -1
- package/dist/jsx/createSheet.js +428 -0
- package/dist/jsx/createSheet.js.map +6 -0
- package/dist/jsx/createSheet.mjs +428 -0
- package/dist/jsx/createSheet.mjs.map +6 -0
- package/dist/jsx/index.js +1 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -0
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +13 -13
- package/src/Sheet.tsx +20 -543
- package/src/constants.tsx +1 -0
- package/src/createSheet.tsx +565 -0
- package/src/index.ts +1 -0
- package/types/Sheet.d.ts +159 -80
- package/types/Sheet.d.ts.map +1 -1
- package/types/constants.d.ts +1 -0
- package/types/constants.d.ts.map +1 -1
- package/types/createSheet.d.ts +66 -0
- package/types/createSheet.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/dist/esm/Sheet.js
CHANGED
|
@@ -1,52 +1,10 @@
|
|
|
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";
|
|
1
|
+
import { styled } from "@tamagui/core";
|
|
21
2
|
import { ThemeableStack, XStack, YStack } from "@tamagui/stacks";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
createContext,
|
|
25
|
-
forwardRef,
|
|
26
|
-
useCallback,
|
|
27
|
-
useContext,
|
|
28
|
-
useEffect,
|
|
29
|
-
useMemo,
|
|
30
|
-
useRef,
|
|
31
|
-
useState
|
|
32
|
-
} from "react";
|
|
33
|
-
import {
|
|
34
|
-
Keyboard,
|
|
35
|
-
PanResponder,
|
|
36
|
-
Platform
|
|
37
|
-
} from "react-native";
|
|
38
|
-
import { SHEET_HANDLE_NAME, SHEET_NAME } from "./constants";
|
|
39
|
-
import { getNativeSheet } from "./nativeSheet";
|
|
40
|
-
import { SheetProvider, useSheetContext } from "./SheetContext";
|
|
41
|
-
import { SheetScrollView } from "./SheetScrollView";
|
|
42
|
-
import { useSheetChildren } from "./useSheetChildren";
|
|
43
|
-
import { useSheetController } from "./useSheetController";
|
|
44
|
-
import { useSheetOpenState } from "./useSheetOpenState";
|
|
45
|
-
import { useSheetProviderProps } from "./useSheetProviderProps";
|
|
46
|
-
import { useSheetSnapPoints } from "./useSheetSnapPoints";
|
|
3
|
+
import { SHEET_HANDLE_NAME, SHEET_NAME, SHEET_OVERLAY_NAME } from "./constants";
|
|
4
|
+
import { createSheet } from "./createSheet";
|
|
47
5
|
import { createSheetScope } from "./SheetContext";
|
|
48
6
|
export * from "./types";
|
|
49
|
-
const
|
|
7
|
+
const Handle = styled(XStack, {
|
|
50
8
|
name: SHEET_HANDLE_NAME,
|
|
51
9
|
variants: {
|
|
52
10
|
open: {
|
|
@@ -77,34 +35,17 @@ const SheetHandleFrame = styled(XStack, {
|
|
|
77
35
|
unstyled: false
|
|
78
36
|
}
|
|
79
37
|
});
|
|
80
|
-
const
|
|
81
|
-
({ __scopeSheet, ...props }) => {
|
|
82
|
-
const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet);
|
|
83
|
-
return /* @__PURE__ */ jsx(
|
|
84
|
-
SheetHandleFrame,
|
|
85
|
-
{
|
|
86
|
-
onPress: () => {
|
|
87
|
-
const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0);
|
|
88
|
-
const nextPos = (context.position + 1) % max;
|
|
89
|
-
context.setPosition(nextPos);
|
|
90
|
-
},
|
|
91
|
-
open: context.open,
|
|
92
|
-
...props
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
const SHEET_OVERLAY_NAME = "SheetOverlay";
|
|
98
|
-
const SheetOverlayFrame = styled(ThemeableStack, {
|
|
38
|
+
const Overlay = styled(ThemeableStack, {
|
|
99
39
|
name: SHEET_OVERLAY_NAME,
|
|
100
40
|
variants: {
|
|
101
|
-
|
|
41
|
+
open: {
|
|
102
42
|
true: {
|
|
103
|
-
opacity:
|
|
104
|
-
pointerEvents: "
|
|
43
|
+
opacity: 1,
|
|
44
|
+
pointerEvents: "auto"
|
|
105
45
|
},
|
|
106
46
|
false: {
|
|
107
|
-
|
|
47
|
+
opacity: 0,
|
|
48
|
+
pointerEvents: "none"
|
|
108
49
|
}
|
|
109
50
|
},
|
|
110
51
|
unstyled: {
|
|
@@ -120,29 +61,7 @@ const SheetOverlayFrame = styled(ThemeableStack, {
|
|
|
120
61
|
unstyled: false
|
|
121
62
|
}
|
|
122
63
|
});
|
|
123
|
-
const
|
|
124
|
-
({ __scopeSheet, ...props }) => {
|
|
125
|
-
const context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet);
|
|
126
|
-
return /* @__PURE__ */ jsx(
|
|
127
|
-
SheetOverlayFrame,
|
|
128
|
-
{
|
|
129
|
-
closed: !context.open || context.hidden,
|
|
130
|
-
...props,
|
|
131
|
-
onPress: mergeEvent(
|
|
132
|
-
props.onPress,
|
|
133
|
-
context.dismissOnOverlayPress ? () => {
|
|
134
|
-
context.setOpen(false);
|
|
135
|
-
} : void 0
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
const selectionStyleSheet = isClient ? document.createElement("style") : null;
|
|
142
|
-
if (selectionStyleSheet) {
|
|
143
|
-
document.head.appendChild(selectionStyleSheet);
|
|
144
|
-
}
|
|
145
|
-
const SheetFrameFrame = styled(YStack, {
|
|
64
|
+
const Frame = styled(YStack, {
|
|
146
65
|
name: SHEET_NAME,
|
|
147
66
|
variants: {
|
|
148
67
|
unstyled: {
|
|
@@ -162,365 +81,19 @@ const SheetFrameFrame = styled(YStack, {
|
|
|
162
81
|
unstyled: false
|
|
163
82
|
}
|
|
164
83
|
});
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const composedContentRef = useComposedRefs(forwardedRef, context.contentRef);
|
|
170
|
-
return /* @__PURE__ */ jsx(SheetFrameFrame, { ref: composedContentRef, ...props });
|
|
171
|
-
}
|
|
172
|
-
)
|
|
173
|
-
);
|
|
174
|
-
const HIDDEN_SIZE = 1e4;
|
|
175
|
-
const sheetComponents = {
|
|
176
|
-
Handle: SheetHandle,
|
|
177
|
-
Frame: SheetFrame,
|
|
178
|
-
Overlay: SheetOverlay,
|
|
179
|
-
ScrollView: SheetScrollView
|
|
180
|
-
};
|
|
181
|
-
const ParentSheetContext = createContext({
|
|
182
|
-
zIndex: 1e5
|
|
84
|
+
const Sheet = createSheet({
|
|
85
|
+
Frame,
|
|
86
|
+
Handle,
|
|
87
|
+
Overlay
|
|
183
88
|
});
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const hydrated = useDidFinishSSR();
|
|
187
|
-
const { isShowingNonSheet } = useSheetController();
|
|
188
|
-
let SheetImplementation = SheetImplementationCustom;
|
|
189
|
-
if (props.native && Platform.OS === "ios") {
|
|
190
|
-
if (process.env.TAMAGUI_TARGET === "native") {
|
|
191
|
-
const impl = getNativeSheet("ios");
|
|
192
|
-
if (impl) {
|
|
193
|
-
SheetImplementation = impl;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (isShowingNonSheet || !hydrated) {
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
return /* @__PURE__ */ jsx(SheetImplementation, { ref, ...props });
|
|
201
|
-
}),
|
|
202
|
-
sheetComponents
|
|
203
|
-
);
|
|
204
|
-
const SheetImplementationCustom = themeable(
|
|
205
|
-
forwardRef(function SheetImplementationCustom2(props, forwardedRef) {
|
|
206
|
-
const parentSheet = useContext(ParentSheetContext);
|
|
207
|
-
const {
|
|
208
|
-
animationConfig,
|
|
209
|
-
forceRemoveScrollEnabled = null,
|
|
210
|
-
disableDrag: disableDragProp,
|
|
211
|
-
modal = false,
|
|
212
|
-
zIndex = parentSheet.zIndex + 1,
|
|
213
|
-
moveOnKeyboardChange = false,
|
|
214
|
-
portalProps
|
|
215
|
-
} = props;
|
|
216
|
-
const state = useSheetOpenState(props);
|
|
217
|
-
const providerProps = useSheetProviderProps(props, state);
|
|
218
|
-
const { positions, maxSnapPoint, screenSize } = useSheetSnapPoints(providerProps);
|
|
219
|
-
const { position, contentRef, setPosition, scrollBridge, frameSize, setFrameSize } = providerProps;
|
|
220
|
-
const { open, isHidden, controller } = state;
|
|
221
|
-
const { frameComponent, handleComponent, bottomCoverComponent, overlayComponent } = useSheetChildren(props.children);
|
|
222
|
-
const sheetRef = useRef(null);
|
|
223
|
-
const ref = useComposedRefs(forwardedRef, sheetRef);
|
|
224
|
-
const driver = useAnimationDriver();
|
|
225
|
-
if (!driver) {
|
|
226
|
-
throw new Error("Must set animations in tamagui.config.ts");
|
|
227
|
-
}
|
|
228
|
-
const disableDrag = disableDragProp ?? (controller == null ? void 0 : controller.disableDrag);
|
|
229
|
-
const keyboardIsVisible = useKeyboardVisible();
|
|
230
|
-
const themeName = useThemeName();
|
|
231
|
-
const { useAnimatedNumber, useAnimatedNumberReaction, useAnimatedNumberStyle } = driver;
|
|
232
|
-
const animatedNumber = useAnimatedNumber(HIDDEN_SIZE);
|
|
233
|
-
const at = useRef(0);
|
|
234
|
-
useAnimatedNumberReaction(
|
|
235
|
-
{
|
|
236
|
-
value: animatedNumber,
|
|
237
|
-
hostRef: sheetRef
|
|
238
|
-
},
|
|
239
|
-
(value) => {
|
|
240
|
-
if (!driver.isReactNative)
|
|
241
|
-
return;
|
|
242
|
-
at.current = value;
|
|
243
|
-
scrollBridge.paneY = value;
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
function stopSpring() {
|
|
247
|
-
animatedNumber.stop();
|
|
248
|
-
if (scrollBridge.onFinishAnimate) {
|
|
249
|
-
scrollBridge.onFinishAnimate();
|
|
250
|
-
scrollBridge.onFinishAnimate = void 0;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
const [opacity, setOpacity] = useState(open ? 1 : 0);
|
|
254
|
-
if (open && opacity === 0) {
|
|
255
|
-
setOpacity(1);
|
|
256
|
-
}
|
|
257
|
-
useEffect(() => {
|
|
258
|
-
if (!open) {
|
|
259
|
-
const tm = setTimeout(() => {
|
|
260
|
-
setOpacity(0);
|
|
261
|
-
}, 400);
|
|
262
|
-
return () => {
|
|
263
|
-
clearTimeout(tm);
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}, [open]);
|
|
267
|
-
const animateTo = useEvent((position2) => {
|
|
268
|
-
const current = animatedNumber.getValue();
|
|
269
|
-
if (isHidden && open)
|
|
270
|
-
return;
|
|
271
|
-
if (!current)
|
|
272
|
-
return;
|
|
273
|
-
if (frameSize === 0)
|
|
274
|
-
return;
|
|
275
|
-
const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : screenSize;
|
|
276
|
-
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
277
|
-
if (at.current === toValue)
|
|
278
|
-
return;
|
|
279
|
-
stopSpring();
|
|
280
|
-
if (isHidden) {
|
|
281
|
-
animatedNumber.setValue(toValue, {
|
|
282
|
-
type: "timing",
|
|
283
|
-
duration: 0
|
|
284
|
-
});
|
|
285
|
-
at.current = toValue;
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
const overshootClamping = at.current === HIDDEN_SIZE;
|
|
289
|
-
animatedNumber.setValue(toValue, {
|
|
290
|
-
...animationConfig,
|
|
291
|
-
type: "spring",
|
|
292
|
-
overshootClamping
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
useIsomorphicLayoutEffect(() => {
|
|
296
|
-
animateTo(position);
|
|
297
|
-
}, [isHidden, frameSize, position, animateTo]);
|
|
298
|
-
const [isShowingInnerSheet, setIsShowingInnerSheet] = useState(false);
|
|
299
|
-
const shouldHideParentSheet = !isWeb && modal && isShowingInnerSheet;
|
|
300
|
-
const parentSheetContext = useContext(SheetInsideSheetContext);
|
|
301
|
-
const onInnerSheet = useCallback((hasChild) => {
|
|
302
|
-
setIsShowingInnerSheet(hasChild);
|
|
303
|
-
}, []);
|
|
304
|
-
const panResponder = useMemo(
|
|
305
|
-
() => {
|
|
306
|
-
if (disableDrag)
|
|
307
|
-
return;
|
|
308
|
-
if (!frameSize)
|
|
309
|
-
return;
|
|
310
|
-
if (isShowingInnerSheet)
|
|
311
|
-
return;
|
|
312
|
-
const minY = positions[0];
|
|
313
|
-
scrollBridge.paneMinY = minY;
|
|
314
|
-
let startY = at.current;
|
|
315
|
-
function makeUnselectable(val) {
|
|
316
|
-
if (!selectionStyleSheet)
|
|
317
|
-
return;
|
|
318
|
-
if (!val) {
|
|
319
|
-
selectionStyleSheet.innerText = "";
|
|
320
|
-
} else {
|
|
321
|
-
selectionStyleSheet.innerText = ":root * { user-select: none !important; -webkit-user-select: none !important; }";
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
const release = ({ vy, dragAt }) => {
|
|
325
|
-
isExternalDrag = false;
|
|
326
|
-
previouslyScrolling = false;
|
|
327
|
-
makeUnselectable(false);
|
|
328
|
-
const at2 = dragAt + startY;
|
|
329
|
-
const end = at2 + frameSize * vy * 0.2;
|
|
330
|
-
let closestPoint = 0;
|
|
331
|
-
let dist = Infinity;
|
|
332
|
-
for (let i = 0; i < positions.length; i++) {
|
|
333
|
-
const position2 = positions[i];
|
|
334
|
-
const curDist = end > position2 ? end - position2 : position2 - end;
|
|
335
|
-
if (curDist < dist) {
|
|
336
|
-
dist = curDist;
|
|
337
|
-
closestPoint = i;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
setPosition(closestPoint);
|
|
341
|
-
animateTo(closestPoint);
|
|
342
|
-
};
|
|
343
|
-
const finish = (_e, state2) => {
|
|
344
|
-
release({
|
|
345
|
-
vy: state2.vy,
|
|
346
|
-
dragAt: state2.dy
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
let previouslyScrolling = false;
|
|
350
|
-
const onMoveShouldSet = (_e, { dy }) => {
|
|
351
|
-
const isScrolled = scrollBridge.y !== 0;
|
|
352
|
-
const isDraggingUp = dy < 0;
|
|
353
|
-
const isNearTop = scrollBridge.paneY - 5 <= scrollBridge.paneMinY;
|
|
354
|
-
if (isScrolled) {
|
|
355
|
-
previouslyScrolling = true;
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
if (isNearTop) {
|
|
359
|
-
if (!isScrolled && isDraggingUp) {
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return Math.abs(dy) > 5;
|
|
364
|
-
};
|
|
365
|
-
const grant = () => {
|
|
366
|
-
makeUnselectable(true);
|
|
367
|
-
stopSpring();
|
|
368
|
-
startY = at.current;
|
|
369
|
-
};
|
|
370
|
-
let isExternalDrag = false;
|
|
371
|
-
scrollBridge.drag = (dy) => {
|
|
372
|
-
if (!isExternalDrag) {
|
|
373
|
-
isExternalDrag = true;
|
|
374
|
-
grant();
|
|
375
|
-
}
|
|
376
|
-
const to = dy + startY;
|
|
377
|
-
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
378
|
-
};
|
|
379
|
-
scrollBridge.release = release;
|
|
380
|
-
return PanResponder.create({
|
|
381
|
-
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
382
|
-
onPanResponderGrant: grant,
|
|
383
|
-
onPanResponderMove: (_e, { dy }) => {
|
|
384
|
-
const toFull = dy + startY;
|
|
385
|
-
const to = resisted(toFull, minY);
|
|
386
|
-
animatedNumber.setValue(to, { type: "direct" });
|
|
387
|
-
},
|
|
388
|
-
onPanResponderEnd: finish,
|
|
389
|
-
onPanResponderTerminate: finish,
|
|
390
|
-
onPanResponderRelease: finish
|
|
391
|
-
});
|
|
392
|
-
},
|
|
393
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
394
|
-
[disableDrag, isShowingInnerSheet, animateTo, frameSize, positions, setPosition]
|
|
395
|
-
);
|
|
396
|
-
const animatedStyle = useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
397
|
-
"worklet";
|
|
398
|
-
const translateY = frameSize === 0 ? HIDDEN_SIZE : val;
|
|
399
|
-
return {
|
|
400
|
-
transform: [{ translateY }]
|
|
401
|
-
};
|
|
402
|
-
});
|
|
403
|
-
const sizeBeforeKeyboard = useRef(null);
|
|
404
|
-
useEffect(() => {
|
|
405
|
-
if (isWeb || !moveOnKeyboardChange)
|
|
406
|
-
return;
|
|
407
|
-
const keyboardDidShowListener = Keyboard.addListener("keyboardDidShow", (e) => {
|
|
408
|
-
if (sizeBeforeKeyboard.current !== null)
|
|
409
|
-
return;
|
|
410
|
-
sizeBeforeKeyboard.current = animatedNumber.getValue();
|
|
411
|
-
animatedNumber.setValue(
|
|
412
|
-
Math.max(animatedNumber.getValue() - e.endCoordinates.height, 0)
|
|
413
|
-
);
|
|
414
|
-
});
|
|
415
|
-
const keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", () => {
|
|
416
|
-
if (sizeBeforeKeyboard.current === null)
|
|
417
|
-
return;
|
|
418
|
-
animatedNumber.setValue(sizeBeforeKeyboard.current);
|
|
419
|
-
sizeBeforeKeyboard.current = null;
|
|
420
|
-
});
|
|
421
|
-
return () => {
|
|
422
|
-
keyboardDidHideListener.remove();
|
|
423
|
-
keyboardDidShowListener.remove();
|
|
424
|
-
};
|
|
425
|
-
}, []);
|
|
426
|
-
const AnimatedView = driver["NumberView"] ?? driver.View;
|
|
427
|
-
useIsomorphicLayoutEffect(() => {
|
|
428
|
-
if (!(parentSheetContext && open))
|
|
429
|
-
return;
|
|
430
|
-
parentSheetContext(true);
|
|
431
|
-
return () => {
|
|
432
|
-
parentSheetContext(false);
|
|
433
|
-
};
|
|
434
|
-
}, [parentSheetContext, open]);
|
|
435
|
-
const nextParentContext = useMemo(
|
|
436
|
-
() => ({
|
|
437
|
-
zIndex
|
|
438
|
-
}),
|
|
439
|
-
[zIndex]
|
|
440
|
-
);
|
|
441
|
-
const handleLayout = useCallback(
|
|
442
|
-
(e) => {
|
|
443
|
-
var _a;
|
|
444
|
-
let next = (_a = e.nativeEvent) == null ? void 0 : _a.layout.height;
|
|
445
|
-
if (isWeb && isTouchable && !open) {
|
|
446
|
-
next += 100;
|
|
447
|
-
}
|
|
448
|
-
if (!next)
|
|
449
|
-
return;
|
|
450
|
-
setFrameSize(() => next);
|
|
451
|
-
},
|
|
452
|
-
[keyboardIsVisible]
|
|
453
|
-
);
|
|
454
|
-
const removeScrollEnabled = forceRemoveScrollEnabled ?? (open && modal);
|
|
455
|
-
const contents = /* @__PURE__ */ jsx(ParentSheetContext.Provider, { value: nextParentContext, children: /* @__PURE__ */ jsxs(SheetProvider, { ...providerProps, children: [
|
|
456
|
-
shouldHideParentSheet ? null : overlayComponent,
|
|
457
|
-
/* @__PURE__ */ jsxs(
|
|
458
|
-
AnimatedView,
|
|
459
|
-
{
|
|
460
|
-
ref,
|
|
461
|
-
...panResponder == null ? void 0 : panResponder.panHandlers,
|
|
462
|
-
onLayout: handleLayout,
|
|
463
|
-
pointerEvents: open && !shouldHideParentSheet ? "auto" : "none",
|
|
464
|
-
animation: props.animation,
|
|
465
|
-
style: [
|
|
466
|
-
{
|
|
467
|
-
position: "absolute",
|
|
468
|
-
zIndex,
|
|
469
|
-
width: "100%",
|
|
470
|
-
height: `${maxSnapPoint}%`,
|
|
471
|
-
opacity
|
|
472
|
-
},
|
|
473
|
-
animatedStyle
|
|
474
|
-
],
|
|
475
|
-
children: [
|
|
476
|
-
handleComponent,
|
|
477
|
-
bottomCoverComponent,
|
|
478
|
-
/* @__PURE__ */ jsx(
|
|
479
|
-
RemoveScroll,
|
|
480
|
-
{
|
|
481
|
-
forwardProps: true,
|
|
482
|
-
enabled: removeScrollEnabled,
|
|
483
|
-
allowPinchZoom: true,
|
|
484
|
-
shards: [contentRef],
|
|
485
|
-
removeScrollBar: false,
|
|
486
|
-
children: frameComponent
|
|
487
|
-
}
|
|
488
|
-
)
|
|
489
|
-
]
|
|
490
|
-
}
|
|
491
|
-
)
|
|
492
|
-
] }) });
|
|
493
|
-
const adaptContext = useContext(AdaptParentContext);
|
|
494
|
-
if (modal) {
|
|
495
|
-
const modalContents = /* @__PURE__ */ jsx(Portal, { zIndex, ...portalProps, children: /* @__PURE__ */ jsx(Theme, { forceClassName: true, name: themeName, children: /* @__PURE__ */ jsx(AdaptParentContext.Provider, { value: adaptContext, children: contents }) }) });
|
|
496
|
-
if (isWeb) {
|
|
497
|
-
return modalContents;
|
|
498
|
-
}
|
|
499
|
-
return /* @__PURE__ */ jsx(SheetInsideSheetContext.Provider, { value: onInnerSheet, children: modalContents });
|
|
500
|
-
}
|
|
501
|
-
return contents;
|
|
502
|
-
})
|
|
503
|
-
);
|
|
504
|
-
const SheetInsideSheetContext = createContext(null);
|
|
505
|
-
const ControlledSheet = Sheet;
|
|
506
|
-
function resisted(y, minY, maxOverflow = 25) {
|
|
507
|
-
if (y < minY) {
|
|
508
|
-
const past = minY - y;
|
|
509
|
-
const pctPast = Math.min(maxOverflow, past) / maxOverflow;
|
|
510
|
-
const diminishBy = 1.1 - Math.pow(0.1, pctPast);
|
|
511
|
-
const extra = -diminishBy * maxOverflow;
|
|
512
|
-
return minY + extra;
|
|
513
|
-
}
|
|
514
|
-
return y;
|
|
515
|
-
}
|
|
89
|
+
const SheetOverlayFrame = Overlay;
|
|
90
|
+
const SheetHandleFrame = Handle;
|
|
516
91
|
export {
|
|
517
|
-
|
|
92
|
+
Frame,
|
|
93
|
+
Handle,
|
|
94
|
+
Overlay,
|
|
518
95
|
Sheet,
|
|
519
|
-
SheetFrame,
|
|
520
|
-
SheetFrameFrame,
|
|
521
|
-
SheetHandle,
|
|
522
96
|
SheetHandleFrame,
|
|
523
|
-
SheetOverlay,
|
|
524
97
|
SheetOverlayFrame,
|
|
525
98
|
createSheetScope
|
|
526
99
|
};
|
package/dist/esm/Sheet.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Sheet.tsx"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB,QAAQ,cAAc;AAE/C,SAAS,mBAAmB,YAAY,0BAA0B;AAClE,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AACjC,cAAc;AAMP,MAAM,SAAS,OAAO,QAAQ;AAAA,EACnC,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,QACJ,eAAe;AAAA,MACjB;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,kBAAkB;AAAA,QAClB,cAAc;AAAA,QACd,SAAS;AAAA,QAET,YAAY;AAAA,UACV,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAMM,MAAM,UAAU,OAAO,gBAAgB;AAAA,EAC5C,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,cAAc;AAAA,QACd,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAMM,MAAM,QAAQ,OAAO,QAAQ;AAAA,EAClC,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,qBAAqB;AAAA,QACrB,sBAAsB;AAAA,QACtB,OAAO;AAAA,QACP,WAAW;AAAA,QACX,UAAU;AAAA,QACV,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAEM,MAAM,QAAQ,YAAY;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,MAAM,oBAAoB;AAG1B,MAAM,mBAAmB;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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";
|
|
4
|
+
import { createSheet } from "./createSheet";
|
|
5
|
+
import { createSheetScope } from "./SheetContext";
|
|
6
|
+
export * from "./types";
|
|
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: false
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const 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: true,
|
|
54
|
+
position: "absolute",
|
|
55
|
+
backgrounded: true,
|
|
56
|
+
zIndex: 1e5
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
defaultVariants: {
|
|
61
|
+
unstyled: false
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const Frame = styled(YStack, {
|
|
65
|
+
name: SHEET_NAME,
|
|
66
|
+
variants: {
|
|
67
|
+
unstyled: {
|
|
68
|
+
false: {
|
|
69
|
+
flex: 1,
|
|
70
|
+
backgroundColor: "$background",
|
|
71
|
+
borderTopLeftRadius: "$true",
|
|
72
|
+
borderTopRightRadius: "$true",
|
|
73
|
+
width: "100%",
|
|
74
|
+
maxHeight: "100%",
|
|
75
|
+
overflow: "hidden",
|
|
76
|
+
pointerEvents: "auto"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
defaultVariants: {
|
|
81
|
+
unstyled: false
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const Sheet = createSheet({
|
|
85
|
+
Frame,
|
|
86
|
+
Handle,
|
|
87
|
+
Overlay
|
|
88
|
+
});
|
|
89
|
+
const SheetOverlayFrame = Overlay;
|
|
90
|
+
const SheetHandleFrame = Handle;
|
|
91
|
+
export {
|
|
92
|
+
Frame,
|
|
93
|
+
Handle,
|
|
94
|
+
Overlay,
|
|
95
|
+
Sheet,
|
|
96
|
+
SheetHandleFrame,
|
|
97
|
+
SheetOverlayFrame,
|
|
98
|
+
createSheetScope
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=StyledSheet.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/StyledSheet.tsx"],
|
|
4
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB,QAAQ,cAAc;AAE/C,SAAS,mBAAmB,YAAY,0BAA0B;AAClE,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AACjC,cAAc;AAMP,MAAM,SAAS,OAAO,QAAQ;AAAA,EACnC,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,QACJ,eAAe;AAAA,MACjB;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,kBAAkB;AAAA,QAClB,cAAc;AAAA,QACd,SAAS;AAAA,QAET,YAAY;AAAA,UACV,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAMM,MAAM,UAAU,OAAO,gBAAgB;AAAA,EAC5C,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,IAEA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,cAAc;AAAA,QACd,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAMM,MAAM,QAAQ,OAAO,QAAQ;AAAA,EAClC,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,qBAAqB;AAAA,QACrB,sBAAsB;AAAA,QACtB,OAAO;AAAA,QACP,WAAW;AAAA,QACX,UAAU;AAAA,QACV,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAEM,MAAM,QAAQ,YAAY;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,MAAM,oBAAoB;AAG1B,MAAM,mBAAmB;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const constants = {};
|
|
2
2
|
const SHEET_NAME = "Sheet";
|
|
3
3
|
const SHEET_HANDLE_NAME = "SheetHandle";
|
|
4
|
+
const SHEET_OVERLAY_NAME = "SheetOverlay";
|
|
4
5
|
export {
|
|
5
6
|
SHEET_HANDLE_NAME,
|
|
6
7
|
SHEET_NAME,
|
|
8
|
+
SHEET_OVERLAY_NAME,
|
|
7
9
|
constants
|
|
8
10
|
};
|
|
9
11
|
//# sourceMappingURL=constants.js.map
|