Skip to content

Commit 4ed939b

Browse files
committed
fix(mobile): restore Android workspace navigation and headers
1 parent cafe620 commit 4ed939b

20 files changed

Lines changed: 627 additions & 74 deletions

‎apps/mobile/modules/t3-native-controls/android/build.gradle‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
buildscript {
2+
repositories { mavenCentral() }
3+
dependencies {
4+
classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:${kotlinVersion}")
5+
}
6+
}
7+
18
apply plugin: 'com.android.library'
29
apply plugin: 'org.jetbrains.kotlin.android'
10+
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
311

412
group = 'com.t3tools.nativecontrols'
513
version = '0.0.0'
@@ -12,8 +20,11 @@ android {
1220
minSdkVersion rootProject.ext.minSdkVersion
1321
targetSdkVersion rootProject.ext.targetSdkVersion
1422
}
23+
buildFeatures { compose true }
1524
}
1625

1726
dependencies {
1827
implementation project(':expo-modules-core')
28+
implementation 'androidx.compose.ui:ui-android:1.10.6'
29+
implementation 'androidx.compose.material3:material3-android:1.5.0-alpha17'
1930
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package expo.modules.t3nativecontrols
2+
3+
import android.content.Context
4+
import android.view.ViewGroup
5+
import androidx.compose.foundation.layout.WindowInsets
6+
import androidx.compose.foundation.layout.Spacer
7+
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.material3.Icon
9+
import androidx.compose.material3.MaterialTheme
10+
import androidx.compose.material3.NavigationBar
11+
import androidx.compose.material3.NavigationBarItem
12+
import androidx.compose.material3.NavigationBarItemDefaults
13+
import androidx.compose.material3.NavigationRail
14+
import androidx.compose.material3.NavigationRailItem
15+
import androidx.compose.material3.NavigationRailItemDefaults
16+
import androidx.compose.material3.Text
17+
import androidx.compose.material3.darkColorScheme
18+
import androidx.compose.material3.lightColorScheme
19+
import androidx.compose.runtime.getValue
20+
import androidx.compose.runtime.mutableStateOf
21+
import androidx.compose.runtime.setValue
22+
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.graphics.Color
24+
import androidx.compose.ui.platform.ComposeView
25+
import androidx.compose.ui.platform.ViewCompositionStrategy
26+
import androidx.compose.ui.res.painterResource
27+
import androidx.compose.ui.unit.sp
28+
import expo.modules.kotlin.AppContext
29+
import expo.modules.kotlin.modules.Module
30+
import expo.modules.kotlin.modules.ModuleDefinition
31+
import expo.modules.kotlin.viewevent.EventDispatcher
32+
import expo.modules.kotlin.views.ExpoView
33+
34+
class T3WorkspaceNavigationModule : Module() {
35+
override fun definition() = ModuleDefinition {
36+
Name("T3WorkspaceNavigation")
37+
View(T3WorkspaceNavigationView::class) {
38+
Prop("selectedTab") { view: T3WorkspaceNavigationView, value: String -> view.selectedTab = value }
39+
Prop("rail") { view: T3WorkspaceNavigationView, value: Boolean -> view.rail = value }
40+
Prop("dark") { view: T3WorkspaceNavigationView, value: Boolean -> view.dark = value }
41+
Prop("textScale") { view: T3WorkspaceNavigationView, value: Float -> view.textScale = value }
42+
Prop("containerColor") { view: T3WorkspaceNavigationView, value: Int -> view.containerColor = value }
43+
Prop("selectedColor") { view: T3WorkspaceNavigationView, value: Int -> view.selectedColor = value }
44+
Prop("indicatorColor") { view: T3WorkspaceNavigationView, value: Int -> view.indicatorColor = value }
45+
Prop("unselectedColor") { view: T3WorkspaceNavigationView, value: Int -> view.unselectedColor = value }
46+
Events("onTabSelected")
47+
}
48+
}
49+
}
50+
51+
/** One Material3 selection surface moves from below the list to its leading edge. */
52+
class T3WorkspaceNavigationView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
53+
// Compose must remeasure native children when Yoga resizes the folded window.
54+
override val shouldUseAndroidLayout = true
55+
56+
private val onTabSelected by EventDispatcher()
57+
var selectedTab by mutableStateOf("threads")
58+
var rail by mutableStateOf(false)
59+
var dark by mutableStateOf(false)
60+
var textScale by mutableStateOf(1f)
61+
var containerColor by mutableStateOf(0)
62+
var selectedColor by mutableStateOf(0)
63+
var indicatorColor by mutableStateOf(0)
64+
var unselectedColor by mutableStateOf(0)
65+
66+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
67+
// Fabric measures the replacement bar before attaching it on a fold.
68+
// Compose needs an attached window to obtain its lifecycle recomposer.
69+
if (!isAttachedToWindow) {
70+
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec))
71+
return
72+
}
73+
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
74+
}
75+
76+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
77+
if (isAttachedToWindow) super.onLayout(changed, left, top, right, bottom)
78+
}
79+
80+
override fun onAttachedToWindow() {
81+
super.onAttachedToWindow()
82+
requestLayout()
83+
}
84+
85+
init {
86+
addView(ComposeView(context).apply {
87+
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool)
88+
setContent {
89+
MaterialTheme(colorScheme = if (dark) darkColorScheme() else lightColorScheme()) {
90+
val tabs = listOf("threads", "pullRequests")
91+
if (rail) {
92+
NavigationRail(
93+
modifier = Modifier.fillMaxSize(),
94+
containerColor = Color(containerColor),
95+
windowInsets = WindowInsets(0),
96+
) {
97+
Spacer(Modifier.weight(1f))
98+
tabs.forEach { tab ->
99+
NavigationRailItem(
100+
selected = selectedTab == tab,
101+
onClick = { onTabSelected(mapOf("tab" to tab)) },
102+
icon = { TabIcon(tab) },
103+
label = { Text(if (tab == "threads") "Chats" else "PRs", fontSize = (12 * textScale).sp) },
104+
colors = NavigationRailItemDefaults.colors(
105+
selectedIconColor = Color(selectedColor),
106+
selectedTextColor = Color(selectedColor),
107+
indicatorColor = Color(indicatorColor),
108+
unselectedIconColor = Color(unselectedColor),
109+
unselectedTextColor = Color(unselectedColor),
110+
),
111+
)
112+
}
113+
Spacer(Modifier.weight(1f))
114+
}
115+
} else {
116+
NavigationBar(
117+
modifier = Modifier.fillMaxSize(),
118+
containerColor = Color(containerColor),
119+
tonalElevation = androidx.compose.ui.unit.Dp(0f),
120+
windowInsets = WindowInsets(0),
121+
) {
122+
tabs.forEach { tab ->
123+
NavigationBarItem(
124+
selected = selectedTab == tab,
125+
onClick = { onTabSelected(mapOf("tab" to tab)) },
126+
icon = { TabIcon(tab) },
127+
label = { Text(if (tab == "threads") "Chats" else "Pull requests", fontSize = (12 * textScale).sp) },
128+
colors = NavigationBarItemDefaults.colors(
129+
selectedIconColor = Color(selectedColor),
130+
selectedTextColor = Color(selectedColor),
131+
indicatorColor = Color(indicatorColor),
132+
unselectedIconColor = Color(unselectedColor),
133+
unselectedTextColor = Color(unselectedColor),
134+
),
135+
)
136+
}
137+
}
138+
}
139+
}
140+
}
141+
}, LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
142+
}
143+
144+
@androidx.compose.runtime.Composable
145+
private fun TabIcon(tab: String) {
146+
Icon(
147+
painter = painterResource(if (tab == "threads") R.drawable.t3_chats else R.drawable.t3_pull_requests),
148+
contentDescription = if (tab == "threads") "Chats" else "Pull requests",
149+
)
150+
}
151+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:fillColor="#000000" android:pathData="M20,2H4C2.9,2 2,2.9 2,4V22L6,18H20C21.1,18 22,17.1 22,16V4C22,2.9 21.1,2 20,2ZM20,16H5.17L4,17.17V4H20V16ZM6,6H18V8H6V6ZM6,10H16V12H6V10Z" />
3+
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
2+
<path android:fillColor="#000000" android:pathData="M6,2C4.34,2 3,3.34 3,5C3,6.31 3.84,7.42 5,7.83V16.17C3.84,16.58 3,17.69 3,19C3,20.66 4.34,22 6,22C7.66,22 9,20.66 9,19C9,17.69 8.16,16.58 7,16.17V7.83C8.16,7.42 9,6.31 9,5C9,3.34 7.66,2 6,2ZM6,4C6.55,4 7,4.45 7,5C7,5.55 6.55,6 6,6C5.45,6 5,5.55 5,5C5,4.45 5.45,4 6,4ZM6,18C6.55,18 7,18.45 7,19C7,19.55 6.55,20 6,20C5.45,20 5,19.55 5,19C5,18.45 5.45,18 6,18ZM14,2L10,6L14,10V7H15C16.1,7 17,7.9 17,9V16.17C15.84,16.58 15,17.69 15,19C15,20.66 16.34,22 18,22C19.66,22 21,20.66 21,19C21,17.69 20.16,16.58 19,16.17V9C19,6.79 17.21,5 15,5H14V2ZM18,18C18.55,18 19,18.45 19,19C19,19.55 18.55,20 18,20C17.45,20 17,19.55 17,19C17,18.45 17.45,18 18,18Z" />
3+
</vector>

