@expofp/ui 3.49.1 → 3.49.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,10 @@ export interface OverlayProps {
9
9
  particles?: ReactNode;
10
10
  className?: string;
11
11
  smallSizeMultiplier?: number;
12
+ /**
13
+ * Mobile medium height is `viewportHeight / mediumSizeMultiplier`, or taller to show
14
+ * a `[data-sheet-peek]` element in the content whole (never above full).
15
+ */
12
16
  mediumSizeMultiplier?: number;
13
17
  fullSizeOffset?: number;
14
18
  scrollThreshold?: number;
@@ -24,6 +24,24 @@ const generateSizes = (height = getActualViewportHeight(), smallMultiplier, medi
24
24
  medium: height / mediumMultiplier,
25
25
  full: height - fullSizeOffset,
26
26
  });
27
+ /**
28
+ * The snap point: the sheet's own choice, replaced by the host's `size` whenever that changes
29
+ * (details open at full, the planner at medium). The sheet's own reports come back through the
30
+ * prop too, already applied.
31
+ *
32
+ * The prop is followed during render, not from an effect. The host swaps the content in the same
33
+ * commit as the size, and the resize that swap causes has to find the snap point already moved:
34
+ * the peek observer asks whether the sheet is at full.
35
+ */
36
+ const useSnapPoint = (size) => {
37
+ const [snap, setSnap] = useState(size);
38
+ const [hostSize, setHostSize] = useState(size);
39
+ if (size !== hostSize) {
40
+ setHostSize(size);
41
+ setSnap(size);
42
+ }
43
+ return [snap, setSnap];
44
+ };
27
45
  const Overlay = ({ children, open, size = 'medium', particles, className, onChangeSize, onScrollStateChange, onScrollActivity, smallSizeMultiplier = 12.6, mediumSizeMultiplier = 2.6, fullSizeOffset = 0, scrollThreshold = DEFAULT_SCROLL_THRESHOLD, disableDrag = false, forceFull = false, scrollResetKey, mobileBreakpoint = DEFAULT_MOBILE_BREAKPOINT, noContentLabel, withFloatingButton = false, }) => {
28
46
  const { width: windowWidth, height: windowHeight } = useWindowSize();
29
47
  // Pure derivations of the window size — computed in render, not stored/synced via an effect.
@@ -32,19 +50,23 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
32
50
  // The on-screen keyboard covers the sheet without resizing the window (#1567):
33
51
  // give up the height the keyboard took, and let the content scroll clear of it.
34
52
  const keyboardInset = useKeyboardInset(mobile);
53
+ // Height from the sheet top to the bottom of the `[data-sheet-peek]` block: the part
54
+ // of the content the medium sheet must show whole. 0 when no such block.
55
+ const [peekHeight, setPeekHeight] = useState(0);
35
56
  // What the sheet can show right now. Snap points and visible heights must
36
57
  // come from the same numbers, or a drag lands where the sheet is not.
37
58
  const effectiveSizes = useMemo(() => {
38
- if (keyboardInset <= 0)
39
- return sizes;
40
59
  // Never below the smallest snap point: a collapsed sheet reads as a white screen.
41
60
  const full = Math.max(sizes.full - keyboardInset, sizes.small);
61
+ const medium = Math.max(sizes.medium, peekHeight);
62
+ if (keyboardInset <= 0 && medium === sizes.medium)
63
+ return sizes;
42
64
  return {
43
65
  small: Math.min(sizes.small, full),
44
- medium: Math.min(sizes.medium, full),
66
+ medium: Math.min(medium, full),
45
67
  full,
46
68
  };
47
- }, [sizes, keyboardInset]);
69
+ }, [sizes, keyboardInset, peekHeight]);
48
70
  const [dragging, setDragging] = useState(false);
49
71
  // The sheet is at zero height: closed, or mounted and about to animate open.
50
72
  const [collapsed, setCollapsed] = useState(!open);
@@ -53,6 +75,7 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
53
75
  const [isScrolled, setIsScrolled] = useState(false);
54
76
  const overlayPanelRef = useRef(null);
55
77
  const scrollRef = useRef(null);
78
+ const contentRef = useRef(null);
56
79
  const openedAtRef = useRef(undefined);
57
80
  // The scroll container is published to descendants through context, and context is read during
58
81
  // render — where a ref is still null on the render that mounts the element. Held as state as
@@ -67,7 +90,7 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
67
90
  const [headerElement, setHeaderElement] = useState(null);
68
91
  // The snap point the sheet actually sits on. The prop may be undefined
69
92
  // before the host has chosen one, and a drag needs a value to start from.
