TypeScript
fix(mobile): preserve new-thread drafts and native header layout (#23366)
Julius Marminge002e941fbb2e
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsxindex f74f13acd50..52866ae626d 100644--- a/apps/mobile/src/Stack.tsx+++ b/apps/mobile/src/Stack.tsx@@ -1059,10 +1059,19 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navigconst nativeMetrics = useNativeLayoutMetrics();const usesSplitView = deriveLayout({ width, height, nativeMetrics }).usesSplitView;const usesWorkspaceFlowScreens = Platform.OS === "android" || usesSplitView;+ const flowPresentations = useRef(new Map<string, boolean>());return (<NavigatorscreenLayout={(props) => <GuardedScreenLayout {...props} />}+ screenListeners={{+ state: ({ data }) => {+ const keys = new Set(data.state.routes.map((route) => route.key));+ for (const key of flowPresentations.current.keys()) {+ if (!keys.has(key)) flowPresentations.current.delete(key);+ }+ },+ }}screenOptions={({ route }) => {if (route.name !== "SettingsSheet" && route.name !== "NewTaskSheet") {return Platform.OS === "android"@@ -1070,7 +1079,14 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navig: {};}- return usesWorkspaceFlowScreens+ // Moving an open flow between a sheet and a split column remounts its nested+ // navigator. Keep its presentation until dismissal so folding preserves the draft.+ let usesCard = flowPresentations.current.get(route.key);+ if (usesCard === undefined) {+ usesCard = usesWorkspaceFlowScreens;+ flowPresentations.current.set(route.key, usesCard);+ }+ return usesCard? { presentation: "card" }: {presentation: "formSheet",diff --git a/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx b/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsxindex 3df93a6dd9f..d719c85525d 100644--- a/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx+++ b/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx@@ -65,7 +65,7 @@ export function WorkspaceEmptyDetail(props: {className="mt-2 flex-row items-center gap-2 rounded-full bg-primary px-5 py-3 active:opacity-70"onPress={props.onStartNewTask}>- <Text className="text-base font-t3-bold text-primary-foreground">New Task</Text>+ <Text className="text-base font-t3-bold text-primary-foreground">New thread</Text></Pressable>)) : null}diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsxindex 5acc33b8703..cea3e66a380 100644--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx@@ -282,8 +282,8 @@ function WorkspaceColumns(<WorkspaceEmptyDetailtab={selectedTab}onStartNewTask={- // The detail bar or a visible sidebar already carries compose.- detailCompose || panes.primarySidebarVisible ? undefined : openNewTask+ // Duo provides compose in the detail bar; iPad uses the empty-state action.+ detailCompose ? undefined : openNewTask}/></ColumnContent>diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsxindex 453b6829bd6..319aa12230c 100644--- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx+++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx@@ -21,9 +21,9 @@ import {usePreventRemove,type NavigationAction,} from "@react-navigation/native";-import { HeaderHeightContext } from "@react-navigation/elements";-import { useContext, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";-import { Platform, Pressable, ScrollView, View } from "react-native";+import { useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";+import { Platform, Pressable, View } from "react-native";+import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";import {KeyboardController,KeyboardStickyView,@@ -215,9 +215,6 @@ export function NewTaskDraftScreen(props: {reserveShare,} = useIncomingShare();const insets = useSafeAreaInsets();- // The iOS glass header floats over the hero, and its height differs between an- // iPhone sheet and an iPad column that also carries the status bar.- const navigationHeaderHeight = useContext(HeaderHeightContext) ?? insets.top + 56;const isKeyboardVisible = useKeyboardState((state) => state.isVisible);const controlsBottomPadding = Math.max(insets.bottom, 10);const keyboardOpenedOffset = Math.max(0, controlsBottomPadding - 8);@@ -1553,11 +1550,8 @@ export function NewTaskDraftScreen(props: {<ScrollViewalwaysBounceVertical={isKeyboardVisible}className="flex-1"- contentInsetAdjustmentBehavior="never"+ contentInsetAdjustmentBehavior="automatic"contentContainerClassName="grow items-center pb-[236px] pt-12"- contentContainerStyle={- Platform.OS === "ios" ? { paddingTop: navigationHeaderHeight + 16 } : undefined- }keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}keyboardShouldPersistTaps="handled"showsVerticalScrollIndicator={false}@@ -1851,6 +1845,7 @@ export function NewTaskDraftScreen(props: {headerBackVisible: false,headerShadowVisible: false,title: "New thread",+ unstable_navigationItemStyle: "editor",}}/><SheetHeaderdiff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsxindex 00febb5781f..683b63e8f99 100644--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx@@ -67,9 +67,8 @@ export function WorkspaceToolbar(props: {// On the Duo, compose belongs to the threads tab, in the detail column's bar when unfolded.const nativeToolbarCompose =Platform.OS === "ios" &&- (isDuoDevice(deviceType)- ? deviceType === "duo-folded" && workspace.state.selectedTab === "threads"- : deviceType === "pad");+ deviceType === "duo-folded" &&+ workspace.state.selectedTab === "threads";// The Duo searches from a field at the bottom of the list in every pose. UIKit has no such// placement once the vertical bar holds the toolbar, and re-placing its search controller on// each fold replaces the search field.