Skip to content

Commit 77a2e69

Browse files
t3dotggclaude
andcommitted
fix(android): foldable sidebar and layout fixes
Combines #21049, #21044, #21043, and #21041, and adds: - The sidebar opens threads before the first navigation action. - The Nightly badge hides when the narrow sidebar header cannot fit it. - The 640dp Android reading width from #19424. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 16918b5 commit 77a2e69

22 files changed

Lines changed: 297 additions & 259 deletions

‎apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3WorkspaceNavigationModule.kt‎

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ package expo.modules.t3nativecontrols
33
import android.content.Context
44
import android.view.ViewGroup
55
import androidx.compose.foundation.layout.WindowInsets
6-
import androidx.compose.foundation.layout.Spacer
76
import androidx.compose.foundation.layout.fillMaxSize
87
import androidx.compose.material3.Icon
98
import androidx.compose.material3.MaterialTheme
109
import androidx.compose.material3.NavigationBar
1110
import androidx.compose.material3.NavigationBarItem
1211
import androidx.compose.material3.NavigationBarItemDefaults
13-
import androidx.compose.material3.NavigationRail
14-
import androidx.compose.material3.NavigationRailItem
15-
import androidx.compose.material3.NavigationRailItemDefaults
1612
import androidx.compose.material3.Text
1713
import androidx.compose.material3.darkColorScheme
1814
import androidx.compose.material3.lightColorScheme
@@ -39,7 +35,6 @@ class T3WorkspaceNavigationModule : Module() {
3935
Prop("selectedTab") { view: T3WorkspaceNavigationView, value: String ->
4036
view.selectedTab = value
4137
}
42-
Prop("rail") { view: T3WorkspaceNavigationView, value: Boolean -> view.rail = value }
4338
Prop("dark") { view: T3WorkspaceNavigationView, value: Boolean -> view.dark = value }
4439
Prop("textScale") { view: T3WorkspaceNavigationView, value: Float -> view.textScale = value }
4540
Prop("containerColor") { view: T3WorkspaceNavigationView, value: Int ->
@@ -59,7 +54,7 @@ class T3WorkspaceNavigationModule : Module() {
5954
}
6055
}
6156

62-
/** One Material3 selection surface moves from below the list to its leading edge. */
57+
/** Material3 bottom navigation for the compact workspace. */
6358
class T3WorkspaceNavigationView(
6459
context: Context,
6560
appContext: AppContext
@@ -69,7 +64,6 @@ class T3WorkspaceNavigationView(
6964

7065
private val onTabSelected by EventDispatcher()
7166
var selectedTab by mutableStateOf("threads")
72-
var rail by mutableStateOf(false)
7367
var dark by mutableStateOf(false)
7468
var textScale by mutableStateOf(1f)
7569
var containerColor by mutableStateOf(0)
@@ -108,58 +102,29 @@ class T3WorkspaceNavigationView(
108102
setContent {
109103
MaterialTheme(colorScheme = if (dark) darkColorScheme() else lightColorScheme()) {
110104
val tabs = listOf("threads", "pullRequests")
111-
if (rail) {
112-
NavigationRail(
113-
modifier = Modifier.fillMaxSize(),
114-
containerColor = Color(containerColor),
115-
windowInsets = WindowInsets(0),
116-
) {
117-
Spacer(Modifier.weight(1f))
118-
tabs.forEach { tab ->
119-
NavigationRailItem(
120-
selected = selectedTab == tab,
121-
onClick = { onTabSelected(mapOf("tab" to tab)) },
122-
icon = { tabIcon(tab) },
123-
label = {
124-
val title = if (tab == "threads") "Chats" else "PRs"
125-
Text(title, fontSize = (12 * textScale).sp)
126-
},
127-
colors = NavigationRailItemDefaults.colors(
128-
selectedIconColor = Color(selectedColor),
129-
selectedTextColor = Color(selectedColor),
130-
indicatorColor = Color(indicatorColor),
131-
unselectedIconColor = Color(unselectedColor),
132-
unselectedTextColor = Color(unselectedColor),
133-
),
134-
)
135-
}
136-
Spacer(Modifier.weight(1f))
137-
}
138-
} else {
139-
NavigationBar(
140-
modifier = Modifier.fillMaxSize(),
141-
containerColor = Color(containerColor),
142-
tonalElevation = androidx.compose.ui.unit.Dp(0f),
143-
windowInsets = WindowInsets(0),
144-
) {
145-
tabs.forEach { tab ->
146-
NavigationBarItem(
147-
selected = selectedTab == tab,
148-
onClick = { onTabSelected(mapOf("tab" to tab)) },
149-
icon = { tabIcon(tab) },
150-
label = {
151-
val title = if (tab == "threads") "Chats" else "Pull requests"
152-
Text(title, fontSize = (12 * textScale).sp)
153-
},
154-
colors = NavigationBarItemDefaults.colors(
155-
selectedIconColor = Color(selectedColor),
156-
selectedTextColor = Color(selectedColor),
157-
indicatorColor = Color(indicatorColor),
158-
unselectedIconColor = Color(unselectedColor),
159-
unselectedTextColor = Color(unselectedColor),
160-
),
161-
)
162-
}
105+
NavigationBar(
106+
modifier = Modifier.fillMaxSize(),
107+
containerColor = Color(containerColor),
108+
tonalElevation = androidx.compose.ui.unit.Dp(0f),
109+
windowInsets = WindowInsets(0),
110+
) {
111+
tabs.forEach { tab ->
112+
NavigationBarItem(
113+
selected = selectedTab == tab,
114+
onClick = { onTabSelected(mapOf("tab" to tab)) },
115+
icon = { tabIcon(tab) },
116+
label = {
117+
val title = if (tab == "threads") "Chats" else "Pull requests"
118+
Text(title, fontSize = (12 * textScale).sp)
119+
},
120+
colors = NavigationBarItemDefaults.colors(
121+
selectedIconColor = Color(selectedColor),
122+
selectedTextColor = Color(selectedColor),
123+
indicatorColor = Color(indicatorColor),
124+
unselectedIconColor = Color(unselectedColor),
125+
unselectedTextColor = Color(unselectedColor),
126+
),
127+
)
163128
}
164129
}
165130
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import { useResolveClassNames } from "uniwind";
3131

3232
import { AppText as Text } from "./components/ui/AppText";
33+
import { androidWorkspaceDestinationAnimation } from "./lib/android-workspace-navigation";
3334
import { getCompactBrandHeaderOptions } from "./components/CompactBrandTitle";
3435
import { WorkspaceRootScreen } from "./features/workspace/WorkspaceRootScreen";
3536
import { AndroidWorkspaceTabsProvider } from "./features/workspace/AndroidWorkspaceTabsProvider";
@@ -1007,15 +1008,17 @@ function ScreenRenderFallback(props: RenderFailureProps & { readonly routeName:
10071008
export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navigator }) {
10081009
const { width, height } = useWindowDimensions();
10091010
const nativeMetrics = useNativeLayoutMetrics();
1010-
const usesWorkspaceFlowScreens =
1011-
Platform.OS === "android" || deriveLayout({ width, height, nativeMetrics }).usesSplitView;
1011+
const usesSplitView = deriveLayout({ width, height, nativeMetrics }).usesSplitView;
1012+
const usesWorkspaceFlowScreens = Platform.OS === "android" || usesSplitView;
10121013

10131014
return (
10141015
<Navigator
10151016
screenLayout={GuardedScreenLayout}
10161017
screenOptions={({ route }) => {
10171018
if (route.name !== "SettingsSheet" && route.name !== "NewTaskSheet") {
1018-
return {};
1019+
return Platform.OS === "android"
1020+
? { animation: androidWorkspaceDestinationAnimation(route.name, usesSplitView) }
1021+
: {};
10191022
}
10201023

10211024
return usesWorkspaceFlowScreens

‎apps/mobile/src/components/CompactBrandTitle.tsx‎

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NATIVE_WORKSPACE_COLUMNS_SUPPORTED } from "../native/NativeWorkspaceColumns";
22
import Constants from "expo-constants";
33
import type { NativeStackNavigationOptions } from "@react-navigation/native-stack";
4+
import { useState } from "react";
45
import { Platform, View } from "react-native";
56

67
import { AppText as Text } from "./ui/AppText";
@@ -18,20 +19,37 @@ export function CompactBrandTitle(
1819
props: {
1920
readonly allowFontScaling?: boolean;
2021
readonly accessibilityLabel?: string;
22+
/**
23+
* Fills the parent row and drops the stage badge when the full title does not fit.
24+
* Narrow Android sidebar headers otherwise draw their actions over the badge.
25+
*/
26+
readonly fit?: boolean;
2127
} = {},
2228
) {
2329
const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
2430
const titleOffset = brandTitleOffset();
2531
const { scale } = useAndroidControlSizing();
32+
const [availableWidth, setAvailableWidth] = useState<number | null>(null);
33+
// Measured only while the badge shows, so hiding it does not make it look like it fits.
34+
const [fullWidth, setFullWidth] = useState<number | null>(null);
35+
const showStage =
36+
!props.fit || availableWidth === null || fullWidth === null || fullWidth <= availableWidth;
2637

27-
return (
38+
const title = (
2839
<View
40+
onLayout={
41+
props.fit && showStage ? (event) => setFullWidth(event.nativeEvent.layout.width) : undefined
42+
}
2943
aria-level={1}
3044
accessibilityLabel={props.accessibilityLabel ?? "T3 Code, Threads"}
3145
accessible
3246
role="heading"
3347
className="flex-row items-center gap-1.5"
34-
style={[{ marginLeft: titleOffset }, Platform.OS === "android" && { gap: 5.25 * scale }]}
48+
style={[
49+
{ marginLeft: titleOffset },
50+
Platform.OS === "android" && { gap: 5.25 * scale },
51+
props.fit && { flexShrink: 0 },
52+
]}
3553
>
3654
<T3Wordmark colorClassName="accent-icon" height={Math.round(15 * scale)} />
3755
<Text
@@ -41,23 +59,36 @@ export function CompactBrandTitle(
4159
>
4260
Code
4361
</Text>
44-
<View
45-
className="rounded-full bg-subtle px-1.5 py-0.5"
46-
style={
47-
Platform.OS === "android"
48-
? { paddingHorizontal: 5.25 * scale, paddingVertical: 1.75 * scale }
49-
: undefined
50-
}
51-
>
52-
<Text
53-
allowFontScaling={props.allowFontScaling}
54-
className="font-t3-bold text-foreground-muted uppercase"
55-
style={{ fontSize: 9 * scale, letterSpacing: 0.9 * scale }}
62+
{showStage ? (
63+
<View
64+
className="rounded-full bg-subtle px-1.5 py-0.5"
65+
style={
66+
Platform.OS === "android"
67+
? { paddingHorizontal: 5.25 * scale, paddingVertical: 1.75 * scale }
68+
: undefined
69+
}
5670
>
57-
{stageLabel}
58-
</Text>
59-
</View>
71+
<Text
72+
allowFontScaling={props.allowFontScaling}
73+
className="font-t3-bold text-foreground-muted uppercase"
74+
style={{ fontSize: 9 * scale, letterSpacing: 0.9 * scale }}
75+
>
76+
{stageLabel}
77+
</Text>
78+
</View>
79+
) : null}
80+
</View>
81+
);
82+
83+
return props.fit ? (
84+
<View
85+
className="min-w-0 flex-1 flex-row items-center"
86+
onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)}
87+
>
88+
{title}
6089
</View>
90+
) : (
91+
title
6192
);
6293
}
6394

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import { NativeThemeHost } from "./NativeThemeHost.android";
22
import { Switch as ComposeSwitch } from "@expo/ui/jetpack-compose";
3-
import { View } from "react-native";
3+
import { Pressable, View } from "react-native";
44
import type { ThemedSwitchProps } from "./NativeSwitch.types";
55

66
import { useControlTheme } from "./useControlTheme";
77

8-
/** Material's native switch, with the same palette and accessibility contract as our RN controls. */
8+
/**
9+
* Material's native switch, with the same palette and accessibility contract as our RN controls.
10+
* Compose only draws it. The RN Pressable owns the touch so it wins over a pressable parent row;
11+
* with Compose handling touches, a tap on the switch ran the row's onPress instead.
12+
*/
913
export function NativeSwitch(props: ThemedSwitchProps) {
1014
const { colors } = useControlTheme();
11-
const toggle = () => {
12-
if (!props.disabled) props.onValueChange?.(!props.value);
13-
};
1415

1516
return (
16-
<View
17-
accessible
17+
<Pressable
18+
disabled={props.disabled}
19+
onPress={() => props.onValueChange?.(!props.value)}
1820
accessibilityLabel={props.accessibilityLabel}
1921
accessibilityHint={props.accessibilityHint}
2022
accessibilityRole="switch"
2123
accessibilityState={{ checked: Boolean(props.value), disabled: Boolean(props.disabled) }}
22-
accessibilityActions={[{ name: "activate", label: "Toggle" }]}
23-
onAccessibilityAction={toggle}
2424
style={props.style}
2525
testID={props.testID}
2626
>
27-
<View importantForAccessibility="no-hide-descendants">
27+
<View importantForAccessibility="no-hide-descendants" pointerEvents="none">
2828
<NativeThemeHost ignoreSafeAreaKeyboardInsets style={{ width: 52, height: 48 }}>
2929
<ComposeSwitch
3030
value={Boolean(props.value)}
3131
enabled={!props.disabled}
32-
onCheckedChange={props.onValueChange ?? undefined}
3332
colors={{
3433
checkedTrackColor: colors["--color-switch-active-track"],
3534
checkedThumbColor: colors["--color-switch-active-thumb"],
@@ -41,6 +40,6 @@ export function NativeSwitch(props: ThemedSwitchProps) {
4140
/>
4241
</NativeThemeHost>
4342
</View>
44-
</View>
43+
</Pressable>
4544
);
4645
}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { use, useCallback, useEffect, useMemo, useRef, useState, type ComponentP
1818
import {
1919
Platform,
2020
ScrollView,
21+
useWindowDimensions,
2122
View,
2223
type ScrollViewProps,
2324
type GestureResponderEvent,
@@ -30,6 +31,10 @@ import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSw
3031
import { useSafeAreaInsets } from "react-native-safe-area-context";
3132

3233
import { cn } from "../../lib/cn";
34+
import {
35+
ANDROID_READING_MAX_WIDTH,
36+
deriveCenteredContentHorizontalPadding,
37+
} from "../../lib/layout";
3338
import { EmptyState } from "../../components/ui/EmptyState";
3439
import { FloatingActionButton } from "../../components/ui/FloatingActionButton";
3540
import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel";
@@ -264,6 +269,17 @@ export function HomeScreen(props: HomeScreenProps) {
264269
const contentSideInsets = usesNativeWorkspaceColumns
265270
? (columnMetrics ?? screenMetrics)?.safeArea
266271
: undefined;
272+
// Android lists that span a wide window (foldables in portrait) keep the
273+
// reading width, so rows stay clear of the edges and the camera cutout.
274+
const { width: windowWidth } = useWindowDimensions();
275+
const androidListGutter =
276+
Platform.OS === "android"
277+
? deriveCenteredContentHorizontalPadding({
278+
viewportWidth: windowWidth,
279+
maxContentWidth: ANDROID_READING_MAX_WIDTH,
280+
minimumPadding: 0,
281+
})
282+
: 0;
267283
const iosBottomClearance = Math.max(
268284
columnMetrics?.safeArea.bottom ?? insets.bottom,
269285
24,
@@ -1027,8 +1043,10 @@ export function HomeScreen(props: HomeScreenProps) {
10271043
{...scrollGateHandlers}
10281044
scrollEventThrottle={16}
10291045
contentContainerStyle={{
1030-
paddingLeft: (contentSideInsets?.left ?? 0) + (primaryColumn ? 8 : 0),
1031-
paddingRight: (contentSideInsets?.right ?? 0) + (primaryColumn ? 8 : 0),
1046+
paddingLeft:
1047+
(contentSideInsets?.left ?? 0) + (primaryColumn ? 8 : 0) + androidListGutter,
1048+
paddingRight:
1049+
(contentSideInsets?.right ?? 0) + (primaryColumn ? 8 : 0) + androidListGutter,
10321050
paddingBottom:
10331051
Platform.OS === "ios"
10341052
? iosBottomClearance

‎apps/mobile/src/features/home/ThreadListToolbar.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useEffect, useRef, useState, type ComponentProps } from "react";
22
import { useNavigation, useNavigationState } from "@react-navigation/native";
33
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
4+
import { useWorkspaceListNavigation } from "../workspace/useAndroidWorkspaceNavigation";
45
import {
56
BackHandler,
67
Keyboard,
@@ -47,6 +48,7 @@ export function ThreadListToolbar(props: {
4748
const { height: toolbarHeight, ...headerPadding } = useToolbarLayout();
4849
const { state } = useWorkspaceState();
4950
const { onRequestVisibility, onSearchQueryChange } = props;
51+
const showPullRequests = useWorkspaceListNavigation("pullRequests");
5052
const searchRef = useRef<TextInputInstance>(null);
5153
const [searchOpen, setSearchOpen] = useState(false);
5254
const searching = searchOpen || props.searchQuery.length > 0;
@@ -121,9 +123,16 @@ export function ThreadListToolbar(props: {
121123
<WorkspaceConnectionTitle
122124
grow
123125
onPress={props.onOpenEnvironments}
124-
brand={<CompactBrandTitle allowFontScaling={false} />}
126+
brand={<CompactBrandTitle allowFontScaling={false} fit />}
125127
/>
126128
</View>
129+
{props.sidebar && workspace ? (
130+
<AndroidHeaderIconButton
131+
accessibilityLabel="Show pull requests"
132+
icon="arrow.triangle.pull"
133+
onPress={showPullRequests}
134+
/>
135+
) : null}
127136
<AndroidHeaderIconButton
128137
accessibilityLabel="Search threads"
129138
icon="magnifyingglass"

0 commit comments

Comments
 (0)