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