@tamagui/sheet 1.0.1-beta.151 → 1.0.1-beta.152
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 +386 -338
- package/dist/cjs/Sheet.js.map +2 -2
- package/dist/cjs/SheetContext.js +4 -1
- package/dist/cjs/SheetContext.js.map +1 -1
- package/dist/cjs/SheetScrollView.js +79 -79
- package/dist/cjs/SheetScrollView.js.map +1 -1
- package/dist/esm/Sheet.js +382 -337
- package/dist/esm/Sheet.js.map +2 -2
- package/dist/esm/SheetContext.js +4 -1
- package/dist/esm/SheetContext.js.map +1 -1
- package/dist/esm/SheetScrollView.js +79 -76
- package/dist/esm/SheetScrollView.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Sheet.js +331 -300
- package/dist/jsx/Sheet.js.map +2 -2
- package/dist/jsx/SheetContext.js +4 -1
- package/dist/jsx/SheetContext.js.map +1 -1
- package/dist/jsx/SheetScrollView.js +68 -66
- package/dist/jsx/SheetScrollView.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/package.json +9 -9
package/dist/esm/Sheet.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
2
|
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
3
|
import {
|
|
3
4
|
Slot,
|
|
@@ -57,18 +58,20 @@ const SheetHandleFrame = styled(XStack, {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
|
-
const SheetHandle = SheetHandleFrame.extractable(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
61
|
+
const SheetHandle = SheetHandleFrame.extractable(
|
|
62
|
+
({ __scopeSheet, ...props }) => {
|
|
63
|
+
const context = useSheetContext(SHEET_HANDLE_NAME, __scopeSheet);
|
|
64
|
+
return /* @__PURE__ */ jsx(SheetHandleFrame, {
|
|
65
|
+
onPress: () => {
|
|
66
|
+
const max = context.snapPoints.length + (context.dismissOnSnapToBottom ? -1 : 0);
|
|
67
|
+
const nextPos = (context.position + 1) % max;
|
|
68
|
+
context.setPosition(nextPos);
|
|
69
|
+
},
|
|
70
|
+
open: context.open,
|
|
71
|
+
...props
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
);
|
|
72
75
|
const SHEET_OVERLAY_NAME = "SheetOverlay";
|
|
73
76
|
const SheetOverlayFrame = styled(YStack, {
|
|
74
77
|
name: SHEET_OVERLAY_NAME,
|
|
@@ -88,16 +91,21 @@ const SheetOverlayFrame = styled(YStack, {
|
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
});
|
|
91
|
-
const SheetOverlay = SheetOverlayFrame.extractable(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
const SheetOverlay = SheetOverlayFrame.extractable(
|
|
95
|
+
({ __scopeSheet, ...props }) => {
|
|
96
|
+
const context = useSheetContext(SHEET_OVERLAY_NAME, __scopeSheet);
|
|
97
|
+
return /* @__PURE__ */ jsx(SheetOverlayFrame, {
|
|
98
|
+
closed: !context.open || context.hidden,
|
|
99
|
+
...props,
|
|
100
|
+
onPress: mergeEvent(
|
|
101
|
+
props.onPress,
|
|
102
|
+
context.dismissOnOverlayPress ? () => {
|
|
103
|
+
context.setOpen(false);
|
|
104
|
+
} : void 0
|
|
105
|
+
)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
);
|
|
101
109
|
const selectionStyleSheet = isClient ? document.createElement("style") : null;
|
|
102
110
|
if (selectionStyleSheet) {
|
|
103
111
|
document.head.appendChild(selectionStyleSheet);
|
|
@@ -113,323 +121,356 @@ const SheetFrameFrame = styled(YStack, {
|
|
|
113
121
|
overflow: "hidden",
|
|
114
122
|
pointerEvents: "auto"
|
|
115
123
|
});
|
|
116
|
-
const SheetFrame = SheetFrameFrame.extractable(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
+
const SheetFrame = SheetFrameFrame.extractable(
|
|
125
|
+
forwardRef(({ __scopeSheet, ...props }, forwardedRef) => {
|
|
126
|
+
const context = useSheetContext(SHEET_NAME, __scopeSheet);
|
|
127
|
+
const composedContentRef = useComposedRefs(forwardedRef, context.contentRef);
|
|
128
|
+
return /* @__PURE__ */ jsx(SheetFrameFrame, {
|
|
129
|
+
ref: composedContentRef,
|
|
130
|
+
...props
|
|
131
|
+
});
|
|
132
|
+
})
|
|
133
|
+
);
|
|
124
134
|
const HIDDEN_SIZE = 1e4;
|
|
125
|
-
const Sheet = withStaticProperties(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const themeName = useThemeName();
|
|
156
|
-
const contentRef = React.useRef(null);
|
|
157
|
-
const scrollBridge = useConstant(() => ({
|
|
158
|
-
enabled: false,
|
|
159
|
-
y: 0,
|
|
160
|
-
paneY: 0,
|
|
161
|
-
paneMinY: 0,
|
|
162
|
-
scrollStartY: -1,
|
|
163
|
-
drag: () => {
|
|
164
|
-
},
|
|
165
|
-
release: () => {
|
|
166
|
-
},
|
|
167
|
-
scrollLock: false
|
|
168
|
-
}));
|
|
169
|
-
const onChangeOpenInternal = (val) => {
|
|
170
|
-
var _a;
|
|
171
|
-
(_a = controller == null ? void 0 : controller.onChangeOpen) == null ? void 0 : _a.call(controller, val);
|
|
172
|
-
onChangeOpen == null ? void 0 : onChangeOpen(val);
|
|
173
|
-
};
|
|
174
|
-
const [open, setOpen] = useControllableState({
|
|
175
|
-
prop: (controller == null ? void 0 : controller.open) ?? openProp,
|
|
176
|
-
defaultProp: defaultOpen || true,
|
|
177
|
-
onChange: onChangeOpenInternal,
|
|
178
|
-
strategy: "most-recent-wins"
|
|
179
|
-
});
|
|
180
|
-
const [frameSize, setFrameSize] = useState(0);
|
|
181
|
-
const snapPoints = useMemo(() => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp, [JSON.stringify(snapPointsProp), dismissOnSnapToBottom]);
|
|
182
|
-
const [position_, setPosition_] = useControllableState({
|
|
183
|
-
prop: positionProp,
|
|
184
|
-
defaultProp: defaultPosition || (open ? 0 : -1),
|
|
185
|
-
onChange: onChangePosition,
|
|
186
|
-
strategy: "most-recent-wins"
|
|
187
|
-
});
|
|
188
|
-
const position = open === false ? -1 : position_;
|
|
189
|
-
if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
|
|
190
|
-
setPosition_(0);
|
|
191
|
-
}
|
|
192
|
-
const setPosition = useCallback((next) => {
|
|
193
|
-
if (dismissOnSnapToBottom && next === snapPoints.length - 1) {
|
|
194
|
-
setOpen(false);
|
|
195
|
-
} else {
|
|
196
|
-
setPosition_(next);
|
|
197
|
-
}
|
|
198
|
-
}, [dismissOnSnapToBottom, snapPoints.length, setPosition_, setOpen]);
|
|
199
|
-
const animatedNumber = driver.useAnimatedNumber(HIDDEN_SIZE);
|
|
200
|
-
const at = useRef(0);
|
|
201
|
-
driver.useAnimatedNumberReaction(animatedNumber, (value) => {
|
|
202
|
-
at.current = value;
|
|
203
|
-
scrollBridge.paneY = value;
|
|
204
|
-
});
|
|
205
|
-
const [isResizing, setIsResizing] = useState(true);
|
|
206
|
-
useIsomorphicLayoutEffect(() => {
|
|
207
|
-
if (!isResizing) {
|
|
208
|
-
setIsResizing(true);
|
|
209
|
-
}
|
|
210
|
-
}, [modal]);
|
|
211
|
-
function stopSpring() {
|
|
212
|
-
animatedNumber.stop();
|
|
213
|
-
if (scrollBridge.onFinishAnimate) {
|
|
214
|
-
scrollBridge.onFinishAnimate();
|
|
215
|
-
scrollBridge.onFinishAnimate = void 0;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const shouldSetPositionOpen = open && position < 0;
|
|
219
|
-
useEffect(() => {
|
|
220
|
-
if (shouldSetPositionOpen) {
|
|
221
|
-
setPosition(0);
|
|
222
|
-
}
|
|
223
|
-
}, [setPosition, shouldSetPositionOpen]);
|
|
224
|
-
const positions = useMemo(() => snapPoints.map((point) => getPercentSize(point, frameSize)), [frameSize, snapPoints]);
|
|
225
|
-
const animateTo = useEvent((position2) => {
|
|
226
|
-
const current = animatedNumber.getValue();
|
|
227
|
-
if (isHidden && open)
|
|
228
|
-
return;
|
|
229
|
-
if (!current)
|
|
230
|
-
return;
|
|
231
|
-
if (frameSize === 0)
|
|
232
|
-
return;
|
|
233
|
-
const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : frameSize;
|
|
234
|
-
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
235
|
-
if (at.current === toValue)
|
|
236
|
-
return;
|
|
237
|
-
stopSpring();
|
|
238
|
-
if (isHidden || isResizing) {
|
|
239
|
-
if (isResizing) {
|
|
240
|
-
setIsResizing(false);
|
|
135
|
+
const Sheet = withStaticProperties(
|
|
136
|
+
themeable(
|
|
137
|
+
forwardRef(function Sheet2(props, ref) {
|
|
138
|
+
const {
|
|
139
|
+
__scopeSheet,
|
|
140
|
+
snapPoints: snapPointsProp = [80],
|
|
141
|
+
open: openProp,
|
|
142
|
+
defaultOpen,
|
|
143
|
+
children: childrenProp,
|
|
144
|
+
position: positionProp,
|
|
145
|
+
onChangePosition,
|
|
146
|
+
onChangeOpen,
|
|
147
|
+
defaultPosition,
|
|
148
|
+
dismissOnOverlayPress = true,
|
|
149
|
+
animationConfig,
|
|
150
|
+
dismissOnSnapToBottom = false,
|
|
151
|
+
disableDrag: disableDragProp,
|
|
152
|
+
modal = false,
|
|
153
|
+
handleDisableScroll = true
|
|
154
|
+
} = props;
|
|
155
|
+
if (process.env.NODE_ENV === "development") {
|
|
156
|
+
if (snapPointsProp.some((p) => p < 0 || p > 100)) {
|
|
157
|
+
console.warn(
|
|
158
|
+
`\u26A0\uFE0F Invalid snapPoint given, snapPoints must be between 0 and 100, equal to percent height of frame`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const driver = getAnimationDriver();
|
|
163
|
+
if (!driver) {
|
|
164
|
+
throw new Error(`Must set animations in tamagui.config.ts`);
|
|
241
165
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
166
|
+
const controller = useContext(SheetControllerContext);
|
|
167
|
+
const isHidden = (controller == null ? void 0 : controller.hidden) || false;
|
|
168
|
+
const disableDrag = disableDragProp ?? (controller == null ? void 0 : controller.disableDrag);
|
|
169
|
+
const themeName = useThemeName();
|
|
170
|
+
const contentRef = React.useRef(null);
|
|
171
|
+
const scrollBridge = useConstant(() => ({
|
|
172
|
+
enabled: false,
|
|
173
|
+
y: 0,
|
|
174
|
+
paneY: 0,
|
|
175
|
+
paneMinY: 0,
|
|
176
|
+
scrollStartY: -1,
|
|
177
|
+
drag: () => {
|
|
178
|
+
},
|
|
179
|
+
release: () => {
|
|
180
|
+
},
|
|
181
|
+
scrollLock: false
|
|
182
|
+
}));
|
|
183
|
+
const onChangeOpenInternal = (val) => {
|
|
184
|
+
var _a;
|
|
185
|
+
(_a = controller == null ? void 0 : controller.onChangeOpen) == null ? void 0 : _a.call(controller, val);
|
|
186
|
+
onChangeOpen == null ? void 0 : onChangeOpen(val);
|
|
187
|
+
};
|
|
188
|
+
const [open, setOpen] = useControllableState({
|
|
189
|
+
prop: (controller == null ? void 0 : controller.open) ?? openProp,
|
|
190
|
+
defaultProp: defaultOpen || true,
|
|
191
|
+
onChange: onChangeOpenInternal,
|
|
192
|
+
strategy: "most-recent-wins"
|
|
245
193
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (disableDrag)
|
|
261
|
-
return;
|
|
262
|
-
if (!frameSize)
|
|
263
|
-
return;
|
|
264
|
-
const minY = positions[0];
|
|
265
|
-
scrollBridge.paneMinY = minY;
|
|
266
|
-
let startY = at.current;
|
|
267
|
-
function makeUnselectable(val) {
|
|
268
|
-
if (!selectionStyleSheet)
|
|
269
|
-
return;
|
|
270
|
-
if (!val) {
|
|
271
|
-
selectionStyleSheet.innerText = ``;
|
|
272
|
-
} else {
|
|
273
|
-
selectionStyleSheet.innerText = `:root * { user-select: none !important; -webkit-user-select: none !important; }`;
|
|
194
|
+
const [frameSize, setFrameSize] = useState(0);
|
|
195
|
+
const snapPoints = useMemo(
|
|
196
|
+
() => dismissOnSnapToBottom ? [...snapPointsProp, 0] : snapPointsProp,
|
|
197
|
+
[JSON.stringify(snapPointsProp), dismissOnSnapToBottom]
|
|
198
|
+
);
|
|
199
|
+
const [position_, setPosition_] = useControllableState({
|
|
200
|
+
prop: positionProp,
|
|
201
|
+
defaultProp: defaultPosition || (open ? 0 : -1),
|
|
202
|
+
onChange: onChangePosition,
|
|
203
|
+
strategy: "most-recent-wins"
|
|
204
|
+
});
|
|
205
|
+
const position = open === false ? -1 : position_;
|
|
206
|
+
if (open && dismissOnSnapToBottom && position === snapPoints.length - 1) {
|
|
207
|
+
setPosition_(0);
|
|
274
208
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
209
|
+
const setPosition = useCallback(
|
|
210
|
+
(next) => {
|
|
211
|
+
if (dismissOnSnapToBottom && next === snapPoints.length - 1) {
|
|
212
|
+
setOpen(false);
|
|
213
|
+
} else {
|
|
214
|
+
setPosition_(next);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
[dismissOnSnapToBottom, snapPoints.length, setPosition_, setOpen]
|
|
218
|
+
);
|
|
219
|
+
const animatedNumber = driver.useAnimatedNumber(HIDDEN_SIZE);
|
|
220
|
+
const at = useRef(0);
|
|
221
|
+
driver.useAnimatedNumberReaction(animatedNumber, (value) => {
|
|
222
|
+
at.current = value;
|
|
223
|
+
scrollBridge.paneY = value;
|
|
224
|
+
});
|
|
225
|
+
const [isResizing, setIsResizing] = useState(true);
|
|
226
|
+
useIsomorphicLayoutEffect(() => {
|
|
227
|
+
if (!isResizing) {
|
|
228
|
+
setIsResizing(true);
|
|
229
|
+
}
|
|
230
|
+
}, [modal]);
|
|
231
|
+
function stopSpring() {
|
|
232
|
+
animatedNumber.stop();
|
|
233
|
+
if (scrollBridge.onFinishAnimate) {
|
|
234
|
+
scrollBridge.onFinishAnimate();
|
|
235
|
+
scrollBridge.onFinishAnimate = void 0;
|
|
290
236
|
}
|
|
291
237
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
238
|
+
const shouldSetPositionOpen = open && position < 0;
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (shouldSetPositionOpen) {
|
|
241
|
+
setPosition(0);
|
|
242
|
+
}
|
|
243
|
+
}, [setPosition, shouldSetPositionOpen]);
|
|
244
|
+
const positions = useMemo(
|
|
245
|
+
() => snapPoints.map((point) => getPercentSize(point, frameSize)),
|
|
246
|
+
[frameSize, snapPoints]
|
|
247
|
+
);
|
|
248
|
+
const animateTo = useEvent((position2) => {
|
|
249
|
+
const current = animatedNumber.getValue();
|
|
250
|
+
if (isHidden && open)
|
|
251
|
+
return;
|
|
252
|
+
if (!current)
|
|
253
|
+
return;
|
|
254
|
+
if (frameSize === 0)
|
|
255
|
+
return;
|
|
256
|
+
const hiddenValue = frameSize === 0 ? HIDDEN_SIZE : frameSize;
|
|
257
|
+
const toValue = isHidden || position2 === -1 ? hiddenValue : positions[position2];
|
|
258
|
+
if (at.current === toValue)
|
|
259
|
+
return;
|
|
260
|
+
stopSpring();
|
|
261
|
+
if (isHidden || isResizing) {
|
|
262
|
+
if (isResizing) {
|
|
263
|
+
setIsResizing(false);
|
|
264
|
+
}
|
|
265
|
+
animatedNumber.setValue(toValue, {
|
|
266
|
+
type: "timing",
|
|
267
|
+
duration: 0
|
|
268
|
+
});
|
|
269
|
+
at.current = toValue;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const overshootClamping = at.current === HIDDEN_SIZE;
|
|
273
|
+
animatedNumber.setValue(toValue, {
|
|
274
|
+
...animationConfig,
|
|
275
|
+
type: "spring",
|
|
276
|
+
overshootClamping
|
|
277
|
+
});
|
|
299
278
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
279
|
+
useIsomorphicLayoutEffect(() => {
|
|
280
|
+
animateTo(position);
|
|
281
|
+
}, [isHidden, frameSize, position, animateTo]);
|
|
282
|
+
const panResponder = useMemo(
|
|
283
|
+
() => {
|
|
284
|
+
if (disableDrag)
|
|
285
|
+
return;
|
|
286
|
+
if (!frameSize)
|
|
287
|
+
return;
|
|
288
|
+
const minY = positions[0];
|
|
289
|
+
scrollBridge.paneMinY = minY;
|
|
290
|
+
let startY = at.current;
|
|
291
|
+
function makeUnselectable(val) {
|
|
292
|
+
if (!selectionStyleSheet)
|
|
293
|
+
return;
|
|
294
|
+
if (!val) {
|
|
295
|
+
selectionStyleSheet.innerText = ``;
|
|
296
|
+
} else {
|
|
297
|
+
selectionStyleSheet.innerText = `:root * { user-select: none !important; -webkit-user-select: none !important; }`;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const release = ({ vy, dragAt }) => {
|
|
301
|
+
isExternalDrag = false;
|
|
302
|
+
previouslyScrolling = false;
|
|
303
|
+
makeUnselectable(false);
|
|
304
|
+
const at2 = dragAt + startY;
|
|
305
|
+
const end = at2 + frameSize * vy * 0.2;
|
|
306
|
+
let closestPoint = 0;
|
|
307
|
+
let dist = Infinity;
|
|
308
|
+
for (let i = 0; i < positions.length; i++) {
|
|
309
|
+
const position2 = positions[i];
|
|
310
|
+
const curDist = end > position2 ? end - position2 : position2 - end;
|
|
311
|
+
if (curDist < dist) {
|
|
312
|
+
dist = curDist;
|
|
313
|
+
closestPoint = i;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
setPosition(closestPoint);
|
|
317
|
+
animateTo(closestPoint);
|
|
318
|
+
};
|
|
319
|
+
const finish = (_e, state) => {
|
|
320
|
+
release({
|
|
321
|
+
vy: state.vy,
|
|
322
|
+
dragAt: state.dy
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
let previouslyScrolling = false;
|
|
326
|
+
const onMoveShouldSet = (_e, { dy }) => {
|
|
327
|
+
const isScrolled = scrollBridge.y !== 0;
|
|
328
|
+
if (isScrolled) {
|
|
329
|
+
previouslyScrolling = true;
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (previouslyScrolling) {
|
|
333
|
+
previouslyScrolling = false;
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
const isDraggingUp = dy < 0;
|
|
337
|
+
const isAtTop = scrollBridge.paneY <= scrollBridge.paneMinY;
|
|
338
|
+
if (isAtTop) {
|
|
339
|
+
if (!isScrolled && isDraggingUp) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return Math.abs(dy) > 8;
|
|
344
|
+
};
|
|
345
|
+
const grant = () => {
|
|
346
|
+
makeUnselectable(true);
|
|
347
|
+
stopSpring();
|
|
348
|
+
startY = at.current;
|
|
349
|
+
};
|
|
350
|
+
let isExternalDrag = false;
|
|
351
|
+
scrollBridge.drag = (dy) => {
|
|
352
|
+
if (!isExternalDrag) {
|
|
353
|
+
isExternalDrag = true;
|
|
354
|
+
grant();
|
|
355
|
+
}
|
|
356
|
+
const to = dy + startY;
|
|
357
|
+
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
358
|
+
};
|
|
359
|
+
scrollBridge.release = release;
|
|
360
|
+
return PanResponder.create({
|
|
361
|
+
onMoveShouldSetPanResponder: onMoveShouldSet,
|
|
362
|
+
onPanResponderGrant: grant,
|
|
363
|
+
onPanResponderMove: (_e, { dy }) => {
|
|
364
|
+
const to = dy + startY;
|
|
365
|
+
animatedNumber.setValue(resisted(to, minY), { type: "direct" });
|
|
366
|
+
},
|
|
367
|
+
onPanResponderEnd: finish,
|
|
368
|
+
onPanResponderTerminate: finish,
|
|
369
|
+
onPanResponderRelease: finish
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
[disableDrag, animateTo, frameSize, positions, setPosition]
|
|
373
|
+
);
|
|
374
|
+
let handleComponent = null;
|
|
375
|
+
let overlayComponent = null;
|
|
376
|
+
let frameComponent = null;
|
|
377
|
+
React.Children.forEach(childrenProp, (child) => {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
if (isValidElement(child)) {
|
|
380
|
+
const name = (_b = (_a = child.type) == null ? void 0 : _a["staticConfig"]) == null ? void 0 : _b.componentName;
|
|
381
|
+
switch (name) {
|
|
382
|
+
case "SheetHandle":
|
|
383
|
+
handleComponent = child;
|
|
384
|
+
break;
|
|
385
|
+
case "Sheet":
|
|
386
|
+
frameComponent = child;
|
|
387
|
+
break;
|
|
388
|
+
case "SheetOverlay":
|
|
389
|
+
overlayComponent = child;
|
|
390
|
+
break;
|
|
391
|
+
default:
|
|
392
|
+
console.warn("Warning: passed invalid child to Sheet", child);
|
|
393
|
+
}
|
|
317
394
|
}
|
|
395
|
+
});
|
|
396
|
+
const preventShown = (controller == null ? void 0 : controller.hidden) && (controller == null ? void 0 : controller.open);
|
|
397
|
+
const animatedStyle = driver.useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
398
|
+
return {
|
|
399
|
+
transform: [{ translateY: frameSize === 0 ? HIDDEN_SIZE : val }]
|
|
400
|
+
};
|
|
401
|
+
});
|
|
402
|
+
if (preventShown) {
|
|
403
|
+
return null;
|
|
318
404
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
370
|
-
const preventShown = (controller == null ? void 0 : controller.hidden) && (controller == null ? void 0 : controller.open);
|
|
371
|
-
const animatedStyle = driver.useAnimatedNumberStyle(animatedNumber, (val) => {
|
|
372
|
-
return {
|
|
373
|
-
transform: [{ translateY: frameSize === 0 ? HIDDEN_SIZE : val }]
|
|
374
|
-
};
|
|
375
|
-
});
|
|
376
|
-
if (preventShown) {
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
const AnimatedView = driver["NumberView"] ?? driver.View;
|
|
380
|
-
const contents = /* @__PURE__ */ React.createElement(SheetProvider, {
|
|
381
|
-
modal,
|
|
382
|
-
contentRef,
|
|
383
|
-
dismissOnOverlayPress,
|
|
384
|
-
dismissOnSnapToBottom,
|
|
385
|
-
open,
|
|
386
|
-
hidden: isHidden,
|
|
387
|
-
scope: __scopeSheet,
|
|
388
|
-
position,
|
|
389
|
-
snapPoints,
|
|
390
|
-
setPosition,
|
|
391
|
-
setOpen,
|
|
392
|
-
scrollBridge
|
|
393
|
-
}, isResizing ? null : overlayComponent, /* @__PURE__ */ React.createElement(AnimatedView, {
|
|
394
|
-
ref,
|
|
395
|
-
...panResponder == null ? void 0 : panResponder.panHandlers,
|
|
396
|
-
onLayout: (e) => {
|
|
397
|
-
const next = e.nativeEvent.layout.height;
|
|
398
|
-
setFrameSize((prev) => {
|
|
399
|
-
const isBigChange = Math.abs(prev - next) > 50;
|
|
400
|
-
setIsResizing(isBigChange);
|
|
401
|
-
return next;
|
|
405
|
+
const AnimatedView = driver["NumberView"] ?? driver.View;
|
|
406
|
+
const contents = /* @__PURE__ */ jsxs(SheetProvider, {
|
|
407
|
+
modal,
|
|
408
|
+
contentRef,
|
|
409
|
+
dismissOnOverlayPress,
|
|
410
|
+
dismissOnSnapToBottom,
|
|
411
|
+
open,
|
|
412
|
+
hidden: isHidden,
|
|
413
|
+
scope: __scopeSheet,
|
|
414
|
+
position,
|
|
415
|
+
snapPoints,
|
|
416
|
+
setPosition,
|
|
417
|
+
setOpen,
|
|
418
|
+
scrollBridge,
|
|
419
|
+
children: [
|
|
420
|
+
isResizing ? null : overlayComponent,
|
|
421
|
+
/* @__PURE__ */ jsxs(AnimatedView, {
|
|
422
|
+
ref,
|
|
423
|
+
...panResponder == null ? void 0 : panResponder.panHandlers,
|
|
424
|
+
onLayout: (e) => {
|
|
425
|
+
const next = e.nativeEvent.layout.height;
|
|
426
|
+
setFrameSize((prev) => {
|
|
427
|
+
const isBigChange = Math.abs(prev - next) > 50;
|
|
428
|
+
setIsResizing(isBigChange);
|
|
429
|
+
return next;
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
pointerEvents: open ? "auto" : "none",
|
|
433
|
+
style: [
|
|
434
|
+
{
|
|
435
|
+
position: "absolute",
|
|
436
|
+
zIndex: 10,
|
|
437
|
+
width: "100%",
|
|
438
|
+
height: "100%"
|
|
439
|
+
},
|
|
440
|
+
animatedStyle
|
|
441
|
+
],
|
|
442
|
+
children: [
|
|
443
|
+
handleComponent,
|
|
444
|
+
/* @__PURE__ */ jsx(RemoveScroll, {
|
|
445
|
+
enabled: open && modal && handleDisableScroll,
|
|
446
|
+
as: Slot,
|
|
447
|
+
allowPinchZoom: true,
|
|
448
|
+
shards: [contentRef],
|
|
449
|
+
removeScrollBar: false,
|
|
450
|
+
children: isResizing ? null : frameComponent
|
|
451
|
+
})
|
|
452
|
+
]
|
|
453
|
+
})
|
|
454
|
+
]
|
|
402
455
|
});
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
removeScrollBar: false
|
|
420
|
-
}, isResizing ? null : frameComponent)));
|
|
421
|
-
if (modal) {
|
|
422
|
-
return /* @__PURE__ */ React.createElement(Portal, null, /* @__PURE__ */ React.createElement(Theme, {
|
|
423
|
-
name: themeName
|
|
424
|
-
}, contents));
|
|
456
|
+
if (modal) {
|
|
457
|
+
return /* @__PURE__ */ jsx(Portal, {
|
|
458
|
+
children: /* @__PURE__ */ jsx(Theme, {
|
|
459
|
+
name: themeName,
|
|
460
|
+
children: contents
|
|
461
|
+
})
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
return contents;
|
|
465
|
+
})
|
|
466
|
+
),
|
|
467
|
+
{
|
|
468
|
+
Handle: SheetHandle,
|
|
469
|
+
Frame: SheetFrame,
|
|
470
|
+
Overlay: SheetOverlay,
|
|
471
|
+
ScrollView: SheetScrollView
|
|
425
472
|
}
|
|
426
|
-
|
|
427
|
-
})), {
|
|
428
|
-
Handle: SheetHandle,
|
|
429
|
-
Frame: SheetFrame,
|
|
430
|
-
Overlay: SheetOverlay,
|
|
431
|
-
ScrollView: SheetScrollView
|
|
432
|
-
});
|
|
473
|
+
);
|
|
433
474
|
function getPercentSize(point, frameSize) {
|
|
434
475
|
if (!frameSize)
|
|
435
476
|
return 0;
|
|
@@ -458,15 +499,19 @@ const SheetController = ({
|
|
|
458
499
|
...value
|
|
459
500
|
}) => {
|
|
460
501
|
const onChangeOpen = useEvent(onChangeOpenProp);
|
|
461
|
-
const memoValue = useMemo(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
value
|
|
469
|
-
|
|
502
|
+
const memoValue = useMemo(
|
|
503
|
+
() => ({
|
|
504
|
+
open: value.open,
|
|
505
|
+
hidden: value.hidden,
|
|
506
|
+
disableDrag: value.disableDrag,
|
|
507
|
+
onChangeOpen
|
|
508
|
+
}),
|
|
509
|
+
[onChangeOpen, value.open, value.hidden, value.disableDrag]
|
|
510
|
+
);
|
|
511
|
+
return /* @__PURE__ */ jsx(SheetControllerContext.Provider, {
|
|
512
|
+
value: memoValue,
|
|
513
|
+
children
|
|
514
|
+
});
|
|
470
515
|
};
|
|
471
516
|
export {
|
|
472
517
|
Sheet,
|