‎apps/mobile/modules/t3-native-controls/expo-module.config.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"android": {
88
"modules": [
99
"expo.modules.t3nativecontrols.T3NativeControlsModule",
10+
"expo.modules.t3nativecontrols.T3WorkspaceNavigationModule",
1011
"expo.modules.t3nativecontrols.T3KeyboardCommandsModule"
1112
]
1213
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { useResolveClassNames } from "uniwind";
3131
import { AppText as Text } from "./components/AppText";
3232
import { getCompactBrandHeaderOptions } from "./components/CompactBrandTitle";
3333
import { WorkspaceRootScreen } from "./features/workspace/WorkspaceRootScreen";
34+
import { AndroidWorkspaceTabsProvider } from "./features/workspace/AndroidWorkspaceTabsProvider";
3435
import {
3536
PullRequestRouteScreen,
3637
PullRequestFileRouteScreen,
@@ -170,6 +171,12 @@ const GLASS_HEADER_OPTIONS: AppScreenOptions = {
170171
unstable_navigationItemStyle: NATIVE_LIQUID_GLASS_SUPPORTED ? "editor" : undefined,
171172
};
172173

174+
// Android PR screens render their own Material toolbar.
175+
const PULL_REQUEST_HEADER_OPTIONS: AppScreenOptions = {
176+
...GLASS_HEADER_OPTIONS,
177+
headerShown: Platform.OS !== "android",
178+
};
179+
173180
// SOLID: opaque sheet-colored header for surfaces that manage their own viewport.
174181
const SOLID_HEADER_OPTIONS: AppScreenOptions = {
175182
headerBackButtonDisplayMode: "minimal",
@@ -647,13 +654,15 @@ function RootStackLayout(props: {
647654
<ThreadOutboxDrainWorker />
648655
<ShowcaseCaptureCoordinator pathname={pathname} />
649656
<ExistingThreadSettingsRouteProvider>
650-
<AdaptiveWorkspaceLayout
651-
pathname={workspaceLocation.pathname}
652-
workspaceRouteKey={workspaceLocation.routeKey}
653-
>
654-
{props.children}
655-
<HardwareKeyboardCommandOverlay />
656-
</AdaptiveWorkspaceLayout>
657+
<AndroidWorkspaceTabsProvider>
658+
<AdaptiveWorkspaceLayout
659+
pathname={workspaceLocation.pathname}
660+
workspaceRouteKey={workspaceLocation.routeKey}
661+
>
662+
{props.children}
663+
<HardwareKeyboardCommandOverlay />
664+
</AdaptiveWorkspaceLayout>
665+
</AndroidWorkspaceTabsProvider>
657666
</ExistingThreadSettingsRouteProvider>
658667
</HardwareKeyboardCommandProvider>
659668
);
@@ -721,15 +730,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
721730
path: "pull-requests/:environmentId/:projectId/:repository/:number",
722731
parse: { number: Number },
723732
},
724-
options: GLASS_HEADER_OPTIONS,
733+
options: PULL_REQUEST_HEADER_OPTIONS,
725734
}),
726735
PullRequestGuideStop: createNativeStackScreen({
727736
screen: PullRequestGuideStopScreen,
728-
options: GLASS_HEADER_OPTIONS,
737+
options: PULL_REQUEST_HEADER_OPTIONS,
729738
}),
730739
PullRequestFile: createNativeStackScreen({
731740
screen: PullRequestFileRouteScreen,
732-
options: GLASS_HEADER_OPTIONS,
741+
options: PULL_REQUEST_HEADER_OPTIONS,
733742
}),
734743
PullRequestFiles: createNativeStackScreen({
735744
screen: PullRequestFilesRouteScreen,
@@ -743,7 +752,7 @@ const RootStackConfig = createWorkspaceStackNavigator({
743752
PullRequestReviewers: createNativeStackScreen({
744753
screen: PullRequestReviewersScreen,
745754
options: {
746-
...GLASS_HEADER_OPTIONS,
755+
...PULL_REQUEST_HEADER_OPTIONS,
747756
...FORM_SHEET_PRESENTATION_OPTIONS,
748757
sheetAllowedDetents: [0.75, 0.92],
749758
sheetGrabberVisible: true,
@@ -752,7 +761,7 @@ const RootStackConfig = createWorkspaceStackNavigator({
752761
}),
753762
PullRequestDiscussion: createNativeStackScreen({
754763
screen: PullRequestDiscussionScreen,
755-
options: GLASS_HEADER_OPTIONS,
764+
options: PULL_REQUEST_HEADER_OPTIONS,
756765
}),
757766
PullRequestInlineComment: createNativeStackScreen({
758767
screen: PullRequestInlineCommentScreen,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ export function HomeHeader(props: HomeHeaderProps) {
9292
[props],
9393
);
9494

95-
if (props.usesWorkspaceToolbar) return null;
96-
9795
return (
9896
<>
9997
<NativeStackScreenOptions options={{ headerShown: false }} />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function HomeRouteScreen() {
209209

210210
return (
211211
<AndroidHomeFabLayout
212-
disabled={workspace !== null}
212+
disabled={workspace !== null && Platform.OS !== "android"}
213213
onStartNewTask={() => navigation.navigate("NewTaskSheet", { screen: "NewTask" })}
214214
>
215215
<>
@@ -230,7 +230,7 @@ export function HomeRouteScreen() {
230230
params: { screen: "SettingsEnvironments" },
231231
}),
232232
}),
233-
headerShown: true,
233+
headerShown: Platform.OS !== "android",
234234
}}
235235
/>
236236
)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ export function HomeScreen(props: HomeScreenProps) {
983983
const v2ListHeader = (
984984
<>
985985
{listHeader}
986-
{workspace ? (
986+
{Platform.OS === "ios" && workspace ? (
987987
<ThreadListFilters
988988
environments={props.environments}
989989
projects={projectScopes.map((scope) => ({ key: scope.key, label: scope.title }))}

0 commit comments

Comments
 (0)