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