TypeScript
fix(mobile): the Android composer no longer lags the keyboard or drops under the nav bar (#19980)
Thalles Passosdc52893873a1
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsxindex ac22a8b7d9e..2b36b8b0959 100644--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx@@ -493,16 +493,13 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaiconst [anchorMessageId, setAnchorMessageId] = useState<MessageId | null>(null);const [submittedMessageId, setSubmittedMessageId] = useState<MessageId | null>(null);const [endFollowEnabled, setEndFollowEnabled] = useState(true);- // Android keys the safe-area padding on keyboard visibility (#5988): the back gesture closes- // the keyboard while the editor stays focused, and a focus-keyed inset would leave the toolbar- // under the gesture bar. iOS must NOT use visibility — it only flips on keyboardDidHide, after- // the hide animation, so the composer would ride down flush to the screen edge and then snap up- // into the inset.- const composerBottomInset = (- Platform.OS === "android" ? isKeyboardVisible : composerExpanded || composerFocused- )- ? 0- : Math.max(insets.bottom, 12);+ // Android Back hides the keyboard without blurring. Keep its safe-area padding+ // fixed through the animation and cancel it with matching composer/list offsets.+ const composerBottomInset =+ Platform.OS === "ios" && (composerExpanded || composerFocused)+ ? 0+ : Math.max(insets.bottom, 12);+ const composerKeyboardOffset = Platform.OS === "android" ? composerBottomInset : 0;const contentPresentationKind = props.contentPresentation.kind;const realThreadSyncLabel = (() => {switch (props.threadSyncStatus) {@@ -1145,6 +1142,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaianchorMessageId={anchorMessageId}submittedMessageId={submittedMessageId}contentInsetEndAdjustment={combinedContentInsetEndAdjustment}+ keyboardOffset={composerKeyboardOffset}contentTopInset={0}contentBottomInset={estimatedOverlayHeight +@@ -1180,12 +1178,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai{showContent ? (<KeyboardStickyView- // iOS emits a native animated height target on both will-show and- // will-hide, so stay subscribed for the full transition.- enabled={Platform.OS === "ios" || (isKeyboardVisible && !keyboardStateSuspect)}+ // Waiting for a visibility render misses the first keyboard frames.+ enabled={Platform.OS === "ios" || !keyboardStateSuspect}pointerEvents="box-none"style={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}- offset={{ closed: 0, opened: 0 }}+ offset={{ closed: 0, opened: composerKeyboardOffset }}><ComposerPopoverHost hidden={composerSlotHidden} popoverHeight={composerPopoverHeight}>{/* The fixed sticky host gives this bottom-anchored child a stablediff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsxindex 293f6aceac6..d9fb29d7d71 100644--- a/apps/mobile/src/features/threads/ThreadFeed.tsx+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx@@ -304,6 +304,7 @@ export interface ThreadFeedProps {readonly anchorMessageId: MessageId | null;readonly submittedMessageId: MessageId | null;readonly contentInsetEndAdjustment: SharedValue<number>;+ readonly keyboardOffset: number;readonly contentTopInset?: number;readonly contentBottomInset?: number;readonly historyControls?: ThreadFeedHistoryControls;@@ -2468,6 +2469,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {// content rest below the transparent header rather than at frame top.contentInsetStartAdjustment={usesNativeAutomaticInsets ? anchorTopInset : 0}contentInsetEndAdjustment={props.contentInsetEndAdjustment}+ keyboardOffset={props.keyboardOffset}// UIKit's automatic behavior adds the safe-area bottom on top of the// raw contentInset the keyboard integration writes. The detail screen// under-reports the composer inset by this amount (see