@tamagui/sheet 1.0.1-beta.199 → 1.0.1-beta.201
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 +360 -345
- package/dist/cjs/Sheet.js.map +3 -3
- package/dist/esm/Sheet.js +360 -345
- package/dist/esm/Sheet.js.map +3 -3
- package/dist/jsx/Sheet.js +316 -304
- package/dist/jsx/Sheet.js.map +3 -3
- package/package.json +11 -11
- package/src/Sheet.tsx +394 -379
- package/types/Sheet.d.ts +2 -5
package/dist/cjs/Sheet.js
CHANGED
|
@@ -157,374 +157,389 @@ const sheetComponents = {
|
|
|
157
157
|
const ParentSheetContext = (0, import_react.createContext)({
|
|
158
158
|
zIndex: 40
|
|
159
159
|
});
|
|
160
|
+
const useSheetContoller = () => {
|
|
161
|
+
const controller = (0, import_react.useContext)(SheetControllerContext);
|
|
162
|
+
const isHidden = (controller == null ? void 0 : controller.hidden) || false;
|
|
163
|
+
const isShowingNonSheet = isHidden && (controller == null ? void 0 : controller.open);
|
|
164
|
+
return {
|
|
165
|
+
controller,
|
|
166
|
+
isHidden,
|
|
167
|
+
isShowingNonSheet
|
|
168
|
+
};
|
|
169
|
+
};
|
|
160
170
|
const Sheet = (0, import_core.withStaticProperties)(
|
|
161
|
-
(0,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
171
|
+
(0, import_react.forwardRef)(function Sheet2(props, ref) {
|
|
172
|
+
const { isShowingNonSheet } = useSheetContoller();
|
|
173
|
+
if (isShowingNonSheet) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetImplementation, {
|
|
177
|
+
ref,
|
|
178
|
+
...props
|
|
179
|
+
});
|
|
180
|
+
}),
|
|
181
|
+
sheetComponents
|
|
182
|
+
);
|
|
183
|
+
const SheetImplementation = (0, import_core.themeable)(
|
|
184
|
+
(0, import_react.forwardRef)(function SheetImplementation2(props, ref) {
|
|
185
|
+
const parentSheet = (0, import_react.useContext)(ParentSheetContext);
|
|
186
|
+
const { isHidden, controller } = useSheetContoller();
|
|
187
|
+
const {
|
|
188
|
+
__scopeSheet,
|
|
189
|
+
snapPoints: snapPointsProp = [80],
|
|
190
|
+
open: openProp,
|
|
191
|
+
defaultOpen,
|
|
192
|
+
children: childrenProp,
|
|
193
|
+
position: positionProp,
|
|
194
|
+
onPositionChange,
|
|
195
|
+
onOpenChange,
|
|
196
|
+
defaultPosition,
|
|
197
|
+
dismissOnOverlayPress = true,
|
|
198
|
+
animationConfig,
|
|
199
|
+
dismissOnSnapToBottom = false,
|
|
200
|
+
disableDrag: disableDragProp,
|
|
201
|
+
modal = false,
|
|
202
|
+
handleDisableScroll = true,
|
|
203
|
+
zIndex = parentSheet.zIndex + 1
|
|
204
|
+
} = props;
|
|
205
|
+
if (process.env.NODE_ENV === "development") {
|
|
206
|
+
if (snapPointsProp.some((p) => p < 0 || p > 100)) {
|
|
207
|
+
console.warn(
|
|
208
|
+
`\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const driver = (0, import_core.getAnimationDriver)();
|
|
213
|
+
if (!driver) {
|
|
214
|
+
throw new Error(`Must set animations in tamagui.config.ts`);
|
|
215
|
+
}
|
|
216
|
+
const disableDrag = disableDragProp ?? (controller == null ? void 0 : controller.disableDrag);
|
|
217
|
+
const themeName = (0, import_core.useThemeName)();
|
|
218
|
+
const contentRef = import_react.default.useRef(null);
|
|
219
|
+
const scrollBridge = (0, import_use_constant.useConstant)(() => ({
|
|
220
|
+
enabled: false,
|
|
221
|
+
y: 0,
|
|
222
|
+
paneY: 0,
|
|
223
|
+
paneMinY: 0,
|
|
224
|
+
scrollStartY: -1,
|
|
225
|
+
drag: () => {
|
|
226
|
+
},
|
|
227
|
+
release: () => {
|
|
228
|
+
},
|
|
229
|
+
scrollLock: false
|
|
230
|
+
}));
|
|
231
|
+
const onOpenChangeInternal = (val) => {
|
|
232
|
+
var _a;
|
|
233
|
+
(_a = controller == null ? void 0 : controller.onOpenChange) == null ? void 0 : _a.call(controller, val);
|
|
234
|
+
onOpenChange == null ? void 0 : onOpenChange(val);
|
|
235
|
+
};
|
|
236
|
+
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
237
|
+
prop: (controller == null ? void 0 : controller.open) ?? openProp,
|
|
238
|
+
defaultProp: defaultOpen || true,
|
|
239
|
+
onChange: onOpenChangeInternal,
|
|
240
|
+
strategy: "most-recent-wins"
|
|
241
|
+
});
|
|
242
|
+
const [frameSize, setFrameSize] = (0, import_react.useState)(0);
|
|
243
|
+
const snapPoints = (0, import_react.useMemo)(
|
|
244
|
+
() => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp,
|
|
245
|
+
[JSON.stringify(snapPointsProp), dismissOnSnapToBottom]
|
|
246
|
+
);
|
|
247
|
+
const [position_, setPosition_] = (0, import_use_controllable_state.useControllableState)({
|
|
248
|
+
prop: positionProp,
|
|
249
|
+
defaultProp: defaultPosition || (open ? 0 : -1),
|
|
250
|
+
onChange: onPositionChange,
|
|
251
|
+
strategy: "most-recent-wins"
|
|
252
|
+
});
|
|
253
|
+
const position = open === false ? -1 : position_;
|
|
254
|
+
if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
|
|
255
|
+
setPosition_(0);
|
|
256
|
+
}
|
|
257
|
+
const setPosition = (0, import_react.useCallback)(
|
|
258
|
+
(next) => {
|
|
259
|
+
if (dismissOnSnapToBottom && next === snapPoints.length - 1) {
|
|
260
|
+
setOpen(false);
|
|
261
|
+
} else {
|
|
262
|
+
setPosition_(next);
|
|
187
263
|
}
|
|
264
|
+
},
|
|
265
|
+
[dismissOnSnapToBottom, snapPoints.length, setPosition_, setOpen]
|
|
266
|
+
);
|
|
267
|
+
const animatedNumber = driver.useAnimatedNumber(HIDDEN_SIZE);
|
|
268
|
+
const at = (0, import_react.useRef)(0);
|
|
269
|
+
driver.useAnimatedNumberReaction(animatedNumber, (value) => {
|
|
270
|
+
at.current = value;
|
|
271
|
+
scrollBridge.paneY = value;
|
|
272
|
+
});
|
|
273
|
+
const [isResizing, setIsResizing] = (0, import_react.useState)(true);
|
|
274
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
275
|
+
if (!isResizing) {
|
|
276
|
+
setIsResizing(true);
|
|
188
277
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
278
|
+
}, [modal]);
|
|
279
|
+
function stopSpring() {
|
|
280
|
+
animatedNumber.stop();
|
|
281
|
+
if (scrollBridge.onFinishAnimate) {
|
|
282
|
+
scrollBridge.onFinishAnimate();
|
|
283
|
+
scrollBridge.onFinishAnimate = void 0;
|
|
192
284
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const scrollBridge = (0, import_use_constant.useConstant)(() => ({
|
|
199
|
-
enabled: false,
|
|
200
|
-
y: 0,
|
|
201
|
-
paneY: 0,
|
|
202
|
-
paneMinY: 0,
|
|
203
|
-
scrollStartY: -1,
|
|
204
|
-
drag: () => {
|
|
205
|
-
},
|
|
206
|
-
release: () => {
|
|
207
|
-
},
|
|
208
|
-
scrollLock: false
|
|
209
|
-
}));
|
|
210
|
-
const onOpenChangeInternal = (val) => {
|
|
211
|
-
var _a;
|
|
212
|
-
(_a = controller == null ? void 0 : controller.onOpenChange) == null ? void 0 : _a.call(controller, val);
|
|
213
|
-
onOpenChange == null ? void 0 : onOpenChange(val);
|
|
214
|
-
};
|
|
215
|
-
const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
|
|
216
|
-
prop: (controller == null ? void 0 : controller.open) ?? openProp,
|
|
217
|
-
defaultProp: defaultOpen || true,
|
|
218
|
-
onChange: onOpenChangeInternal,
|
|
219
|
-
strategy: "most-recent-wins"
|
|
220
|
-
});
|
|
221
|
-
const [frameSize, setFrameSize] = (0, import_react.useState)(0);
|
|
222
|
-
const snapPoints = (0, import_react.useMemo)(
|
|
223
|
-
() => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp,
|
|
224
|
-
[JSON.stringify(snapPointsProp), dismissOnSnapToBottom]
|
|
225
|
-
);
|
|
226
|
-
const [position_, setPosition_] = (0, import_use_controllable_state.useControllableState)({
|
|
227
|
-
prop: positionProp,
|
|
228
|
-
defaultProp: defaultPosition || (open ? 0 : -1),
|
|
229
|
-
onChange: onPositionChange,
|
|
230
|
-
strategy: "most-recent-wins"
|
|
231
|
-
});
|
|
232
|
-
const position = open === false ? -1 : position_;
|
|
233
|
-
if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
|
|
234
|
-
setPosition_(0);
|
|
285
|
+
}
|
|
286
|
+
const shouldSetPositionOpen = open && position < 0;
|
|
287
|
+
(0, import_react.useEffect)(() => {
|
|
288
|
+
if (shouldSetPositionOpen) {
|
|
289
|
+
setPosition(0);
|
|
235
290
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}, [modal]);
|
|
258
|
-
function stopSpring() {
|
|
259
|
-
animatedNumber.stop();
|
|
260
|
-
if (scrollBridge.onFinishAnimate) {
|
|
261
|
-
scrollBridge.onFinishAnimate();
|
|
262
|
-
scrollBridge.onFinishAnimate = void 0;
|
|
291
|
+
}, [setPosition, shouldSetPositionOpen]);
|
|
292
|
+
const positions = (0, import_react.useMemo)(
|
|
293
|
+
() => snapPoints.map((point) => getPercentSize(point, frameSize)),
|
|
294
|
+
[frameSize, snapPoints]
|
|
295
|
+
);
|
|
296
|
+
const animateTo = (0, import_core.useEvent)((position2) => {
|
|
297
|
+
const current = animatedNumber.getValue();
|
|
298
|
+
if (isHidden && open)
|
|
299
|
+
return;
|
|
300
|
+
if (!current)
|
|
301
|
+
return;
|
|
302
|
+
if (frameSize === 0)
|
|
303
|
+
return;
|
|
304
|
+
const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : frameSize;
|
|
305
|
+
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
306
|
+
if (at.current === toValue)
|
|
307
|
+
return;
|
|
308
|
+
stopSpring();
|
|
309
|
+
if (isHidden || isResizing) {
|
|
310
|
+
if (isResizing) {
|
|
311
|
+
setIsResizing(false);
|
|
263
312
|
}
|
|
313
|
+
animatedNumber.setValue(toValue, {
|
|
314
|
+
type: "timing",
|
|
315
|
+
duration: 0
|
|
316
|
+
});
|
|
317
|
+
at.current = toValue;
|
|
318
|
+
return;
|
|
264
319
|
}
|
|
265
|
-
const
|
|
266
|
-
(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
return;
|
|
279
|
-
if (!current)
|
|
280
|
-
return;
|
|
281
|
-
if (frameSize === 0)
|
|
320
|
+
const overshootClamping = at.current === HIDDEN_SIZE;
|
|
321
|
+
animatedNumber.setValue(toValue, {
|
|
322
|
+
...animationConfig,
|
|
323
|
+
type: "spring",
|
|
324
|
+
overshootClamping
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
328
|
+
animateTo(position);
|
|
329
|
+
}, [isHidden, frameSize, position, animateTo]);
|
|
330
|
+
const panResponder = (0, import_react.useMemo)(
|
|
331
|
+
() => {
|
|
332
|
+
if (disableDrag)
|
|
282
333
|
return;
|
|
283
|
-
|
|
284
|
-
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
285
|
-
if (at.current === toValue)
|
|
334
|
+
if (!frameSize)
|
|
286
335
|
return;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
336
|
+
const minY = positions[0];
|
|
337
|
+
scrollBridge.paneMinY = minY;
|
|
338
|
+
let startY = at.current;
|
|
339
|
+
function makeUnselectable(val) {
|
|
340
|
+
if (!selectionStyleSheet)
|
|
341
|
+
return;
|
|
342
|
+
if (!val) {
|
|
343
|
+
selectionStyleSheet.innerText = ``;
|
|
344
|
+
} else {
|
|
345
|
+
selectionStyleSheet.innerText = `:root * { user-select: none !important; -webkit-user-select: none !important; }`;
|
|
291
346
|
}
|
|
292
|
-
animatedNumber.setValue(toValue, {
|
|
293
|
-
type: "timing",
|
|
294
|
-
duration: 0
|
|
295
|
-
});
|
|
296
|
-
at.current = toValue;
|
|
297
|
-
return;
|
|
298
347
|
}
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (!frameSize)
|
|
314
|
-
return;
|
|
315
|
-
const minY = positions[0];
|
|
316
|
-
scrollBridge.paneMinY = minY;
|
|
317
|
-
let startY = at.current;
|
|
318
|
-
function makeUnselectable(val) {
|
|
319
|
-
if (!selectionStyleSheet)
|
|
320
|
-
return;
|
|
321
|
-
if (!val) {
|
|
322
|
-
selectionStyleSheet.innerText = ``;
|
|
323
|
-
} else {
|
|
324
|
-
selectionStyleSheet.innerText = `:root * { user-select: none !important; -webkit-user-select: none !important; }`;
|
|
348
|
+
const release = ({ vy, dragAt }) => {
|
|
349
|
+
isExternalDrag = false;
|
|
350
|
+
previouslyScrolling = false;
|
|
351
|
+
makeUnselectable(false);
|
|
352
|
+
const at2 = dragAt + startY;
|
|
353
|
+
const end = at2 + frameSize * vy * 0.2;
|
|
354
|
+
let closestPoint = 0;
|
|
355
|
+
let dist = Infinity;
|
|
356
|
+
for (let i = 0; i < positions.length; i++) {
|
|
357
|
+
const position2 = positions[i];
|
|
358
|
+
const curDist = end > position2 ? end - position2 : position2 - end;
|
|
359
|
+
if (curDist < dist) {
|
|
360
|
+
dist = curDist;
|
|
361
|
+
closestPoint = i;
|
|
325
362
|
}
|
|
326
363
|
}
|
|
327
|
-
|
|
328
|
-
|
|
364
|
+
setPosition(closestPoint);
|
|
365
|
+
animateTo(closestPoint);
|
|
366
|
+
};
|
|
367
|
+
const finish = (_e, state) => {
|
|
368
|
+
release({
|
|
369
|
+
vy: state.vy,
|
|
370
|
+
dragAt: state.dy
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
let previouslyScrolling = false;
|
|
374
|
+
const onMoveShouldSet = (_e, { dy }) => {
|
|
375
|
+
const isScrolled = scrollBridge.y !== 0;
|
|
376
|
+
const isDraggingUp = dy < 0;
|
|
377
|
+
const isAtTop = scrollBridge.paneY <= scrollBridge.paneMinY;
|
|
378
|
+
if (isScrolled) {
|
|
379
|
+
previouslyScrolling = true;
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
if (previouslyScrolling) {
|
|
329
383
|
previouslyScrolling = false;
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
let dist = Infinity;
|
|
335
|
-
for (let i = 0; i < positions.length; i++) {
|
|
336
|
-
const position2 = positions[i];
|
|
337
|
-
const curDist = end > position2 ? end - position2 : position2 - end;
|
|
338
|
-
if (curDist < dist) {
|
|
339
|
-
dist = curDist;
|
|
340
|
-
closestPoint = i;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
setPosition(closestPoint);
|
|
344
|
-
animateTo(closestPoint);
|
|
345
|
-
};
|
|
346
|
-
const finish = (_e, state) => {
|
|
347
|
-
release({
|
|
348
|
-
vy: state.vy,
|
|
349
|
-
dragAt: state.dy
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
let previouslyScrolling = false;
|
|
353
|
-
const onMoveShouldSet = (_e, { dy }) => {
|
|
354
|
-
const isScrolled = scrollBridge.y !== 0;
|
|
355
|
-
const isDraggingUp = dy < 0;
|
|
356
|
-
const isAtTop = scrollBridge.paneY <= scrollBridge.paneMinY;
|
|
357
|
-
if (isScrolled) {
|
|
358
|
-
previouslyScrolling = true;
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
if (isAtTop) {
|
|
387
|
+
if (!isScrolled && isDraggingUp) {
|
|
359
388
|
return false;
|
|
360
389
|
}
|
|
361
|
-
if (previouslyScrolling) {
|
|
362
|
-
previouslyScrolling = false;
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
if (isAtTop) {
|
|
366
|
-
if (!isScrolled && isDraggingUp) {
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return Math.abs(dy) > 5;
|
|
371
|
-
};
|
|
372
|
-
const grant = () => {
|
|
373
|
-
makeUnselectable(true);
|
|
374
|
-
stopSpring();
|
|
375
|
-
startY = at.current;
|
|
376
|
-
};
|
|
377
|
-
let isExternalDrag = false;
|
|
378
|
-
scrollBridge.drag = (dy) => {
|
|
379
|
-
if (!isExternalDrag) {
|
|
380
|
-
isExternalDrag = true;
|
|
381
|
-
grant();
|
|
382
|
-
}
|
|
383
|
-
const to = dy + startY;
|
|
384
|
-
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
385
|
-
};
|
|
386
|
-
scrollBridge.release = release;
|
|
387
|
-
return import_react_native.PanResponder.create({
|
|
388
|
-
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
389
|
-
onPanResponderGrant: grant,
|
|
390
|
-
onPanResponderMove: (_e, { dy }) => {
|
|
391
|
-
const toFull = dy + startY;
|
|
392
|
-
const to = resisted(toFull, minY);
|
|
393
|
-
animatedNumber.setValue(to, { type: "direct" });
|
|
394
|
-
},
|
|
395
|
-
onPanResponderEnd: finish,
|
|
396
|
-
onPanResponderTerminate: finish,
|
|
397
|
-
onPanResponderRelease: finish
|
|
398
|
-
});
|
|
399
|
-
},
|
|
400
|
-
[disableDrag, animateTo, frameSize, positions, setPosition]
|
|
401
|
-
);
|
|
402
|
-
let handleComponent = null;
|
|
403
|
-
let overlayComponent = null;
|
|
404
|
-
let frameComponent = null;
|
|
405
|
-
import_react.default.Children.forEach(childrenProp, (child) => {
|
|
406
|
-
var _a, _b;
|
|
407
|
-
if ((0, import_react.isValidElement)(child)) {
|
|
408
|
-
const name = (_b = (_a = child.type) == null ? void 0 : _a["staticConfig"]) == null ? void 0 : _b.componentName;
|
|
409
|
-
switch (name) {
|
|
410
|
-
case "SheetHandle":
|
|
411
|
-
handleComponent = child;
|
|
412
|
-
break;
|
|
413
|
-
case "Sheet":
|
|
414
|
-
frameComponent = child;
|
|
415
|
-
break;
|
|
416
|
-
case "SheetOverlay":
|
|
417
|
-
overlayComponent = child;
|
|
418
|
-
break;
|
|
419
|
-
default:
|
|
420
|
-
console.warn("Warning: passed invalid child to Sheet", child);
|
|
421
390
|
}
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
const preventShown = (controller == null ? void 0 : controller.hidden) && (controller == null ? void 0 : controller.open);
|
|
425
|
-
const animatedStyle = driver.useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
426
|
-
return {
|
|
427
|
-
transform: [{ translateY: frameSize === 0 ? HIDDEN_SIZE : val }]
|
|
391
|
+
return Math.abs(dy) > 5;
|
|
428
392
|
};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
parentSheetContext(false);
|
|
393
|
+
const grant = () => {
|
|
394
|
+
makeUnselectable(true);
|
|
395
|
+
stopSpring();
|
|
396
|
+
startY = at.current;
|
|
397
|
+
};
|
|
398
|
+
let isExternalDrag = false;
|
|
399
|
+
scrollBridge.drag = (dy) => {
|
|
400
|
+
if (!isExternalDrag) {
|
|
401
|
+
isExternalDrag = true;
|
|
402
|
+
grant();
|
|
403
|
+
}
|
|
404
|
+
const to = dy + startY;
|
|
405
|
+
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
443
406
|
};
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
407
|
+
scrollBridge.release = release;
|
|
408
|
+
return import_react_native.PanResponder.create({
|
|
409
|
+
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
410
|
+
onPanResponderGrant: grant,
|
|
411
|
+
onPanResponderMove: (_e, { dy }) => {
|
|
412
|
+
const toFull = dy + startY;
|
|
413
|
+
const to = resisted(toFull, minY);
|
|
414
|
+
animatedNumber.setValue(to, { type: "direct" });
|
|
415
|
+
},
|
|
416
|
+
onPanResponderEnd: finish,
|
|
417
|
+
onPanResponderTerminate: finish,
|
|
418
|
+
onPanResponderRelease: finish
|
|
419
|
+
});
|
|
420
|
+
},
|
|
421
|
+
[disableDrag, animateTo, frameSize, positions, setPosition]
|
|
422
|
+
);
|
|
423
|
+
let handleComponent = null;
|
|
424
|
+
let overlayComponent = null;
|
|
425
|
+
let frameComponent = null;
|
|
426
|
+
import_react.default.Children.forEach(childrenProp, (child) => {
|
|
427
|
+
var _a, _b;
|
|
428
|
+
if ((0, import_react.isValidElement)(child)) {
|
|
429
|
+
const name = (_b = (_a = child.type) == null ? void 0 : _a["staticConfig"]) == null ? void 0 : _b.componentName;
|
|
430
|
+
switch (name) {
|
|
431
|
+
case "SheetHandle":
|
|
432
|
+
handleComponent = child;
|
|
433
|
+
break;
|
|
434
|
+
case "Sheet":
|
|
435
|
+
frameComponent = child;
|
|
436
|
+
break;
|
|
437
|
+
case "SheetOverlay":
|
|
438
|
+
overlayComponent = child;
|
|
439
|
+
break;
|
|
440
|
+
default:
|
|
441
|
+
console.warn("Warning: passed invalid child to Sheet", child);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
const animatedStyle = driver.useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
446
|
+
return {
|
|
447
|
+
transform: [{ translateY: frameSize === 0 ? HIDDEN_SIZE : val }]
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
const AnimatedView = driver["NumberView"] ?? driver.View;
|
|
451
|
+
const [isShowingInnerSheet, setIsShowingInnerSheet] = (0, import_react.useState)(false);
|
|
452
|
+
const shouldHideParentSheet = !import_core.isWeb && modal && isShowingInnerSheet;
|
|
453
|
+
const parentSheetContext = (0, import_react.useContext)(SheetInsideSheetContext);
|
|
454
|
+
const onInnerSheet = (0, import_react.useCallback)((hasChild) => {
|
|
455
|
+
setIsShowingInnerSheet(hasChild);
|
|
456
|
+
}, []);
|
|
457
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
458
|
+
if (!parentSheetContext || !open)
|
|
459
|
+
return;
|
|
460
|
+
parentSheetContext(true);
|
|
461
|
+
return () => {
|
|
462
|
+
parentSheetContext(false);
|
|
463
|
+
};
|
|
464
|
+
}, [parentSheetContext, open]);
|
|
465
|
+
const nextParentContext = (0, import_react.useMemo)(
|
|
466
|
+
() => ({
|
|
467
|
+
zIndex
|
|
468
|
+
}),
|
|
469
|
+
[zIndex]
|
|
470
|
+
);
|
|
471
|
+
const contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ParentSheetContext.Provider, {
|
|
472
|
+
value: nextParentContext,
|
|
473
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_SheetContext.SheetProvider, {
|
|
474
|
+
modal,
|
|
475
|
+
contentRef,
|
|
476
|
+
dismissOnOverlayPress,
|
|
477
|
+
dismissOnSnapToBottom,
|
|
478
|
+
open,
|
|
479
|
+
hidden: isHidden,
|
|
480
|
+
scope: __scopeSheet,
|
|
481
|
+
position,
|
|
482
|
+
snapPoints,
|
|
483
|
+
setPosition,
|
|
484
|
+
setOpen,
|
|
485
|
+
scrollBridge,
|
|
486
|
+
children: [
|
|
487
|
+
isResizing || shouldHideParentSheet ? null : overlayComponent,
|
|
488
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AnimatedView, {
|
|
489
|
+
ref,
|
|
490
|
+
...panResponder == null ? void 0 : panResponder.panHandlers,
|
|
491
|
+
onLayout: (e) => {
|
|
492
|
+
const next = e.nativeEvent.layout.height;
|
|
493
|
+
setFrameSize((prev) => {
|
|
494
|
+
const isBigChange = Math.abs(prev - next) > 50;
|
|
495
|
+
setIsResizing(isBigChange);
|
|
496
|
+
return next;
|
|
497
|
+
});
|
|
498
|
+
},
|
|
499
|
+
pointerEvents: open && !shouldHideParentSheet ? "auto" : "none",
|
|
500
|
+
style: [
|
|
501
|
+
{
|
|
502
|
+
position: "absolute",
|
|
503
|
+
zIndex,
|
|
504
|
+
width: "100%",
|
|
505
|
+
height: "100%",
|
|
506
|
+
opacity: shouldHideParentSheet ? 0 : 1
|
|
478
507
|
},
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
]
|
|
508
|
+
animatedStyle
|
|
509
|
+
],
|
|
510
|
+
children: [
|
|
511
|
+
handleComponent,
|
|
512
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
|
|
513
|
+
enabled: open && modal && handleDisableScroll,
|
|
514
|
+
as: import_core.Slot,
|
|
515
|
+
allowPinchZoom: true,
|
|
516
|
+
shards: [contentRef],
|
|
517
|
+
removeScrollBar: false,
|
|
518
|
+
children: isResizing ? null : frameComponent
|
|
519
|
+
})
|
|
520
|
+
]
|
|
521
|
+
})
|
|
522
|
+
]
|
|
523
|
+
})
|
|
524
|
+
});
|
|
525
|
+
if (modal) {
|
|
526
|
+
const modalContents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.Portal, {
|
|
527
|
+
zIndex,
|
|
528
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
529
|
+
name: themeName,
|
|
530
|
+
children: contents
|
|
503
531
|
})
|
|
504
532
|
});
|
|
505
|
-
if (
|
|
506
|
-
return
|
|
533
|
+
if (import_core.isWeb) {
|
|
534
|
+
return modalContents;
|
|
507
535
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
});
|
|
516
|
-
if (import_core.isWeb) {
|
|
517
|
-
return modalContents;
|
|
518
|
-
}
|
|
519
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetInsideSheetContext.Provider, {
|
|
520
|
-
value: onInnerSheet,
|
|
521
|
-
children: modalContents
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
return contents;
|
|
525
|
-
})
|
|
526
|
-
),
|
|
527
|
-
sheetComponents
|
|
536
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetInsideSheetContext.Provider, {
|
|
537
|
+
value: onInnerSheet,
|
|
538
|
+
children: modalContents
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
return contents;
|
|
542
|
+
})
|
|
528
543
|
);
|
|
529
544
|
const SheetInsideSheetContext = (0, import_react.createContext)(null);
|
|
530
545
|
const ControlledSheet = Sheet;
|