Skip to content

Commit 91455de

Browse files
authored
feat(mobile): add Usage and Settings to workspace navigation (pingdotgg#23841)
1 parent c893353 commit 91455de

44 files changed

Lines changed: 1487 additions & 410 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ import expo.modules.kotlin.modules.ModuleDefinition
6363
import expo.modules.kotlin.viewevent.EventDispatcher
6464
import expo.modules.kotlin.views.ExpoView
6565

66-
private val TABS = listOf("threads", "pullRequests", "settings")
67-
6866
class T3WorkspaceNavigationModule : Module() {
6967
override fun definition() = ModuleDefinition {
7068
Name("T3WorkspaceNavigation")
7169
View(T3WorkspaceNavigationView::class) {
70+
Prop("tabs") { view: T3WorkspaceNavigationView, value: List<String> -> view.tabs = value }
7271
Prop("selectedTab") { view: T3WorkspaceNavigationView, value: String ->
7372
view.selectedTab = value
7473
}
@@ -121,6 +120,7 @@ class T3WorkspaceNavigationView(
121120
private val onTabSelected by EventDispatcher()
122121
private val onNewThread by EventDispatcher()
123122
private val onOverlayChange by EventDispatcher()
123+
var tabs by mutableStateOf(listOf("threads", "pullRequests", "usage", "settings"))
124124
var selectedTab by mutableStateOf("threads")
125125
var rail by mutableStateOf(false)
126126
var dark by mutableStateOf(false)
@@ -175,7 +175,7 @@ class T3WorkspaceNavigationView(
175175
tonalElevation = androidx.compose.ui.unit.Dp(0f),
176176
windowInsets = WindowInsets(0),
177177
) {
178-
TABS.forEach { tab ->
178+
tabs.forEach { tab ->
179179
NavigationBarItem(
180180
selected = selectedTab == tab,
181181
onClick = { onTabSelected(mapOf("tab" to tab)) },
@@ -267,12 +267,14 @@ class T3WorkspaceNavigationView(
267267
)
268268
}
269269
}
270-
newThreadButton(fraction) {
271-
expanded = false
272-
onNewThread(emptyMap<String, Any>())
270+
if (selectedTab == "threads") {
271+
newThreadButton(fraction) {
272+
expanded = false
273+
onNewThread(emptyMap<String, Any>())
274+
}
273275
}
274276
Spacer(Modifier.weight(1f))
275-
TABS.forEach { tab ->
277+
tabs.forEach { tab ->
276278
railItem(tab, fraction) {
277279
expanded = false
278280
onTabSelected(mapOf("tab" to tab))
@@ -356,7 +358,8 @@ class T3WorkspaceNavigationView(
356358

357359
private fun tabTitle(tab: String) = when (tab) {
358360
"threads" -> "Chats"
359-
"pullRequests" -> "PRs"
361+
"pullRequests" -> "Pulls"
362+
"usage" -> "Usage"
360363
else -> "Settings"
361364
}
362365

@@ -368,6 +371,7 @@ class T3WorkspaceNavigationView(
368371
when (tab) {
369372
"threads" -> R.drawable.t3_chats
370373
"pullRequests" -> R.drawable.t3_pull_requests
374+
"usage" -> R.drawable.t3_usage
371375
else -> R.drawable.t3_settings
372376
}
373377
)
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:fillType="evenOdd" android:pathData="M4,20V10H8V20ZM10,20V4H14V20ZM16,20V7H20V20Z" />
3+
</vector>

‎apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ public final class T3NativeControlsModule: Module {
3434

3535
View(T3SidebarTabBarView.self) {
3636
ViewName("SidebarTabBar")
37-
Events("onSelectionChange")
38-
Prop("selectedIndex") { (view: T3SidebarTabBarView, value: Int) in view.selectedIndex = value }
37+
Events("onSelectionChange", "onCompose")
38+
Prop("tabs") { (view: T3SidebarTabBarView, value: [String]) in view.tabs = value }
39+
Prop("selectedTab") { (view: T3SidebarTabBarView, value: String) in view.selectedTab = value }
3940
Prop("selectedColor") { (view: T3SidebarTabBarView, value: UIColor) in view.selectedColor = value }
41+
Prop("showsCompose") { (view: T3SidebarTabBarView, value: Bool) in view.showsCompose = value }
42+
Prop("compact") { (view: T3SidebarTabBarView, value: Bool) in view.compact = value }
4043
Prop("appearance") { (view: T3SidebarTabBarView, value: String) in view.appearance = value }
4144
}
4245

Lines changed: 121 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,139 @@
11
import ExpoModulesCore
22
import UIKit
33

4+
private final class WorkspaceTabBar: UITabBar {
5+
var onContentLayout: ((CGRect) -> Void)?
6+
7+
override func layoutSubviews() {
8+
super.layoutSubviews()
9+
let row = tabButtons(in: self).reduce(CGRect.null) { $0.union(convert($1.bounds, from: $1)) }
10+
if !row.isNull { onContentLayout?(row) }
11+
}
12+
13+
override func safeAreaInsetsDidChange() {
14+
super.safeAreaInsetsDidChange()
15+
invalidateIntrinsicContentSize()
16+
}
17+
18+
private func tabButtons(in view: UIView) -> [UIView] {
19+
view.subviews.filter { !$0.isHidden }.flatMap { subview in
20+
if subview is UIControl, subview.accessibilityIdentifier?.hasPrefix("workspace-tab-") == true {
21+
return [subview]
22+
}
23+
return tabButtons(in: subview)
24+
}
25+
}
26+
}
27+
428
final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
529
let onSelectionChange = EventDispatcher()
6-
private let tabBar = UITabBar()
7-
var selectedIndex = 0 { didSet { updateSelection() } }
30+
let onCompose = EventDispatcher()
31+
private let tabBar = WorkspaceTabBar()
32+
private let composeButton = UIButton(type: .system)
33+
private lazy var tabBarTrailing = tabBar.trailingAnchor.constraint(equalTo: trailingAnchor)
34+
private var itemsByTab: [String: UITabBarItem] = [:]
35+
var tabs = ["threads", "pullRequests", "usage", "settings"] {
36+
didSet { if tabs != oldValue { updateItems() } }
37+
}
38+
var selectedTab = "threads" { didSet { updateSelection() } }
839
var selectedColor: UIColor = .systemBlue { didSet { tabBar.tintColor = selectedColor } }
40+
var compact = false {
41+
didSet {
42+
tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
43+
tabBar.setNeedsLayout()
44+
}
45+
}
46+
var showsCompose = false {
47+
didSet {
48+
composeButton.isHidden = !showsCompose
49+
tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
50+
setNeedsLayout()
51+
}
52+
}
953
var appearance = "light" {
1054
didSet { overrideUserInterfaceStyle = appearance == "dark" ? .dark : .light }
1155
}
1256

1357
required init(appContext: AppContext? = nil) {
1458
super.init(appContext: appContext)
15-
let iconBundle = Bundle(for: Self.self).url(forResource: "T3NativeControlIcons", withExtension: "bundle").flatMap(Bundle.init(url:))
16-
let pullRequestIcon = UIImage(named: "pull-request", in: iconBundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
17-
tabBar.items = [
18-
UITabBarItem(title: "Threads", image: tabIcon(UIImage(systemName: "text.bubble")), tag: 0),
19-
UITabBarItem(title: "Pulls", image: tabIcon(pullRequestIcon), tag: 1),
20-
]
21-
tabBar.items?.last?.accessibilityLabel = "Pull requests"
22-
tabBar.items?.first?.selectedImage = tabIcon(UIImage(systemName: "text.bubble.fill"))
2359
tabBar.itemPositioning = .fill
60+
// iPad's regular bar uses a compressed inline row even with fill positioning.
61+
// This floating sidebar control needs the same full-size items as a phone bar.
62+
if #available(iOS 17.0, *) {
63+
tabBar.traitOverrides.horizontalSizeClass = .compact
64+
}
2465
tabBar.delegate = self
66+
tabBar.translatesAutoresizingMaskIntoConstraints = false
2567
addSubview(tabBar)
26-
updateSelection()
68+
NSLayoutConstraint.activate([
69+
tabBar.leadingAnchor.constraint(equalTo: leadingAnchor),
70+
tabBarTrailing,
71+
tabBar.bottomAnchor.constraint(equalTo: bottomAnchor),
72+
])
73+
// UIKit's floating row changes with window geometry. Follow its laid-out items
74+
// instead of estimating their position from a second set of safe-area updates.
75+
tabBar.onContentLayout = { [weak self] frame in self?.layoutCompose(alongside: frame) }
76+
composeButton.accessibilityLabel = "New chat"
77+
composeButton.addAction(UIAction { [weak self] _ in self?.onCompose() }, for: .touchUpInside)
78+
composeButton.isHidden = true
79+
addSubview(composeButton)
80+
configureCompose()
81+
prepareItems()
82+
updateItems()
2783
}
2884

29-
override func layoutSubviews() {
30-
super.layoutSubviews()
31-
tabBar.frame = bounds
85+
private func configureCompose() {
86+
var configuration: UIButton.Configuration
87+
if #available(iOS 26.0, *) {
88+
configuration = .glass()
89+
} else {
90+
configuration = .gray()
91+
}
92+
configuration.cornerStyle = .capsule
93+
configuration.baseForegroundColor = .label
94+
configuration.image = UIImage(systemName: "square.and.pencil")
95+
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 24)
96+
composeButton.configuration = configuration
97+
}
98+
99+
private func prepareItems() {
100+
let iconBundle = Bundle(for: Self.self).url(forResource: "T3NativeControlIcons", withExtension: "bundle").flatMap(Bundle.init(url:))
101+
let pullRequestIcon = UIImage(named: "pull-request", in: iconBundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
102+
let labels = ["threads": "Chats", "pullRequests": "PRs", "usage": "Usage", "settings": "Settings"]
103+
let symbols = ["threads": "text.bubble", "usage": "chart.bar.xaxis", "settings": "gearshape"]
104+
for (tab, label) in labels {
105+
let icon = tab == "pullRequests" ? pullRequestIcon : UIImage(systemName: symbols[tab] ?? "circle")
106+
let item = UITabBarItem(title: nil, image: tabIcon(icon), tag: 0)
107+
item.accessibilityLabel = label
108+
item.accessibilityIdentifier = "workspace-tab-\(tab)"
109+
if tab == "threads" { item.selectedImage = tabIcon(UIImage(systemName: "text.bubble.fill")) }
110+
itemsByTab[tab] = item
111+
}
112+
}
113+
114+
private func updateItems() {
115+
tabBar.items = tabs.enumerated().compactMap { index, tab in
116+
guard let item = itemsByTab[tab] else { return nil }
117+
item.tag = index
118+
return item
119+
}
32120
updateSelection()
33121
}
34122

123+
private func layoutCompose(alongside frame: CGRect) {
124+
guard showsCompose, frame.height > 0 else { return }
125+
let row = convert(frame, from: tabBar)
126+
let size = row.height + 8
127+
composeButton.frame = CGRect(x: row.maxX + 16, y: row.midY - size / 2, width: size, height: size)
128+
}
129+
130+
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
131+
if showsCompose, let target = composeButton.hitTest(convert(point, to: composeButton), with: event) {
132+
return target
133+
}
134+
return tabBar.hitTest(convert(point, to: tabBar), with: event)
135+
}
136+
35137
override func didMoveToWindow() {
36138
super.didMoveToWindow()
37139
updateSelection()
@@ -49,12 +151,13 @@ final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
49151
}
50152

51153
private func updateSelection() {
52-
guard let items = tabBar.items, items.indices.contains(selectedIndex) else { return }
53-
guard tabBar.selectedItem !== items[selectedIndex] else { return }
54-
tabBar.selectedItem = items[selectedIndex]
154+
guard let item = itemsByTab[selectedTab], tabBar.items?.contains(item) == true else { return }
155+
guard tabBar.selectedItem !== item else { return }
156+
tabBar.selectedItem = item
55157
}
56158

57159
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
58-
onSelectionChange(["index": item.tag])
160+
guard tabs.indices.contains(item.tag) else { return }
161+
onSelectionChange(["tab": tabs[item.tag]])
59162
}
60163
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
} from "./features/threads/ThreadSettingsSheet";
8686
import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
8787
import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
88+
import { SettingsNavigationRouteScreen } from "./features/settings/SettingsNavigationRouteScreen";
8889
import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
8990
import { SettingsClientStorageRouteScreen } from "./features/settings/SettingsClientStorageRouteScreen";
9091
import { SettingsDiagnosticsRouteScreen } from "./features/diagnostics/SettingsDiagnosticsRouteScreen";
@@ -237,6 +238,7 @@ const SettingsContentStack = createV5SheetStackNavigator({
237238
// Android draws its own app bar here. Hidden only from inside the screen, the native one
238239
// showed for the first frame of the Settings tab and pushed the page down.
239240
headerShown: Platform.OS !== "android",
241+
headerBackVisible: false,
240242
},
241243
}),
242244
SettingsEnvironments: createNativeStackScreen({
@@ -305,6 +307,11 @@ const SettingsContentStack = createV5SheetStackNavigator({
305307
title: "Archived Threads",
306308
},
307309
}),
310+
SettingsNavigation: createNativeStackScreen({
311+
screen: SettingsNavigationRouteScreen,
312+
linking: "navigation-tabs",
313+
options: { title: "Navigation tabs" },
314+
}),
308315
SettingsAppearance: createNativeStackScreen({
309316
screen: SettingsAppearanceRouteScreen,
310317
linking: "appearance",
@@ -975,8 +982,8 @@ const RootStackConfig = createWorkspaceStackNavigator({
975982
...NESTED_NAVIGATOR_OPTIONS,
976983
gestureEnabled: true,
977984
headerShown: false,
978-
// Android opens Settings as a top-level tab, so it swaps like the other tabs.
979-
...(Platform.OS === "android" ? { animation: "none" as const } : null),
985+
presentation: "card",
986+
animation: "none",
980987
},
981988
}),
982989
SettingsLegal: createNativeStackScreen({
@@ -1066,42 +1073,15 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navig
10661073
const { width, height } = useWindowDimensions();
10671074
const nativeMetrics = useNativeLayoutMetrics();
10681075
const usesSplitView = deriveLayout({ width, height, nativeMetrics }).usesSplitView;
1069-
const usesWorkspaceFlowScreens = Platform.OS === "android" || usesSplitView;
1070-
const flowPresentations = useRef(new Map<string, boolean>());
10711076

10721077
return (
10731078
<Navigator
10741079
screenLayout={(props) => <GuardedScreenLayout {...props} />}
1075-
screenListeners={{
1076-
state: ({ data }) => {
1077-
const keys = new Set(data.state.routes.map((route) => route.key));
1078-
for (const key of flowPresentations.current.keys()) {
1079-
if (!keys.has(key)) flowPresentations.current.delete(key);
1080-
}
1081-
},
1082-
}}
1083-
screenOptions={({ route }) => {
1084-
if (route.name !== "SettingsSheet") {
1085-
return Platform.OS === "android"
1086-
? { animation: androidWorkspaceDestinationAnimation(route.name, usesSplitView) }
1087-
: {};
1088-
}
1089-
1090-
// Moving an open flow between a sheet and a split column remounts its nested
1091-
// navigator. Keep its presentation until dismissal so folding preserves the settings flow.
1092-
let usesCard = flowPresentations.current.get(route.key);
1093-
if (usesCard === undefined) {
1094-
usesCard = usesWorkspaceFlowScreens;
1095-
flowPresentations.current.set(route.key, usesCard);
1096-
}
1097-
return usesCard
1098-
? { presentation: "card" }
1099-
: {
1100-
presentation: "formSheet",
1101-
sheetAllowedDetents: [1],
1102-
sheetGrabberVisible: true,
1103-
};
1104-
}}
1080+
screenOptions={({ route }) =>
1081+
Platform.OS === "android" && route.name !== "SettingsSheet"
1082+
? { animation: androidWorkspaceDestinationAnimation(route.name, usesSplitView) }
1083+
: {}
1084+
}
11051085
/>
11061086
);
11071087
});

‎apps/mobile/src/components/ui/ScreenScrollView.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import type { ComponentProps } from "react";
1+
import { createContext, use, type ComponentProps } from "react";
22
import { Platform } from "react-native";
33
import { NativeScrollView as ScrollView } from "../../native/NativeScrollViewMarker";
44

5+
export const ScreenScrollViewBottomInset = createContext(0);
6+
57
export function ScreenScrollView(props: ComponentProps<typeof ScrollView>) {
8+
const bottomInset = use(ScreenScrollViewBottomInset);
69
return (
710
<ScrollView
811
{...props}
12+
contentInset={
13+
Platform.OS === "ios" && bottomInset > 0
14+
? { ...props.contentInset, bottom: (props.contentInset?.bottom ?? 0) + bottomInset }
15+
: props.contentInset
16+
}
917
contentContainerStyle={[
1018
props.contentContainerStyle,
1119
Platform.OS === "android" && {

‎apps/mobile/src/features/home/home-thread-navigation.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function loadRouters() {
2121

2222
vi.mock("react-native", () => ({ Platform: { OS: "ios" }, Keyboard: { dismiss: vi.fn() } }));
2323

24+
vi.mock("../workspace/useAndroidWorkspaceSelection", () => ({
25+
useAndroidWorkspaceSelection: vi.fn(),
26+
}));
27+
2428
vi.mock("@react-navigation/native", () => {
2529
const { CommonActions, StackActions } = loadRouters();
2630
return { CommonActions, StackActions };

0 commit comments

Comments
 (0)