70
- const [currentSnap, setCurrentSnap] = useState(size);
93
+ const [currentSnap, setCurrentSnap] = useSnapPoint(size);
71
94
  // Mirror for the identity-stable callbacks below. Written after paint, not
72
95
  // during render, so a concurrent re-render cannot observe a torn value.
73
96
  const snapRef = useRef(currentSnap);
@@ -85,7 +108,7 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
85
108
  setCurrentSnap(newSize);
86
109
  setCollapsed(false);
87
110
  onChangeSizeRef.current?.(newSize);
88
- }, []);
111
+ }, [setCurrentSnap]);
89
112
  const positioningStyles = useMemo(() => {
90
113
  if (mobile) {
91
114
  // The sheet stays on the bottom edge and runs on under the keyboard. A
@@ -218,11 +241,42 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
218
241
  }, 10);
219
242
  return () => clearTimeout(timer);
220
243
  }, [open, shouldRender, setSize]);
221
- // Host-driven size changes (details open at full, the planner at medium).
222
- // The sheet's own reports come back through here too, already applied.
244
+ // Tracks `peekHeight`. The content box changes size when the peek block comes or goes.
245
+ // Content may drop the block at full and bring it back at medium; the last height
246
+ // is kept at full, so a drag down lands on it instead of growing after the snap.
223
247
  useEffect(() => {
224
- setCurrentSnap(size);
225
- }, [size]);
248
+ const content = contentRef.current;
249
+ if (!mobile || !shouldRender || !content || typeof ResizeObserver !== 'function') {
250
+ setPeekHeight(0);
251
+ return;
252
+ }
253
+ const observer = new ResizeObserver(() => {
254
+ const panel = overlayPanelRef.current;
255
+ const peek = content.querySelector('[data-sheet-peek]');
256
+ if (!panel || !peek) {
257
+ if (snapRef.current !== 'full')
258
+ setPeekHeight(0);
259
+ return;
260
+ }
261
+ observer.observe(peek);
262
+ const scrollTop = scrollRef.current?.scrollTop ?? 0;
263
+ const height = peek.getBoundingClientRect().bottom - panel.getBoundingClientRect().top + scrollTop;
264
+ setPeekHeight(Math.ceil(height));
265
+ });
266
+ observer.observe(content);
267
+ return () => observer.disconnect();
268
+ }, [mobile, shouldRender]);
269
+ // Off full, a kept height is stale when the content has no peek block. Checked a
270
+ // frame late: the host swaps the content in after it hears of the new size.
271
+ useEffect(() => {
272
+ if (currentSnap === 'full')
273
+ return;
274
+ const frame = requestAnimationFrame(() => {
275
+ if (!contentRef.current?.querySelector('[data-sheet-peek]'))
276
+ setPeekHeight(0);
277
+ });
278
+ return () => cancelAnimationFrame(frame);
279
+ }, [currentSnap]);
226
280
  useEffect(() => {
227
281
  if (open && !isAnimating) {
228
282
  scrollRef.current?.scrollTo({ top: 0 });
@@ -245,6 +299,6 @@ const Overlay = ({ children, open, size = 'medium', particles, className, onChan
245
299
  }, className), style: positioningStyles, ref: overlayPanelRef, onPointerDown: onPointerDown, children: [!disableDrag && _jsx("div", { className: "efp-overlay__draghandle", "data-sheet-handle": true }), _jsx("div", { className: "efp-overlay__header", ref: setHeaderElement }), _jsxs("div", { className: "efp-overlay__scroll", style: scrollStyles, ref: attachScroll, onScroll: () => {
246
300
  handleScroll();
247
301
  debouncedScrollActivity();
248
- }, children: [particles, _jsx("div", { className: "efp-overlay__content", children: _jsx(OverlayHeaderContext, { value: headerElement, children: _jsx(OverlayKeyboardInsetContext, { value: mobile ? keyboardInset : 0, children: children ? children : noContentLabel }) }) })] })] }) }));
302
+ }, children: [particles, _jsx("div", { className: "efp-overlay__content", ref: contentRef, children: _jsx(OverlayHeaderContext, { value: headerElement, children: _jsx(OverlayKeyboardInsetContext, { value: mobile ? keyboardInset : 0, children: children ? children : noContentLabel }) }) })] })] }) }));
249
303
  };
250
304
  export default Overlay;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expofp/ui",
3
- "version": "3.49.1",
3
+ "version": "3.49.2",
4
4
  "type": "module",
5
5
  "description": "ExpoFP SDK internal: shared pure React UI components",
6
6
  "homepage": "https://developer.expofp.com/",