Skip to content
TypeScript

fix(mobile): Settings split view keeps its selection and its header matches the page (#24644)

Julius Marminge8fdaf3479cba
diff --git a/apps/mobile/src/components/ui/ScreenScrollView.tsx b/apps/mobile/src/components/ui/ScreenScrollView.tsx
index 684d2e3bdf5..5e48866c163 100644
--- a/apps/mobile/src/components/ui/ScreenScrollView.tsx
+++ b/apps/mobile/src/components/ui/ScreenScrollView.tsx
@@ -1,14 +1,22 @@
import { createContext, use, type ComponentProps } from "react";
import { Platform } from "react-native";
+import { cn } from "../../lib/cn";
import { NativeScrollView as ScrollView } from "../../native/NativeScrollViewMarker";
export const ScreenScrollViewBottomInset = createContext(0);
+/**
+ * The screen's surface class. UIKit's scroll-edge material under the header takes the scroll
+ * view's own color; a clear scroll view gets the system's near-white bar over the screen's surface.
+ */
+export const ScreenScrollViewSurface = createContext<string | undefined>(undefined);
export function ScreenScrollView(props: ComponentProps<typeof ScrollView>) {
const bottomInset = use(ScreenScrollViewBottomInset);
+ const surface = use(ScreenScrollViewSurface);
return (
<ScrollView
{...props}
+ className={Platform.OS === "ios" && surface ? cn(surface, props.className) : props.className}
contentInset={
Platform.OS === "ios" && bottomInset > 0
? { ...props.contentInset, bottom: (props.contentInset?.bottom ?? 0) + bottomInset }
diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
index b39e1cdde21..826d352fb4a 100644
--- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
@@ -8,6 +8,8 @@ import {
useNavigationTabOrder,
useHiddenNavigationTabs,
} from "../workspace/navigation-tabs";
+import { currentWorkspaceSelections } from "../workspace/workspace-selection-store";
+import { rememberedSettingsPage } from "../workspace/workspace-tab-navigation";
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
import {
ScreenScrollView as ScrollView,
@@ -42,10 +44,14 @@ export function SettingsRouteScreen() {
const compactTabs = useCompactWorkspaceTabs();
const { layout } = useAdaptiveWorkspaceLayout();
const inSidebar = use(NativePrimaryColumnContext) !== null && layout.usesSplitView;
- // The page open beside the list: the route right above the Settings tab's route.
+ // The page open beside the list: the route right above the Settings tab's route. While
+ // another tab is open this list stays mounted, hidden, and must keep showing the page Settings
+ // reopens on; otherwise returning shows it unselected for a frame before the page arrives.
const selected = useNavigationState((state) => {
const list = state.routes.findIndex((route) => route.name === "Settings");
- return list < 0 ? null : (state.routes[list + 1]?.name ?? null);
+ return list < 0
+ ? rememberedSettingsPage(currentWorkspaceSelections())
+ : (state.routes[list + 1]?.name ?? null);
});
const sidebar = useMemo(() => (inSidebar ? { selected } : null), [inSidebar, selected]);
const content = hasCloudPublicConfig() ? (
@@ -56,7 +62,7 @@ export function SettingsRouteScreen() {
return (
<SettingsSidebarContext value={sidebar}>
- <View className={`flex-1 ${surface.className}`}>
+ <View className={`flex-1 ${inSidebar ? surface.className : "bg-screen"}`}>
<SettingsEnvironmentFilterHeader />
<ScreenScrollViewBottomInset value={deviceType === "pad" || compactTabs ? 80 : 0}>
{Platform.OS === "android" ? (
@@ -75,7 +81,8 @@ export function SettingsRouteScreen() {
function ConfiguredSettingsRouteScreen() {
// UIKit's scroll-edge material takes the scroll view's own color; like the chat list, match
// the sidebar's surface so the bar doesn't darken over content at rest.
- const listSurface = use(NativePrimaryColumnContext) ? "bg-drawer" : "bg-screen";
+ // Grouped cards only lift off the screen surface; the drawer is as dark as they are.
+ const listSurface = use(SettingsSidebarContext) ? "bg-drawer" : "bg-screen";
const insets = useSafeAreaInsets();
const navigation = useNavigation();
const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
@@ -124,7 +131,8 @@ function ConfiguredSettingsRouteScreen() {
function LocalSettingsRouteScreen() {
// UIKit's scroll-edge material takes the scroll view's own color; like the chat list, match
// the sidebar's surface so the bar doesn't darken over content at rest.
- const listSurface = use(NativePrimaryColumnContext) ? "bg-drawer" : "bg-screen";
+ // Grouped cards only lift off the screen surface; the drawer is as dark as they are.
+ const listSurface = use(SettingsSidebarContext) ? "bg-drawer" : "bg-screen";
const insets = useSafeAreaInsets();
const { savedConnectionsById } = useSavedRemoteConnections();
const environmentCount = Object.keys(savedConnectionsById).length;
diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
index e05d71239ac..85a8258187a 100644
--- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
@@ -9,7 +9,10 @@ import { useWorkspaceTabs } from "../../workspace/WorkspaceTabsContext";
import { useWorkspaceSurface } from "../../workspace/useWorkspaceSurface";
import { useDeviceType } from "../../../native/native-layout-metrics";
import { useCompactWorkspaceTabs } from "../../workspace/useSystemWorkspaceTabBar";
-import { ScreenScrollViewBottomInset } from "../../../components/ui/ScreenScrollView";
+import {
+ ScreenScrollViewBottomInset,
+ ScreenScrollViewSurface,
+} from "../../../components/ui/ScreenScrollView";
export { SettingsScreenContent };
@@ -32,11 +35,12 @@ export function SettingsScreen(
props.workspaceRoot ||
(Platform.OS === "android" && workspace !== null && route.name === "Settings");
+ // Settings' grouped cards only lift off the screen surface, so the folded Duo doesn't take
+ // the workspace's drawer surface here.
+ const surfaceClassName = cover ? "bg-screen" : workspaceRoot ? surface.className : "bg-sheet";
+
return (
- <View
- collapsable={false}
- className={`flex-1 ${workspaceRoot || cover ? surface.className : "bg-sheet"}`}
- >
+ <View collapsable={false} className={`flex-1 ${surfaceClassName}`}>
<AppBar
title={props.title}
actions={props.actions}
@@ -46,11 +50,13 @@ export function SettingsScreen(
hideBottomBorder={!props.formSheet}
/>
<ScreenScrollViewBottomInset value={deviceType === "pad" || compactTabs ? 80 : 0}>
- {props.formSheet ? (
- props.children
- ) : (
- <SettingsScreenContent>{props.children}</SettingsScreenContent>
- )}
+ <ScreenScrollViewSurface value={surfaceClassName}>
+ {props.formSheet ? (
+ props.children
+ ) : (
+ <SettingsScreenContent>{props.children}</SettingsScreenContent>
+ )}
+ </ScreenScrollViewSurface>
</ScreenScrollViewBottomInset>
</View>
);