Skip to content

Commit 31610cb

Browse files
fix(mobile): keep Settings pages full width on Android tablets and cheap on iOS
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8627396 commit 31610cb

3 files changed

Lines changed: 55 additions & 24 deletions

File tree

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import {
9292
import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
9393
import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
9494
import { WindowHingeContext } from "../../native/window-hinge-context";
95+
import { useAndroidWorkspaceRoot } from "../workspace/AndroidWorkspaceTabsProvider";
9596
import { openSettings } from "../settings/settings-navigation";
9697

9798
export { useAdaptiveWorkspaceLayout };
@@ -209,9 +210,9 @@ function AdaptiveWorkspaceLayoutContent(
209210
const pathname = props.pathname;
210211
const workspace = useWorkspaceTabs();
211212
// Settings and Usage occupy the workspace rather than a list/detail pair.
213+
const androidSettingsOpen = useAndroidWorkspaceRoot()?.settingsOpen ?? false;
212214
const workspacePage =
213-
Platform.OS === "android" &&
214-
(pathname.startsWith("/settings") || workspace?.state.selectedTab === "usage");
215+
Platform.OS === "android" && (androidSettingsOpen || workspace?.state.selectedTab === "usage");
215216
const navigation = useNavigation();
216217
const activeRoleOwner = useRef<symbol | null>(null);
217218
const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);

‎apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ const isPullRequestRoute = (route: Route) =>
6868
route.name === "PullRequestFile" ||
6969
route.name === "PullRequestFiles";
7070

71+
/** Only these screens follow the sidebar's state; a thread's header draws its own toggle. */
72+
function SidebarToggleHeader(props: ComponentProps<typeof V5StackHeader>) {
73+
const sidebarItem = useWorkspaceSidebarHeaderItem();
74+
const options = useMemo(
75+
() =>
76+
({
77+
...props.options,
78+
unstable_headerLeftItems: () => [sidebarItem],
79+
}) as AppNativeStackNavigationOptions as typeof props.options,
80+
[props.options, sidebarItem],
81+
);
82+
return <V5StackHeader {...props} options={options} />;
83+
}
84+
7185
function ColumnScreen(props: {
7286
readonly descriptor: Descriptor;
7387
readonly primary?: boolean;
@@ -82,14 +96,10 @@ function ColumnScreen(props: {
8296
readonly navigation: ViewProps["navigation"];
8397
}) {
8498
const { descriptor } = props;
85-
const sidebarItem = useWorkspaceSidebarHeaderItem();
86-
const options =
99+
const Header =
87100
props.sidebarToggle && !descriptor.options.unstable_headerLeftItems
88-
? ({
89-
...descriptor.options,
90-
unstable_headerLeftItems: () => [sidebarItem],
91-
} as AppNativeStackNavigationOptions as typeof descriptor.options)
92-
: descriptor.options;
101+
? SidebarToggleHeader
102+
: V5StackHeader;
93103
const [presented, setPresented] = useState(false);
94104
const primaryColumn = useMemo(
95105
() =>
@@ -130,8 +140,8 @@ function ColumnScreen(props: {
130140
>
131141
<NavigationContext value={descriptor.navigation}>
132142
<NavigationRouteContext value={descriptor.route}>
133-
<V5StackHeader
134-
options={options}
143+
<Header
144+
options={descriptor.options}
135145
canGoBack={!props.primary}
136146
column={props.primary ? "primary" : "detail"}
137147
onCompose={

‎apps/mobile/src/features/settings/settings-environment-filter.tsx‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,38 @@ export type SettingsTarget = EnvironmentPresentation & {
1919
readonly serverConfig: NonNullable<EnvironmentPresentation["serverConfig"]>;
2020
};
2121

22+
// Several mounted Settings components read the scope at once (the list, its header, a page and
23+
// its editor), so share the derived lists across them for the same inputs.
24+
const targetsCache = new WeakMap<readonly EnvironmentPresentation[], readonly SettingsTarget[]>();
25+
const groupsCache = new WeakMap<object, Map<string, ReturnType<typeof buildProjectGroups>>>();
26+
2227
function connectedSettingsTargets(environments: readonly EnvironmentPresentation[]) {
23-
return environments.filter(
24-
(entry): entry is SettingsTarget =>
25-
entry.connection.phase === "connected" && entry.serverConfig !== null,
26-
);
28+
let targets = targetsCache.get(environments);
29+
if (!targets) {
30+
targets = environments.filter(
31+
(entry): entry is SettingsTarget =>
32+
entry.connection.phase === "connected" && entry.serverConfig !== null,
33+
);
34+
targetsCache.set(environments, targets);
35+
}
36+
return targets;
37+
}
38+
39+
function settingsProjectGroups(
40+
projects: Parameters<typeof buildProjectGroups>[0]["projects"],
41+
groupingMode: Parameters<typeof buildProjectGroups>[0]["settings"]["sidebarProjectGroupingMode"],
42+
) {
43+
let byMode = groupsCache.get(projects);
44+
if (!byMode) groupsCache.set(projects, (byMode = new Map()));
45+
let groups = byMode.get(groupingMode);
46+
if (!groups) {
47+
groups = buildProjectGroups({
48+
projects,
49+
settings: { sidebarProjectGroupingMode: groupingMode, sidebarProjectGroupingOverrides: {} },
50+
});
51+
byMode.set(groupingMode, groups);
52+
}
53+
return groups;
2754
}
2855

2956
interface SettingsEnvironmentSelection {
@@ -72,15 +99,8 @@ export function useSettingsEnvironmentFilter() {
7299
const projects = useProjects();
73100
const groupingSettings = useMobileProjectGroupingSettings();
74101
const groupingMode = groupingSettings.sidebarProjectGroupingMode;
75-
const projectGroups = useMemo(
76-
() =>
77-
buildProjectGroups({
78-
projects,
79-
settings: { sidebarProjectGroupingMode: groupingMode, sidebarProjectGroupingOverrides: {} },
80-
}),
81-
[projects, groupingMode],
82-
);
83-
const availableTargets = useMemo(() => connectedSettingsTargets(environments), [environments]);
102+
const projectGroups = settingsProjectGroups(projects, groupingMode);
103+
const availableTargets = connectedSettingsTargets(environments);
84104
const selectedTargets = useMemo(
85105
() =>
86106
availableTargets.filter(

0 commit comments

Comments
 (0)