Skip to content
TypeScript

fix(mobile): the drawer surface is only for a sidebar beside a page (#27289)

Julius Marminge9aa80a0dc412
diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx
index 4609ecfb96c..0883e819bd8 100644
--- a/apps/mobile/src/features/home/HomeScreen.tsx
+++ b/apps/mobile/src/features/home/HomeScreen.tsx
@@ -1,3 +1,4 @@
+import { usePaneRole } from "../../components/ui/Pane";
import { useActiveNewTask } from "../../state/active-new-task";
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
@@ -215,6 +216,7 @@ function HomeTopContentSpacer() {
function HomeScrollView(props: ComponentProps<typeof ScrollView>) {
const primaryColumn = use(NativePrimaryColumnContext);
+ const sidebarSurface = usePaneRole() === "sidebar" && primaryColumn !== null;
if (Platform.OS !== "ios") return <ScrollView {...props} />;
// Register the scroll view explicitly; layout and header siblings hide it from UIKit.
@@ -229,7 +231,7 @@ function HomeScrollView(props: ComponentProps<typeof ScrollView>) {
<ScrollView
{...props}
// UIKit's scroll-edge material needs the scroll view's own surface color.
- className={cn(props.className, primaryColumn ? "bg-drawer" : "bg-screen")}
+ className={cn(props.className, sidebarSurface ? "bg-drawer" : "bg-screen")}
/>
</ScrollViewMarker>
);
@@ -245,7 +247,8 @@ export function HomeScreen(props: HomeScreenProps) {
const workspace = useWorkspaceTabs();
const [initialScrollOffset] = useState(() => workspace?.getScrollOffset("threads") ?? 0);
const primaryColumn = use(NativePrimaryColumnContext);
- const contentBackground = primaryColumn ? "bg-drawer" : "bg-screen";
+ const sidebarSurface = usePaneRole() === "sidebar" && primaryColumn !== null;
+ const contentBackground = sidebarSurface ? "bg-drawer" : "bg-screen";
const containerClassName = cn(
"flex-1",
Platform.OS === "android" ? "bg-header" : contentBackground,
@@ -507,7 +510,7 @@ export function HomeScreen(props: HomeScreenProps) {
);
return (
<ThreadListV2PendingRow
- pane={primaryColumn ? "sidebar" : "screen"}
+ pane={sidebarSurface ? "sidebar" : "screen"}
pendingTask={item.pendingTask}
selected={
activeNewTask?.pendingKey === item.pendingTask.key ||
@@ -569,7 +572,7 @@ export function HomeScreen(props: HomeScreenProps) {
const thread = item.item.thread;
return (
<ThreadListV2Row
- pane={primaryColumn ? "sidebar" : "screen"}
+ pane={sidebarSurface ? "sidebar" : "screen"}
selected={scopedThreadKey(thread.environmentId, thread.id) === selectedThreadKey}
fullSwipeWidth={fullSwipeWidth}
onNewThreadOnBranch={props.onNewThreadOnBranch}
@@ -719,7 +722,7 @@ export function HomeScreen(props: HomeScreenProps) {
{listHeader}
{Platform.OS === "ios" && workspace ? (
<ThreadListFilters
- gutter={primaryColumn ? 8 : 0}
+ gutter={sidebarSurface ? 8 : 0}
environments={props.environments}
projects={pickableProjectGroups(projectScopes).map((scope) => ({
key: scope.key,
@@ -786,7 +789,7 @@ export function HomeScreen(props: HomeScreenProps) {
<SwipeableScrollGateProvider enabled={swipeEnabled} activation={swipeRowActivation}>
<GestureDetector gesture={homeScrollGesture}>
<AnimatedLegendList
- itemLayoutAnimation={primaryColumn ? THREAD_SIDEBAR_ROW_LAYOUT : undefined}
+ itemLayoutAnimation={sidebarSurface ? THREAD_SIDEBAR_ROW_LAYOUT : undefined}
ref={listRef}
onLoad={() => activateVisibleRows(threadListV2Items)}
onTouchStart={(event) => trackListTouches(event, true)}
@@ -840,9 +843,9 @@ export function HomeScreen(props: HomeScreenProps) {
scrollEventThrottle={16}
contentContainerStyle={{
paddingLeft:
- (contentSideInsets?.left ?? 0) + (primaryColumn ? 8 : 0) + androidListGutter,
+ (contentSideInsets?.left ?? 0) + (sidebarSurface ? 8 : 0) + androidListGutter,
paddingRight:
- (contentSideInsets?.right ?? 0) + (primaryColumn ? 8 : 0) + androidListGutter,
+ (contentSideInsets?.right ?? 0) + (sidebarSurface ? 8 : 0) + androidListGutter,
paddingBottom:
Platform.OS === "ios"
? iosBottomClearance - (columnMetrics?.safeArea.bottom ?? insets.bottom)
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index bede4e8a6c9..ab5d8baad87 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -105,6 +105,9 @@ function ColumnScreen(props: {
readonly footer?: ReactNode;
}) {
const { descriptor } = props;
+ const { layout } = useAdaptiveWorkspaceLayout();
+ // A collapsed split shows the primary column as the page itself, not as a sidebar.
+ const sidebar = props.primary === true && layout.usesSplitView;
// Options a screen set inside this workspace tab slot, over its route's.
const options = slotScreenOptions(
use(WorkspaceSlotOptionsContext),
@@ -145,7 +148,7 @@ function ColumnScreen(props: {
props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: true } })
}
>
- <PaneContext value={props.primary ? "sidebar" : "content"}>
+ <PaneContext value={sidebar ? "sidebar" : "content"}>
<NavigationContext value={descriptor.navigation}>
<NavigationRouteContext value={descriptor.route}>
<V5StackHeader
@@ -161,7 +164,7 @@ function ColumnScreen(props: {
}
/>
<ColumnContent
- primary={props.primary}
+ primary={sidebar}
insetHorizontally={
(options as AppNativeStackNavigationOptions).nativeContentInsetHorizontally
}
diff --git a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
index 5d55f86c4e8..14ea14036a5 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
@@ -1,3 +1,4 @@
+import { usePaneRole } from "../../components/ui/Pane";
import { Button } from "../../components/ui/Button";
import {
applyPullRequestDraftFilterChange,
@@ -186,7 +187,8 @@ export function PullRequestsScreen(
connectedTargets.map((target) => target.environmentId),
result.updateEntry,
);
- const sidebar = props.sidebar === true || primaryColumn !== null;
+ const paneRole = usePaneRole();
+ const sidebar = props.sidebar === true || (primaryColumn !== null && paneRole === "sidebar");
const selectedKey = props.selectedPullRequestKey ?? primaryColumn?.selectedPullRequestKey;
const connectedKey = connectedTargets.map((target) => target.environmentId).join("\n");
const entries = useMemo(
diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
index b39c1b5a5cc..a8576efc54a 100644
--- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
@@ -18,7 +18,6 @@ import { useAuth, useUser } from "@clerk/expo";
import { useNavigation, useNavigationState } from "@react-navigation/native";
import { use, type ComponentProps } from "react";
import { Platform, View } from "react-native";
-import { useWorkspaceSurface } from "../workspace/useWorkspaceSurface";
import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import { deriveProjectGroupLabel } from "@t3tools/client-runtime/state/project-grouping";
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -57,7 +56,6 @@ export function SettingsListScreen(props: {
readonly sidebar: boolean;
readonly selected: string | null;
}) {
- const surface = useWorkspaceSurface();
const workspace = useWorkspaceTabs();
const environmentMenu = useSettingsEnvironmentMenu();
const inSidebar = props.sidebar;
@@ -71,7 +69,7 @@ export function SettingsListScreen(props: {
return (
<SettingsSidebarContext value={sidebar}>
- <View className={`flex-1 ${inSidebar ? surface.className : "bg-screen"}`}>
+ <View className="flex-1 bg-screen">
<SettingsEnvironmentFilterHeader />
{Platform.OS === "android" ? (
<SettingsScreen
diff --git a/apps/mobile/src/features/settings/components/SettingsRow.tsx b/apps/mobile/src/features/settings/components/SettingsRow.tsx
index 76894659ec9..ce61dec7cfe 100644
--- a/apps/mobile/src/features/settings/components/SettingsRow.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsRow.tsx
@@ -53,7 +53,7 @@ export function SettingsRow(props: {
accessibilityState={{ disabled: Boolean(props.disabled), selected }}
disabled={props.disabled}
onPress={onPress}
- className={cn("rounded-2xl", selected && "bg-subtle-strong")}
+ className={cn("rounded-2xl", selected && "bg-thread-selected")}
>
<ListRowLayout {...content} />
</RowPressable>
diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
index 7b742cdbb96..ac9ef97706c 100644
--- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
@@ -6,7 +6,6 @@ import type { AppBarProps } from "../../../components/ui/AppBar.types";
import { AppBar } from "../../../components/ui/AppBar";
import { ScreenContent as SettingsScreenContent } from "../../../components/ui/ScreenContent";
import { useWorkspaceTabs } from "../../workspace/WorkspaceTabsContext";
-import { useWorkspaceSurface } from "../../workspace/useWorkspaceSurface";
import { useDeviceType } from "../../../native/native-layout-metrics";
import { useCompactWorkspaceTabs } from "../../workspace/useSystemWorkspaceTabBar";
import { useAdaptiveWorkspaceLayout } from "../../layout/adaptive-workspace-context";
@@ -27,7 +26,6 @@ export function SettingsScreen(
const navigation = useNavigation();
const route = useRoute();
const workspace = useWorkspaceTabs();
- const surface = useWorkspaceSurface();
const deviceType = useDeviceType();
const compactTabs = useCompactWorkspaceTabs();
const { layout } = useAdaptiveWorkspaceLayout();
@@ -37,9 +35,7 @@ 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";
+ const surfaceClassName = workspaceRoot || cover ? "bg-screen" : "bg-sheet";
return (
<View collapsable={false} className={`flex-1 ${surfaceClassName}`}>
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
index bd9524f15ad..bed075eea31 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
@@ -16,7 +16,6 @@ import { NativeStackScreenOptions } from "../../native/StackHeader";
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
import { isDuoDevice } from "../../lib/device-type";
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
-import { useWorkspaceSurface } from "./useWorkspaceSurface";
import {
useDeviceType,
useNativeColumnLayoutMetrics,
@@ -81,7 +80,6 @@ function WorkspaceRootContent() {
const columnMetrics = useNativeColumnLayoutMetrics();
const nativeMetrics = useNativeLayoutMetrics();
const deviceType = useDeviceType();
- const surface = useWorkspaceSurface();
const systemTabBar = useSystemWorkspaceTabBar();
const compactTabs = useCompactWorkspaceTabs();
const enabled = useEnabledNavigationTabs();
@@ -128,7 +126,7 @@ function WorkspaceRootContent() {
return (
<WorkspaceTabsContext value={context}>
- <View className={`flex-1 ${sidebarPicker ? "bg-drawer" : surface.className}`}>
+ <View className={sidebarPicker ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
{Platform.OS === "ios" ? (
<NativeStackScreenOptions
optionsVersion={[
diff --git a/apps/mobile/src/features/workspace/android-workspace-navigation-colors.test.ts b/apps/mobile/src/features/workspace/android-workspace-navigation-colors.test.ts
index de33d9c6786..35513187eab 100644
--- a/apps/mobile/src/features/workspace/android-workspace-navigation-colors.test.ts
+++ b/apps/mobile/src/features/workspace/android-workspace-navigation-colors.test.ts
@@ -45,6 +45,12 @@ describe("Android workspace navigation colors", () => {
] as const) {
expectVisibleSelection(androidWorkspaceNavigationColors(variables, rail, floating));
}
+ if (appearance === "dark") {
+ const pill = androidWorkspaceNavigationColors(variables, false, true).containerColor;
+ for (const surface of ["--color-screen", "--color-grouped-card"] as const) {
+ expect(contrast(pill, variables[surface]), surface).toBeGreaterThanOrEqual(1.25);
+ }
+ }
expect(variables).toEqual(snapshot);
}
});
diff --git a/apps/mobile/src/features/workspace/android-workspace-navigation-colors.ts b/apps/mobile/src/features/workspace/android-workspace-navigation-colors.ts
index 7064d037f68..48216bfec42 100644
--- a/apps/mobile/src/features/workspace/android-workspace-navigation-colors.ts
+++ b/apps/mobile/src/features/workspace/android-workspace-navigation-colors.ts
@@ -1,23 +1,41 @@
import {
flattenThemeColor,
+ isDarkThemeColor,
themeColorWithAlpha,
themeColorWithContrast,
type MobileThemeVariables,
} from "../../lib/mobileTheme";
+// A dark page swallows the native shadow, so the fill alone has to lift the pill off the page
+// and off the cards it floats over.
+function floatingContainerColor(colors: MobileThemeVariables) {
+ const screen = colors["--color-screen"];
+ const fill = flattenThemeColor(colors["--color-secondary"], screen);
+ if (!isDarkThemeColor(screen)) return fill;
+ return themeColorWithContrast(
+ fill,
+ [screen, flattenThemeColor(colors["--color-grouped-card"], screen)],
+ 1.25,
+ );
+}
+
export function androidWorkspaceNavigationColors(
colors: MobileThemeVariables,
rail: boolean,
floating = false,
) {
- const header = flattenThemeColor(colors["--color-header"], colors["--color-screen"]);
+ const screen = colors["--color-screen"];
+ const header = flattenThemeColor(colors["--color-header"], screen);
const containerColor = rail
? header
: floating
- ? flattenThemeColor(colors["--color-secondary"], colors["--color-screen"])
+ ? floatingContainerColor(colors)
: flattenThemeColor(themeColorWithAlpha(colors["--color-header-foreground"], 0.05), header);
+ // The lifted dark pill already took the secondary fill's place, so its indicator lifts further.
const indicatorColor = themeColorWithContrast(
- flattenThemeColor(colors["--color-secondary"], containerColor),
+ floating && isDarkThemeColor(screen)
+ ? containerColor
+ : flattenThemeColor(colors["--color-secondary"], containerColor),
containerColor,
1.5,
);
diff --git a/apps/mobile/src/features/workspace/useWorkspaceSurface.ts b/apps/mobile/src/features/workspace/useWorkspaceSurface.ts
deleted file mode 100644
index 6b9c664ecf8..00000000000
--- a/apps/mobile/src/features/workspace/useWorkspaceSurface.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { useControlTheme } from "../../components/ui/useControlTheme";
-import { useDeviceType } from "../../native/native-layout-metrics";
-
-export function useWorkspaceSurface() {
- const cover = useDeviceType() === "duo-folded";
- const { colors } = useControlTheme();
- return {
- className: cover ? "bg-drawer" : "bg-screen",
- backgroundColor: colors[cover ? "--color-drawer" : "--color-screen"],
- };
-}
diff --git a/apps/mobile/src/lib/mobileTheme.test.ts b/apps/mobile/src/lib/mobileTheme.test.ts
index 31fc6f83f11..0b35a5ba27d 100644
--- a/apps/mobile/src/lib/mobileTheme.test.ts
+++ b/apps/mobile/src/lib/mobileTheme.test.ts
@@ -193,6 +193,28 @@ describe("mobile themes", () => {
`${appearance}: ${role} on Android header`,
).toBeGreaterThanOrEqual(4.5);
}
+ if (appearance === "dark") {
+ for (const surface of [variables["--color-screen"], header]) {
+ expect(
+ contrastRatio(group, surface),
+ `dark grouped surface on Android ${surface}`,
+ ).toBeGreaterThanOrEqual(1.2);
+ }
+ }
+ }
+ const selected = variables["--color-thread-selected"];
+ expect(
+ contrastRatio(selected, flattenThemeColor(variables["--color-drawer"], sheet)),
+ `${platform} ${appearance}: selected row on drawer`,
+ ).toBeGreaterThanOrEqual(1.2);
+ for (const role of [
+ "--color-thread-selected-foreground",
+ "--color-thread-selected-foreground-muted",
+ ] as const) {
+ expect(
+ contrastRatio(variables[role], selected),
+ `${platform} ${appearance}: ${role} on selected row`,
+ ).toBeGreaterThanOrEqual(4.5);
}
expect(
contrastRatio(variables["--color-foreground-muted"], variables["--color-secondary"]),
diff --git a/apps/mobile/src/lib/mobileThemeVariables.ts b/apps/mobile/src/lib/mobileThemeVariables.ts
index e2ea7be7227..48f697d5455 100644
--- a/apps/mobile/src/lib/mobileThemeVariables.ts
+++ b/apps/mobile/src/lib/mobileThemeVariables.ts
@@ -1,8 +1,10 @@
import defaultThemeVariables from "../../generated-uniwind-default-theme-variables.json";
import {
DEFAULT_MOBILE_THEME_ID,
+ flattenThemeColor,
getMobileThemeVariables,
themeColorWithAlpha,
+ themeColorWithContrast,
type MobileThemeAppearance,
type MobileThemeId,
type MobileThemeVariables,
@@ -12,10 +14,46 @@ const defaults = defaultThemeVariables as Readonly<
Record<MobileThemeAppearance, MobileThemeVariables>
>;
+const CARD_TEXT_ROLES = [
+ "--color-foreground-secondary",
+ "--color-foreground-muted",
+ "--color-placeholder",
+ "--color-primary-text",
+] as const;
+
+// A selected row in a sidebar sits on the drawer, so it must stay visible there with its labels.
+function withVisibleSelection(variables: MobileThemeVariables): MobileThemeVariables {
+ const selected = themeColorWithContrast(
+ flattenThemeColor(variables["--color-thread-selected"], variables["--color-drawer"]),
+ flattenThemeColor(variables["--color-drawer"], variables["--color-screen"]),
+ 1.2,
+ );
+ return {
+ ...variables,
+ "--color-thread-selected": selected,
+ "--color-thread-selected-foreground": themeColorWithContrast(
+ variables["--color-thread-selected-foreground"],
+ selected,
+ ),
+ "--color-thread-selected-foreground-muted": themeColorWithContrast(
+ variables["--color-thread-selected-foreground-muted"],
+ selected,
+ ),
+ };
+}
+
export function getMobileThemeRuntimeVariables(
themeId: MobileThemeId,
appearance: MobileThemeAppearance,
platform: string,
+): MobileThemeVariables {
+ return withVisibleSelection(platformThemeVariables(themeId, appearance, platform));
+}
+
+function platformThemeVariables(
+ themeId: MobileThemeId,
+ appearance: MobileThemeAppearance,
+ platform: string,
): MobileThemeVariables {
const usesDefaultPalette = themeId === DEFAULT_MOBILE_THEME_ID || themeId === "material-you";
const variables = usesDefaultPalette
@@ -36,10 +74,24 @@ export function getMobileThemeRuntimeVariables(
}
if (platform !== "android") return variables;
+ // Android paints the drawer as the page inside a lighter frame, so dark cards lift off both.
+ const screen = variables["--color-screen"];
+ const groupedCard =
+ appearance === "dark"
+ ? themeColorWithContrast(
+ variables["--color-grouped-card"],
+ [screen, flattenThemeColor(frame, screen)],
+ 1.2,
+ )
+ : variables["--color-grouped-card"];
+ const readableOnCard = (role: (typeof CARD_TEXT_ROLES)[number]) =>
+ [role, themeColorWithContrast(variables[role], groupedCard)] as const;
return {
...variables,
+ ...Object.fromEntries(CARD_TEXT_ROLES.map(readableOnCard)),
"--color-header": frame,
"--color-header-foreground": variables["--color-drawer-foreground"],
- "--color-drawer": variables["--color-screen"],
+ "--color-drawer": screen,
+ "--color-grouped-card": groupedCard,
};
}