Skip to content

Commit 6d85e7c

Browse files
committed
feat(mobile): float Android workspace tabs beside New thread
1 parent 6524a8d commit 6d85e7c

10 files changed

Lines changed: 136 additions & 80 deletions

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

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,40 @@ package expo.modules.t3nativecontrols
22

33
import android.content.Context
44
import android.view.ViewGroup
5+
import androidx.compose.foundation.background
6+
import androidx.compose.foundation.layout.Box
7+
import androidx.compose.foundation.layout.Row
58
import androidx.compose.foundation.layout.WindowInsets
69
import androidx.compose.foundation.layout.Spacer
10+
import androidx.compose.foundation.layout.fillMaxHeight
711
import androidx.compose.foundation.layout.fillMaxSize
12+
import androidx.compose.foundation.layout.padding
13+
import androidx.compose.foundation.selection.selectable
14+
import androidx.compose.foundation.selection.selectableGroup
15+
import androidx.compose.foundation.shape.CircleShape
816
import androidx.compose.material3.Icon
17+
import androidx.compose.material3.LocalContentColor
918
import androidx.compose.material3.MaterialTheme
10-
import androidx.compose.material3.NavigationBar
11-
import androidx.compose.material3.NavigationBarItem
12-
import androidx.compose.material3.NavigationBarItemDefaults
1319
import androidx.compose.material3.NavigationRail
1420
import androidx.compose.material3.NavigationRailItem
1521
import androidx.compose.material3.NavigationRailItemDefaults
22+
import androidx.compose.material3.Surface
1623
import androidx.compose.material3.Text
1724
import androidx.compose.material3.darkColorScheme
1825
import androidx.compose.material3.lightColorScheme
1926
import androidx.compose.runtime.Composable
2027
import androidx.compose.runtime.getValue
2128
import androidx.compose.runtime.mutableStateOf
2229
import androidx.compose.runtime.setValue
30+
import androidx.compose.ui.Alignment
2331
import androidx.compose.ui.Modifier
32+
import androidx.compose.ui.draw.clip
2433
import androidx.compose.ui.graphics.Color
2534
import androidx.compose.ui.platform.ComposeView
2635
import androidx.compose.ui.platform.ViewCompositionStrategy
2736
import androidx.compose.ui.res.painterResource
37+
import androidx.compose.ui.semantics.Role
38+
import androidx.compose.ui.unit.dp
2839
import androidx.compose.ui.unit.sp
2940
import expo.modules.kotlin.AppContext
3041
import expo.modules.kotlin.modules.Module
@@ -59,7 +70,7 @@ class T3WorkspaceNavigationModule : Module() {
5970
}
6071
}
6172

