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