Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion apps/mobile/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { StatusBar } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { KeyboardProvider } from "react-native-keyboard-controller";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { createStaticNavigation, getStateFromPath } from "@react-navigation/native";
import {
createNavigationContainerRef,
createStaticNavigation,
getActionFromState,
getStateFromPath,
} from "@react-navigation/native";

import { RegistryContext } from "@effect/atom-react";
import { ProjectChipIconRasterizer } from "./native/ProjectChipIconImages";
Expand Down Expand Up @@ -38,6 +43,7 @@ import {
recordWorkspaceSelections,
settingsLinkPage,
} from "./features/workspace/workspace-selection-store";
import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection";
import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";

import "../global.css";
Expand All @@ -54,6 +60,13 @@ const appLinking = {
config: { initialRouteName: "Home" },
filter: shouldHandleAppLink,
getInitialURL: async () => (await Linking.getInitialURL()) ?? (await launchWorkspaceURL()),
getActionFromState: (
state: Parameters<typeof getActionFromState>[0],
options: Parameters<typeof getActionFromState>[1],
): ReturnType<typeof getActionFromState> =>
// Our router handles the selection; React Navigation's type only lists its own actions.
(workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ??
getActionFromState(state, options),
getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) =>
restoreSettingsLinkState(
restoreDraftLinkState(getStateFromPath(path, options), path),
Expand All @@ -62,6 +75,7 @@ const appLinking = {
};

const Navigation = createStaticNavigation(RootStack);
const navigationRef = createNavigationContainerRef();

function SplashScreenCoordinator() {
const { isReady } = useAppearancePreferences();
Expand Down Expand Up @@ -116,7 +130,9 @@ function AppContent() {
<NativeLayoutMetricsProvider>
<IncomingShareProvider>
<Navigation
ref={navigationRef}
linking={appLinking}
onReady={() => recordWorkspaceSelections(navigationRef.getRootState())}
theme={navigationTheme}
onStateChange={recordWorkspaceSelections}
/>
Expand Down
12 changes: 11 additions & 1 deletion apps/mobile/src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ import { nativeHeaderScrollEdgeEffects } from "./native/StackHeader";
import { HORIZONTAL_FORM_SHEET_OPTIONS, formSheetDetents } from "./native/sheet-surface";
import { useThreadOutboxDrain } from "./state/use-thread-outbox-drain";
import { useComposerAttachmentUploadWorker } from "./state/composer-attachment-uploads";
import {
selectWorkspaceDetail,
workspaceDetailRouter,
} from "./features/workspace/workspace-detail-selection";

const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);

Expand Down Expand Up @@ -525,7 +529,12 @@ function RootStackLayout(props: {
if (!transition.shareIdToPresent) {
return;
}
navigation.navigate("Thread", { draft: { incomingShareId: transition.shareIdToPresent } });
navigation.dispatch(
selectWorkspaceDetail({
name: "Thread",
params: { draft: { incomingShareId: transition.shareIdToPresent } },
}),
);
}, [navigation, pendingShare, props.state]);

return (
Expand Down Expand Up @@ -599,6 +608,7 @@ function NotFoundScreen() {

const RootStackConfig = createWorkspaceStackNavigator({
initialRouteName: "Home",
UNSTABLE_router: workspaceDetailRouter,
// React Navigation calls layouts inline; compiled components would share the navigator's memo cache.
layout: (props) => <RootStackLayout {...props} />,
screenOptions: {
Expand Down
6 changes: 1 addition & 5 deletions apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AudioFilePreview } from "./AudioFilePreview";
import { EmptyState } from "../../components/ui/EmptyState";
import { FilePreviewModal, type FilePreviewSource } from "../../components/FilePreviewModal";
import { LoadingScreen } from "../../components/LoadingScreen";
import { resolveFileSelectionNavigationAction } from "../../lib/adaptive-navigation";
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import { isPdfFile } from "../../lib/filePreview";
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
Expand Down Expand Up @@ -478,10 +477,7 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
navigation.navigate("NewTaskFile", params);
return;
}
const navigationAction = resolveFileSelectionNavigationAction({
hasPersistentFileInspector: hasFileInspector,
});
if (navigationAction === "replace") {
if (hasFileInspector) {
navigation.dispatch(StackActions.replace("ThreadFile", params));
return;
}
Expand Down
20 changes: 16 additions & 4 deletions apps/mobile/src/features/home/HomeRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import { HomeScreen } from "./HomeScreen";
import { HomeHeader } from "./HomeHeader";
import { useHomeListOptions } from "./home-list-options";
import { useAtomValueWhileVisible, useHomeRouteVisible } from "./home-route-visibility";
import { useHomeThreadRouteSelection, useHomeThreadSelection } from "./home-thread-navigation";
import { buildHomeProjectScopes } from "./homeThreadList";
import { usePendingTaskListActions } from "./usePendingTaskListActions";
import { useThreadListActions } from "./useThreadListActions";
import { getConnectionAwareBrandHeaderOptions } from "./WorkspaceConnectionTitle";
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import { openSettings } from "../settings/settings-navigation";
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
import { useSelectWorkspaceDetail } from "../workspace/useSelectWorkspaceDetail";

export function HomeRouteScreen() {
const { width: windowWidth } = useWindowDimensions();
Expand All @@ -45,6 +45,7 @@ export function HomeRouteScreen() {
const headerWidth = nativePrimaryColumn ? (columnMetrics?.width ?? windowWidth) : windowWidth;
const { layout, panes, primarySidebarSearchQuery, setPrimarySidebarSearchQuery, startNewTask } =
useAdaptiveWorkspaceLayout();
const selectDetail = useSelectWorkspaceDetail();
const projects = useProjects();
// Stop rebuilding the streaming thread list while Thread covers Home.
const visible = useHomeRouteVisible();
Expand All @@ -67,8 +68,18 @@ export function HomeRouteScreen() {
else if (workspace) workspace.dispatch({ type: "query", query, tab: "threads" });
else setLocalSearchQuery(query);
};
const handleSelectThread = useHomeThreadSelection();
const selectThreadRoute = useHomeThreadRouteSelection();
const handleSelectThread = useCallback(
(thread: EnvironmentThreadShell) =>
selectDetail({
name: "Thread",
params: { environmentId: String(thread.environmentId), threadId: String(thread.id) },
}),
[selectDetail],
);
const selectThreadRoute = useCallback(
(params: ReactNavigation.RootParamList["Thread"]) => selectDetail({ name: "Thread", params }),
[selectDetail],
);
const handleNewThreadOnBranch = useCallback(
(thread: EnvironmentThreadShell) => {
selectThreadRoute({
Expand Down Expand Up @@ -104,7 +115,8 @@ export function HomeRouteScreen() {
unsettleThread,
} = useThreadListActions();
const pendingTasks = usePendingNewTasks();
const { openPendingTask, confirmDeletePendingTask } = usePendingTaskListActions();
const { openPendingTask, confirmDeletePendingTask } =
usePendingTaskListActions(selectThreadRoute);
const environments = useMemo(() => {
const connectionStateByEnvironmentId = new Map(
workspaceEnvironments.map(
Expand Down
Loading
Loading