62-
/** One Material3 selection surface moves from below the list to its leading edge. */
73+
/** Compact windows use an icon pill; expanded windows retain the Material navigation rail. */
6374
class T3WorkspaceNavigationView(
6475
context: Context,
6576
appContext: AppContext
@@ -100,8 +111,12 @@ class T3WorkspaceNavigationView(
100111
}
101112

102113
init {
114+
clipChildren = false
115+
clipToPadding = false
103116
addView(
104117
ComposeView(context).apply {
118+
clipChildren = false
119+
clipToPadding = false
105120
setViewCompositionStrategy(
106121
ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool
107122
)
@@ -136,29 +151,39 @@ class T3WorkspaceNavigationView(
136151
Spacer(Modifier.weight(1f))
137152
}
138153
} else {
139-
NavigationBar(
154+
Surface(
140155
modifier = Modifier.fillMaxSize(),
141-
containerColor = Color(containerColor),
142-
tonalElevation = androidx.compose.ui.unit.Dp(0f),
143-
windowInsets = WindowInsets(0),
156+
shape = CircleShape,
157+
color = Color(containerColor),
158+
// Match the resting elevation of the Compose New thread FAB.
159+
shadowElevation = 6.dp,
144160
) {
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-
)
161+
Row(
162+
modifier = Modifier.fillMaxSize().selectableGroup(),
163+
verticalAlignment = Alignment.CenterVertically,
164+
) {
165+
tabs.forEach { tab ->
166+
val selected = selectedTab == tab
167+
Box(
168+
modifier = Modifier
169+
.weight(1f)
170+
.fillMaxHeight()
171+
.clip(CircleShape)
172+
.selectable(
173+
selected = selected,
174+
role = Role.Tab,
175+
onClick = { onTabSelected(mapOf("tab" to tab)) },
176+
)
177+
.padding(4.dp)
178+
.background(
179+
if (selected) Color(indicatorColor) else Color.Transparent,
180+
CircleShape,
181+
),
182+
contentAlignment = Alignment.Center,
183+
) {
184+
tabIcon(tab, Color(if (selected) selectedColor else unselectedColor))
185+
}
186+
}
162187
}
163188
}
164189
}
@@ -170,7 +195,7 @@ class T3WorkspaceNavigationView(
170195
}
171196

172197
@Composable
173-
private fun tabIcon(tab: String) {
198+
private fun tabIcon(tab: String, tint: Color = LocalContentColor.current) {
174199
val drawable = if (tab == "threads") {
175200
R.drawable.t3_chats
176201
} else {
@@ -179,6 +204,7 @@ class T3WorkspaceNavigationView(
179204
Icon(
180205
painter = painterResource(drawable),
181206
contentDescription = if (tab == "threads") "Chats" else "Pull requests",
207+
tint = tint,
182208
)
183209
}
184210
}

‎apps/mobile/src/components/MaterialNewThreadButton.shared.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function MaterialNewThreadButton(props: {
99
readonly onPress: () => void;
1010
readonly extended?: boolean;
1111
readonly expanded?: boolean;
12+
readonly maxWidth?: number;
1213
readonly className?: string;
1314
readonly style?: StyleProp<ViewStyle>;
1415
}) {

‎apps/mobile/src/components/MaterialScrollComposeButton.android.tsx‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Box, ExtendedFloatingActionButton, Host, Icon, Text } from "@expo/ui/je
22
import {
33
defaultMinSize,
44
fillMaxWidth,
5-
graphicsLayer,
65
height,
76
onSizeChanged,
87
size,
@@ -16,18 +15,17 @@ import { resolveScaledTextRole } from "../lib/appearancePreferences";
1615
/** Keep the animated width and icon positioning entirely inside Compose, not Yoga. */
1716
export function MaterialScrollComposeButton(props: {
1817
readonly expanded: boolean;
18+
readonly maxWidth?: number;
1919
readonly onPress: () => void;
2020
readonly className?: string;
2121
readonly style?: StyleProp<ViewStyle>;
2222
}) {
2323
const { appearance, themeAppearance, themeVariables: colors } = useAppearancePreferences();
2424
const typography = resolveScaledTextRole("footnote", appearance.baseFontSize);
2525
const { iconSize, fabSize } = useAndroidControlSizing();
26-
// Scale the native 56dp minimum; keep text and icons at their requested sizes.
27-
const nativeSize = Math.max(56, fabSize);
28-
const scale = fabSize / nativeSize;
29-
const nativeIconSize = Math.round(iconSize / scale);
30-
const [buttonWidth, setButtonWidth] = useState(nativeSize);
26+
const [buttonWidth, setButtonWidth] = useState(fabSize);
27+
const expanded =
28+
props.expanded && (props.maxWidth === undefined || buttonWidth <= props.maxWidth);
3129
const rememberWidth = useCallback(({ width }: { width: number }) => {
3230
setButtonWidth((previous) => Math.max(previous, width));
3331
}, []);
@@ -46,25 +44,19 @@ export function MaterialScrollComposeButton(props: {
4644
>
4745
<Box modifiers={[fillMaxWidth()]} contentAlignment="centerEnd">
4846
<ExtendedFloatingActionButton
49-
expanded={props.expanded}
47+
expanded={expanded}
5048
containerColor={colors["--color-primary"]}
5149
modifiers={[
52-
defaultMinSize({ minWidth: nativeSize }),
53-
height(nativeSize),
54-
graphicsLayer({
55-
scaleX: scale,
56-
scaleY: scale,
57-
transformOriginX: 1,
58-
transformOriginY: 0,
59-
}),
50+
defaultMinSize({ minWidth: fabSize }),
51+
height(fabSize),
6052
onSizeChanged(rememberWidth),
6153
]}
6254
>
6355
<ExtendedFloatingActionButton.Icon>
64-
<Box modifiers={[size(nativeIconSize, nativeIconSize)]}>
56+
<Box modifiers={[size(iconSize, iconSize)]}>
6557
<Icon
6658
source={require("../../assets/icons/compose.xml")}
67-
size={nativeIconSize}
59+
size={iconSize}
6860
tint={colors["--color-primary-foreground"]}
6961
/>
7062
</Box>
@@ -73,8 +65,8 @@ export function MaterialScrollComposeButton(props: {
7365
<Text
7466
color={colors["--color-primary-foreground"]}
7567
style={{
76-
fontSize: typography.fontSize / scale,
77-
lineHeight: typography.lineHeight / scale,
68+
fontSize: typography.fontSize,
69+
lineHeight: typography.lineHeight,
7870
fontWeight: "500",
7971
}}
8072
>
@@ -97,8 +89,8 @@ export function MaterialScrollComposeButton(props: {
9789
top: 0,
9890
bottom: 0,
9991
// Release the label area as soon as collapse starts, before native measurements arrive.
100-
width: props.expanded ? buttonWidth * scale : fabSize,
101-
borderRadius: 16 * scale,
92+
width: expanded ? buttonWidth : fabSize,
93+
borderRadius: 16,
10294
overflow: "hidden",
10395
}}
10496
/>

‎apps/mobile/src/features/home/AndroidHomeFab.android.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ import {
77
} from "react-native";
88
import { useSafeAreaInsets } from "react-native-safe-area-context";
99
import { MaterialNewThreadButton } from "../../components/MaterialNewThreadButton";
10+
import { useAndroidControlSizing } from "../../components/useAndroidControlSizing";
1011
import type { AndroidHomeFabLayout as SharedAndroidHomeFabLayout } from "./AndroidHomeFab.shared";
1112
import { useWorkspaceState } from "../../state/workspace";
1213
import { MaterialFabScrollContext } from "./MaterialFabScrollContext";
1314
import { updateMaterialFabScroll } from "./material-fab-scroll";
1415
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
16+
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
17+
import { ANDROID_WORKSPACE_DOCK } from "../workspace/workspace-tabs-state";
1518

1619
export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidHomeFabLayout>) {
1720
const insets = useSafeAreaInsets();
1821
const { appearance } = useAppearancePreferences();
1922
const { fontScale } = useWindowDimensions();
23+
const { scale } = useAndroidControlSizing();
24+
const workspace = useWorkspaceTabs();
2025
const [layoutWidth, setLayoutWidth] = useState<number | null>(null);
2126
const { state } = useWorkspaceState();
2227
const [expanded, setExpanded] = useState(true);
@@ -41,6 +46,15 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
4146
key={`${appearance.baseFontSize}:${fontScale}:${layoutWidth}`}
4247
extended
4348
expanded={expanded}
49+
maxWidth={
50+
workspace && !props.sidebar
51+
? layoutWidth -
52+
Math.max(insets.left, ANDROID_WORKSPACE_DOCK.edge) -
53+
ANDROID_WORKSPACE_DOCK.tabsWidth * Math.max(1, scale) -
54+
ANDROID_WORKSPACE_DOCK.gap -
55+
20
56+
: undefined
57+
}
4458
onPress={props.onStartNewTask}
4559
className="absolute right-5"
4660
style={{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,10 @@ export function HomeScreen(props: HomeScreenProps) {
942942
Platform.OS === "android" && "overflow-hidden rounded-t-[28px]",
943943
)}
944944
style={{
945-
paddingBottom: Platform.OS === "ios" ? iosBottomClearance : Math.max(insets.bottom, 24),
945+
paddingBottom:
946+
Platform.OS === "ios"
947+
? iosBottomClearance
948+
: Math.max(insets.bottom, workspace?.bottomClearance ?? 0, 24),
946949
paddingTop: NATIVE_LIQUID_GLASS_SUPPORTED ? insets.top + 72 : 0,
947950
paddingLeft: 32 + (contentSideInsets?.left ?? 0),
948951
paddingRight: 32 + (contentSideInsets?.right ?? 0),
@@ -1030,7 +1033,7 @@ export function HomeScreen(props: HomeScreenProps) {
10301033
<View className="flex-1 bg-header">
10311034
<View
10321035
className="flex-1 items-center justify-center overflow-hidden rounded-t-[28px] bg-screen px-4"
1033-
style={{ paddingBottom: insets.bottom }}
1036+
style={{ paddingBottom: Math.max(insets.bottom, workspace?.bottomClearance ?? 0) }}
10341037
>
10351038
{v2ListEmpty}
10361039
</View>

‎apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useAndroidControlSizing } from "../../components/useAndroidControlSizin
1515
import { androidWorkspaceNavigationColors } from "./android-workspace-navigation-colors";
1616
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
1717
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
18-
import type { WorkspaceTab } from "./workspace-tabs-state";
18+
import { ANDROID_WORKSPACE_DOCK, type WorkspaceTab } from "./workspace-tabs-state";
1919

2020
export const ANDROID_WORKSPACE_RAIL_WIDTH = 80;
2121

@@ -47,7 +47,7 @@ export function AndroidWorkspaceNavigation(props: {
4747
const insets = useSafeAreaInsets();
4848
const keyboardVisible = useKeyboardState((state) => state.isVisible);
4949
const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
50-
const { scale } = useAndroidControlSizing();
50+
const { scale, fabSize } = useAndroidControlSizing();
5151
const rail = Boolean(props.rail);
5252
const { containerColor, indicatorColor, selectedColor, unselectedColor } =
5353
androidWorkspaceNavigationColors(colors, rail);
@@ -64,7 +64,7 @@ export function AndroidWorkspaceNavigation(props: {
6464
paddingTop: insets.top,
6565
paddingBottom: insets.bottom,
6666
}
67-
: { paddingBottom: insets.bottom }),
67+
: { borderRadius: 999 }),
6868
}}
6969
>
7070
<NativeNavigation
@@ -87,7 +87,14 @@ export function AndroidWorkspaceNavigation(props: {
8787
}
8888
props.onSelect?.();
8989
}}
90-
style={rail ? { flex: 1 } : { height: 80 * Math.max(1, scale) }}
90+
style={
91+
rail
92+
? { flex: 1 }
93+
: {
94+
width: ANDROID_WORKSPACE_DOCK.tabsWidth * Math.max(1, scale),
95+
height: fabSize,
96+
}
97+
}
9198
/>
9299
</View>
93100
);

0 commit comments

Comments
 (0)