251
252
function useComposerRestingTransition(
253
isCollapsed: boolean,
254
+ isResting: boolean,
255
restingControlsRef: React.RefObject<HTMLDivElement | null>,
256
onOverlayHeightChange: (height: number) => void,
257
) {
258
const elementRef = useRef<HTMLDivElement>(null);
259
const isCollapsedRef = useRef(isCollapsed);
260
const previousCollapsedRef = useRef(isCollapsed);
261
+ const previousRestingRef = useRef(isResting);
262
const previousHeightRef = useRef<number | null>(null);
263
const previousContentOffsetsRef = useRef<{
264
promptFromTop: number | null;
357
358
const nextRect = element.getBoundingClientRect();
359
const nextHeight = nextRect.height;
360
+ // The chat view resize-observes the overlay to place the timeline
361
+ // inset, the scroll-to-end pill, and the mini player. Publishing the
362
+ // destination height here turns that feedback into one update instead
363
+ // of a ChatView re-render on every animation frame.
364
+ const overlay = element.closest<HTMLElement>('[data-chat-composer-overlay="true"]');
365
+ const overlayHeight = overlay?.getBoundingClientRect().height ?? null;
366
+ if (overlayHeight !== null) {
367
+ onOverlayHeightChange(overlayHeight);
368
+ }
369
const nextPromptRect = prompt?.getBoundingClientRect() ?? null;
370
const nextPromptTop = nextPromptRect?.top ?? null;
371
const nextActionTop = action?.getBoundingClientRect().top ?? null;
396
element.style.overflow = "clip";
397
surface.style.height = "100%";
398
388
- // The chat view resize-observes the overlay to place the timeline
389
- // inset, the scroll-to-end pill, and the mini player. Pinning the
390
- // overlay at the destination height turns that feedback into one
391
- // update instead of a ChatView re-render on every animation frame;
392
- // bottom alignment keeps the animating surface glued to the overlay's
393
- // stable bottom edge. The pin lasts only for the tween so later
394
- // attachment, thread, font, and viewport changes remain natural.
395
- const overlay = element.closest<HTMLElement>('[data-chat-composer-overlay="true"]');
396
- let pinnedOverlayHeight: number | null = null;
397
- if (overlay) {
398
- pinnedOverlayHeight = overlay.getBoundingClientRect().height;
399
- overlay.style.height = `${String(pinnedOverlayHeight)}px`;
399
+ // Pinning the overlay at the destination height keeps the resize
400
+ // observer quiet for the tween; bottom alignment keeps the animating
401
+ // surface glued to the overlay's stable bottom edge. The pin lasts
402
+ // only for the tween so later attachment, thread, font, and viewport
403
+ // changes remain natural.
404
+ if (overlay && overlayHeight !== null) {
405
+ overlay.style.height = `${String(overlayHeight)}px`;
406
overlay.style.display = "flex";
407
overlay.style.flexDirection = "column";
408
overlay.style.justifyContent = "flex-end";
436
);
437
animationRef.current = animation;
438
animationTargetHeightRef.current = nextHeight;
433
- // Publish the destination overlay geometry in the same layout pass;
434
- // ResizeObserver remains the fallback for non-transition changes.
435
- if (pinnedOverlayHeight !== null) {
436
- onOverlayHeightChange(pinnedOverlayHeight);
437
- }
439
440
const animatedRect = element.getBoundingClientRect();
441
const previousPromptTop =
613
};
614
}, [isCollapsed, transitionToCurrentGeometry]);
615
616
+ // The resting flag can change while the collapsed layout stays the same,
617
+ // for example when an unfocused thread crosses the phone breakpoint. The
618
+ // chat view pairs overlay heights with that flag, so republish the natural
619
+ // height for the new flag. A transition in flight publishes its own.
620
+ useLayoutEffect(() => {
621
+ if (previousRestingRef.current === isResting) return;
622
+ previousRestingRef.current = isResting;
623
+ if (animationRef.current) return;
624
+ const overlay = elementRef.current?.closest<HTMLElement>('[data-chat-composer-overlay="true"]');
625
+ if (overlay) onOverlayHeightChange(overlay.getBoundingClientRect().height);
626
+ }, [isResting, onOverlayHeightChange]);
627
+
628
useLayoutEffect(() => {
629
const element = elementRef.current;
630
if (!element || typeof ResizeObserver === "undefined") return;
1245
getTimelineScrollableNode: () => HTMLElement | null;
1246
isTimelineAtLogicalEnd: () => boolean;
1247
onComposerOverlayHeightChange: (height: number) => void;
1248
+ /**
1249
+ * Whether the desktop resting layout is active. Reported from a layout
1250
+ * effect, so it is current before the chat view measures the overlay.
1251
+ */
1252
+ onRestingChange: (resting: boolean) => void;
1253
1254
// Refs the parent needs kept in sync
1255
promptRef: React.RefObject<string>;
1354
getTimelineScrollableNode,
1355
isTimelineAtLogicalEnd,
1356
onComposerOverlayHeightChange,
1357
+ onRestingChange,
1358
promptRef,
1359
composerRef,
1360
composerImagesRef,
3603
useLayoutEffect(() => {
3604
onRestingControlsVisibilityChange(composerControlsVisibleInStrip);
3605
}, [composerControlsVisibleInStrip, onRestingControlsVisibilityChange]);
3606
+ useLayoutEffect(() => {
3607
+ onRestingChange(isComposerResting);
3608
+ }, [isComposerResting, onRestingChange]);
3609
const restingImagePreviewCounts = getRestingComposerImagePreviewCounts(
3610
standaloneComposerImages.length,
3611
);
3661
) : null;
3662
const composerMainSurfaceRef = useComposerRestingTransition(
3663
composerControlsInStrip,
3664
+ isComposerResting,
3665
restingComposerControlsRef,
3666
onComposerOverlayHeightChange,
3667
);