TypeScript
fix(mobile): lift thread status above composer suggestions (#17964)
Cameron Chisholm28059f6ed31b
diff --git a/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx b/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsxindex 172d3266bc7..6fe265f99b5 100644--- a/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx+++ b/apps/mobile/src/features/threads/ComposerPopoverAnchor.android.tsx@@ -16,6 +16,7 @@ export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) {const host = useComposerPopoverHost();const anchorRef = useRef<ViewInstance>(null);const [frame, setFrame] = useState<Frame | null>(null);+ const popoverHeight = host?.popoverHeight;const measure = () => {const hostView = host?.hostRef.current;@@ -41,14 +42,26 @@ export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) {className="absolute top-0 justify-end"style={{ left: frame.x, width: frame.width, height: frame.y - COMPOSER_GAP }}>- {props.children}+ <View+ onLayout={(event) => {+ popoverHeight?.set(event.nativeEvent.layout.height);+ }}+ >+ {props.children}+ </View></View>),);});const setHostContent = host?.setContent;- useEffect(() => () => setHostContent?.(null), [setHostContent]);+ useEffect(+ () => () => {+ setHostContent?.(null);+ popoverHeight?.set(0);+ },+ [setHostContent, popoverHeight],+ );if (host === null) {return <View className="absolute inset-x-0 bottom-full z-10 mb-2">{props.children}</View>;diff --git a/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx b/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsxindex c1292873d85..ecf9314791a 100644--- a/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx+++ b/apps/mobile/src/features/threads/ComposerPopoverAnchor.tsx@@ -1,6 +1,25 @@import type { ReactNode } from "react";+import { useEffect } from "react";import { View } from "react-native";+import { useComposerPopoverHost } from "./ComposerPopoverHost";+export function ComposerPopoverAnchor(props: { readonly children: ReactNode }) {- return <View className="absolute inset-x-0 bottom-full z-10 mb-2">{props.children}</View>;+ const popoverHeight = useComposerPopoverHost()?.popoverHeight;+ useEffect(+ () => () => {+ popoverHeight?.set(0);+ },+ [popoverHeight],+ );+ return (+ <View+ className="absolute inset-x-0 bottom-full z-10 mb-2"+ onLayout={(event) => {+ popoverHeight?.set(event.nativeEvent.layout.height);+ }}+ >+ {props.children}+ </View>+ );}diff --git a/apps/mobile/src/features/threads/ComposerPopoverHost.tsx b/apps/mobile/src/features/threads/ComposerPopoverHost.tsxindex e3ee8525a38..818ef490a5b 100644--- a/apps/mobile/src/features/threads/ComposerPopoverHost.tsx+++ b/apps/mobile/src/features/threads/ComposerPopoverHost.tsx@@ -1,11 +1,13 @@import type { ReactNode, RefObject } from "react";import { createContext, useContext, useMemo, useRef, useState } from "react";import { View, type ViewInstance } from "react-native";+import type { SharedValue } from "react-native-reanimated";type ComposerPopoverHostValue = {readonly hostRef: RefObject<ViewInstance | null>;readonly setContent: (content: ReactNode) => void;readonly layoutVersion: number;+ readonly popoverHeight: SharedValue<number>;};const ComposerPopoverHostContext = createContext<ComposerPopoverHostValue | null>(null);@@ -21,12 +23,16 @@ export function useComposerPopoverHost() {*/export function ComposerPopoverHost(props: {readonly hidden: boolean;+ readonly popoverHeight: SharedValue<number>;readonly children: ReactNode;}) {const hostRef = useRef<ViewInstance>(null);const [content, setContent] = useState<ReactNode>(null);const [layoutVersion, setLayoutVersion] = useState(0);- const value = useMemo(() => ({ hostRef, setContent, layoutVersion }), [layoutVersion]);+ const value = useMemo(+ () => ({ hostRef, setContent, layoutVersion, popoverHeight: props.popoverHeight }),+ [layoutVersion, props.popoverHeight],+ );return (<ComposerPopoverHostContext.Provider value={value}>diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsxindex bb36fce9bcb..500abb7575a 100644--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx@@ -695,6 +695,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaiconst userInputCardProgress = useSharedValue(1);const userInputInsetProgress = useSharedValue(1);const userInputCardCoverage = useSharedValue(0);+ const composerPopoverHeight = useSharedValue(0);const floatingControlCoverage = useSharedValue(showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0,);@@ -721,9 +722,18 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai},[userInputCoverageApplies],);+ const composerPopoverLift = useDerivedValue(() =>+ withTiming(+ !composerSlotHidden && composerPopoverHeight.value > 0 ? composerPopoverHeight.value + 8 : 0,+ { duration: 180, easing: Easing.out(Easing.cubic), reduceMotion: ReduceMotion.System },+ ),+ );const floatingControlLift = useDerivedValue(() =>- userInputCoverageApplies ? userInputCardProgress.value * userInputCardCoverage.value : 0,+ Math.max(+ userInputCoverageApplies ? userInputCardProgress.value * userInputCardCoverage.value : 0,+ composerPopoverLift.value,+ ),[userInputCoverageApplies],);const { freeze, scrollMessageToEnd } = useKeyboardScrollToEnd({ listRef });@@ -1127,7 +1137,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaistyle={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}offset={{ closed: 0, opened: 0 }}>- <ComposerPopoverHost hidden={composerSlotHidden}>+ <ComposerPopoverHost hidden={composerSlotHidden} popoverHeight={composerPopoverHeight}>{/* The fixed sticky host gives this bottom-anchored child a stablecoordinate space. Its top and height can then animate togetherinstead of the auto-sized host jumping to Yoga's destination. */}