diff --git a/apps/mobile/src/features/threads/ComposerCommandPopover.tsx b/apps/mobile/src/features/threads/ComposerCommandPopover.tsx index 13f0bbde955ee..8fba12472f398 100644 --- a/apps/mobile/src/features/threads/ComposerCommandPopover.tsx +++ b/apps/mobile/src/features/threads/ComposerCommandPopover.tsx @@ -88,19 +88,26 @@ interface ComposerCommandPopoverProps { readonly triggerKind: ComposerTriggerKind | null; readonly isLoading: boolean; readonly error?: string | null; + /** Clear glass reads over the feed; over the composer's own text it needs the frosted style. */ + readonly overlapsComposer?: boolean; readonly onSelect: (item: ComposerCommandItem) => void; } -function PopoverSurface(props: { readonly children: React.ReactNode; readonly style?: ViewStyle }) { +function PopoverSurface(props: { + readonly children: React.ReactNode; + readonly frosted: boolean; + readonly style?: ViewStyle; +}) { const baseStyle: ViewStyle = { borderRadius: 16, overflow: "hidden", + flexShrink: 1, ...props.style, }; return ( @@ -239,7 +246,7 @@ export const ComposerCommandPopover = memo(function ComposerCommandPopover( const label = groupLabel(props.triggerKind, props.items); return ( - + {label ? ( @@ -249,7 +256,7 @@ export const ComposerCommandPopover = memo(function ComposerCommandPopover( ) : null} {props.items.length > 0 ? ( diff --git a/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx b/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx index 54ccaec0d29e0..e0fa0909b001a 100644 --- a/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx +++ b/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx @@ -2,18 +2,26 @@ import type { ReactNode } from "react"; import { useEffect, useRef, useState } from "react"; import { View, type ViewInstance } from "react-native"; -import { useComposerPopoverHost } from "./ComposerPopoverHost"; - -const COMPOSER_GAP = 8; +import { + COMPOSER_POPOVER_GAP, + composerPopoverPlacement, + useComposerPopoverHost, +} from "./ComposerPopoverHost"; type Frame = { readonly x: number; readonly y: number; readonly width: number }; /** Android only delivers drags inside parent bounds; bottom-full popover lists cannot scroll. */ -export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) { +export function ComposerPopoverAnchor(props: { + readonly children: (overlapsComposer: boolean) => ReactNode; +}) { const host = useComposerPopoverHost(); const anchorRef = useRef(null); const [frame, setFrame] = useState(null); const popoverHeight = host?.popoverHeight; + const placement = composerPopoverPlacement(host); + // A pinned popover's top sits `above` over the composer whatever its height. + const pinnedAbove = placement?.pinnedToTop ? placement.above : null; + const measuredHeightRef = useRef(0); const measure = () => { const hostView = host?.hostRef.current; @@ -31,25 +39,46 @@ export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) { // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- measures the anchor view after every commit and hands its popover content to the composer popover host useEffect(() => { measure(); + if (frame === null) { + host?.setContent(null); + return; + } + // The host's top can sit above the screen while the keyboard lifts it, so the room + // estimate, not the anchor's offset, bounds the height. + const bottom = frame.y - COMPOSER_POPOVER_GAP; + const pinnedToTop = placement?.pinnedToTop === true; + const height = placement === null ? bottom : Math.min(bottom, placement.maxHeight); host?.setContent( - frame === null ? null : ( + { + measuredHeightRef.current = event.nativeEvent.layout.height; + popoverHeight?.set(pinnedAbove ?? measuredHeightRef.current); + }} > - { - popoverHeight?.set(event.nativeEvent.layout.height); - }} - > - {props.children} - + {props.children(pinnedToTop)} - ), + , ); }); + // New room can leave the popover's own size unchanged, so no layout event reports it. + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- re-reports the popover's height above the composer when the room estimate changes + useEffect(() => { + if (measuredHeightRef.current === 0) return; + popoverHeight?.set(pinnedAbove ?? measuredHeightRef.current); + }, [pinnedAbove, popoverHeight]); + const setHostContent = host?.setContent; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the popover host's content and shared height value when the anchor unmounts useEffect( @@ -61,7 +90,9 @@ export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) { ); if (host === null) { - return {props.children}; + return ( + {props.children(false)} + ); } return ( diff --git a/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx b/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx index b38bfc12eebfc..dbc63b5ac316a 100644 --- a/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx +++ b/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx @@ -2,10 +2,18 @@ import type { ReactNode } from "react"; import { useEffect } from "react"; import { View } from "react-native"; -import { useComposerPopoverHost } from "./ComposerPopoverHost"; +import { + COMPOSER_POPOVER_GAP, + composerPopoverPlacement, + useComposerPopoverHost, +} from "./ComposerPopoverHost"; -export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) { - const popoverHeight = useComposerPopoverHost()?.popoverHeight; +export function ComposerPopoverAnchor(props: { + readonly children: (overlapsComposer: boolean) => ReactNode; +}) { + const host = useComposerPopoverHost(); + const popoverHeight = host?.popoverHeight; + const placement = composerPopoverPlacement(host); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- resets the popover host's shared height value when the anchor unmounts useEffect( () => () => { @@ -15,12 +23,19 @@ export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) { ); return ( { - popoverHeight?.set(event.nativeEvent.layout.height); + popoverHeight?.set( + placement?.pinnedToTop ? placement.above : event.nativeEvent.layout.height, + ); }} > - {props.children} + {props.children(placement?.pinnedToTop === true)} ); } diff --git a/apps/mobile/src/features/threads/ComposerPopoverHost.tsx b/apps/mobile/src/features/threads/ComposerPopoverHost.tsx index 10254b5f00c39..b2507af81517c 100644 --- a/apps/mobile/src/features/threads/ComposerPopoverHost.tsx +++ b/apps/mobile/src/features/threads/ComposerPopoverHost.tsx @@ -8,6 +8,9 @@ type ComposerPopoverHostValue = { readonly setContent: (content: ReactNode) => void; readonly layoutVersion: number; readonly popoverHeight: SharedValue; + /** Room between the header and the composer's top, or null when unknown. */ + readonly popoverRoom: number | null; + readonly composerHeight: number; }; const ComposerPopoverHostContext = createContext(null); @@ -16,17 +19,48 @@ export function useComposerPopoverHost() { return useContext(ComposerPopoverHostContext); } +export const COMPOSER_POPOVER_GAP = 8; +// The group label plus about three rows. +const COMPOSER_POPOVER_MIN_HEIGHT = 160; + +/** + * With too little room above the composer (the Duo's front screen, keyboard up), the popover pins + * below the header and grows down over the composer, stopping at its bottom edge so no row hides + * behind the keyboard. `above` is the height it can use above the composer. + */ +export function composerPopoverPlacement(host: ComposerPopoverHostValue | null) { + if (host?.popoverRoom == null) return null; + const above = Math.max(0, host.popoverRoom - COMPOSER_POPOVER_GAP * 2); + if (above >= COMPOSER_POPOVER_MIN_HEIGHT) { + return { above, maxHeight: above, pinnedToTop: false }; + } + const maxHeight = Math.min( + COMPOSER_POPOVER_MIN_HEIGHT, + above + host.composerHeight - COMPOSER_POPOVER_GAP, + ); + return { above, maxHeight, pinnedToTop: true }; +} + /** Mount inside KeyboardStickyView for Android gestures. Hide explicitly because portal content outlives its subtree. */ export function ComposerPopoverHost(props: { readonly hidden: boolean; readonly inFlow?: boolean; readonly popoverHeight: SharedValue; + readonly popoverRoom: number | null; + readonly composerHeight: number; readonly children: ReactNode; }) { const hostRef = useRef(null); const [content, setContent] = useState(null); const [layoutVersion, setLayoutVersion] = useState(0); - const value = { hostRef, setContent, layoutVersion, popoverHeight: props.popoverHeight }; + const value = { + hostRef, + setContent, + layoutVersion, + popoverHeight: props.popoverHeight, + popoverRoom: props.popoverRoom, + composerHeight: props.composerHeight, + }; return ( diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx index 3b1b927ef8a9b..96229749592d9 100644 --- a/apps/mobile/src/features/threads/ThreadComposer.tsx +++ b/apps/mobile/src/features/threads/ThreadComposer.tsx @@ -842,13 +842,16 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps composerMenu.trigger && (composerMenu.items.length > 0 || composerMenu.trigger.kind === "pull-request") ? ( - + {(overlapsComposer) => ( + + )} ) : null} diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx index 5e4e90e0b68ae..993926f53bed5 100644 --- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx @@ -1093,6 +1093,15 @@ function ThreadDetailBody( }), flexGrow: 0, })); + // The sticky view lifts the composer by the keyboard less its opened offset, and the + // composer's measured height already includes its bottom inset. A measured Android screen + // already sits below its opaque header. + const composerPopoverRoom = + screenAreaHeight - + (Platform.OS === "android" && screenHeight !== null ? 0 : navigationHeaderHeight) - + controlInsets.bottom - + (keyboardStickyEnabled ? Math.max(0, liveKeyboardHeight - composerKeyboardOffset) : 0) - + composerOverlapHeight; // The usage panel stacks with the composer and any approval card, so it gets // whatever room they leave below the header. Measured only while it is open // so typing in the composer does not re-render the screen. @@ -1575,6 +1584,8 @@ function ThreadDetailBody( hidden={composerSlotHidden} popoverHeight={composerPopoverHeight} inFlow={questionInFlow} + popoverRoom={composerPopoverRoom} + composerHeight={composerOverlapHeight} > {/* The fixed sticky host gives this bottom-anchored child a stable coordinate space. Its top and height can then animate together