Skip to content

Commit f91b0bb

Browse files
committed
feat(mobile): add Usage and Settings to workspace navigation
1 parent 66ee628 commit f91b0bb

39 files changed

Lines changed: 1218 additions & 306 deletions

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

Lines changed: 7 additions & 5 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)) },
@@ -272,7 +272,7 @@ class T3WorkspaceNavigationView(
272272
onNewThread(emptyMap<String, Any>())
273273
}
274274
Spacer(Modifier.weight(1f))
275-
TABS.forEach { tab ->
275+
tabs.forEach { tab ->
276276
railItem(tab, fraction) {
277277
expanded = false
278278
onTabSelected(mapOf("tab" to tab))
@@ -356,7 +356,8 @@ class T3WorkspaceNavigationView(
356356

357357
private fun tabTitle(tab: String) = when (tab) {
358358
"threads" -> "Chats"
359-
"pullRequests" -> "PRs"
359+
"pullRequests" -> "Pulls"
360+
"usage" -> "Usage"
360361
else -> "Settings"
361362
}
362363

@@ -368,6 +369,7 @@ class T3WorkspaceNavigationView(
368369
when (tab) {
369370
"threads" -> R.drawable.t3_chats
370371
"pullRequests" -> R.drawable.t3_pull_requests
372+
"usage" -> R.drawable.t3_usage
371373
else -> R.drawable.t3_settings
372374
}
373375
)
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: 138 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,155 @@
11
import ExpoModulesCore
22
import UIKit
33

4-
final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
4+
private final class WorkspaceTabBar: UITabBar {
5+
var onContentLayout: ((CGRect) -> Void)?
6+
7+
override func layoutSubviews() {
8+
super.layoutSubviews()
9+
let row = tabButton(in: self).map { convert($0.bounds, from: $0) }
10+
onContentLayout?(row ?? safeAreaLayoutGuide.layoutFrame)
11+
}
12+
13+
override func safeAreaInsetsDidChange() {
14+
super.safeAreaInsetsDidChange()
15+
invalidateIntrinsicContentSize()
16+
}
17+
18+
private func tabButton(in view: UIView) -> UIView? {
19+
for subview in view.subviews where !subview.isHidden {
20+
if subview is UIControl, subview.accessibilityIdentifier?.hasPrefix("workspace-tab-") == true {
21+
return subview
22+
}
23+
if let button = tabButton(in: subview) { return button }
24+
}
25+
return nil
26+
}
27+
}
28+
29+
final class T3SidebarTabBarView: ExpoView, UITabBarDelegate, UIToolbarDelegate {
530
let onSelectionChange = EventDispatcher()
6-
private let tabBar = UITabBar()
7-
var selectedIndex = 0 { didSet { updateSelection() } }
31+
let onCompose = EventDispatcher()
32+
private let tabBar = WorkspaceTabBar()
33+
private let composeButton = UIButton(type: .system)
34+
private let composeToolbar = UIToolbar()
35+
private lazy var tabBarTrailing = tabBar.trailingAnchor.constraint(equalTo: trailingAnchor)
36+
private lazy var composeWidth = composeButton.widthAnchor.constraint(equalToConstant: 60)
37+
private lazy var composeHeight = composeButton.heightAnchor.constraint(equalToConstant: 60)
38+
private var itemsByTab: [String: UITabBarItem] = [:]
39+
var tabs = ["threads", "pullRequests", "usage", "settings"] {
40+
didSet { if tabs != oldValue { updateItems() } }
41+
}
42+
var selectedTab = "threads" { didSet { updateSelection() } }
843
var selectedColor: UIColor = .systemBlue { didSet { tabBar.tintColor = selectedColor } }
44+
var compact = false {
45+
didSet {
46+
configureCompose()
47+
tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
48+
tabBar.setNeedsLayout()
49+
}
50+
}
51+
var showsCompose = false {
52+
didSet {
53+
composeToolbar.isHidden = !showsCompose
54+
tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
55+
setNeedsLayout()
56+
}
57+
}
958
var appearance = "light" {
1059
didSet { overrideUserInterfaceStyle = appearance == "dark" ? .dark : .light }
1160
}
1261

1362
required init(appContext: AppContext? = nil) {
1463
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"))
2364
tabBar.itemPositioning = .fill
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+
NSLayoutConstraint.activate([composeWidth, composeHeight])
79+
composeToolbar.items = [UIBarButtonItem(customView: composeButton)]
80+
composeToolbar.delegate = self
81+
composeToolbar.isHidden = true
82+
addSubview(composeToolbar)
83+
configureCompose()
84+
prepareItems()
85+
updateItems()
2786
}
2887

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

130+
private func layoutCompose(alongside frame: CGRect) {
131+
guard showsCompose, frame.height > 0 else { return }
132+
let row = convert(frame, from: tabBar)
133+
let buttonHeight = row.height + (compact ? 8 : 0)
134+
composeWidth.constant = buttonHeight
135+
composeHeight.constant = buttonHeight
136+
let width = buttonHeight + 16
137+
let height = composeToolbar.sizeThatFits(CGSize(width: width, height: bounds.height)).height
138+
composeToolbar.frame = CGRect(x: bounds.width - 8 - width, y: row.midY - height / 2, width: width, height: height)
139+
composeToolbar.layoutIfNeeded()
140+
}
141+
142+
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
143+
if showsCompose, let target = composeButton.hitTest(convert(point, to: composeButton), with: event) {
144+
return target
145+
}
146+
return tabBar.hitTest(convert(point, to: tabBar), with: event)
147+
}
148+
149+
func position(for bar: UIBarPositioning) -> UIBarPosition {
150+
.bottom
151+
}
152+
35153
override func didMoveToWindow() {
36154
super.didMoveToWindow()
37155
updateSelection()
@@ -49,12 +167,13 @@ final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
49167
}
50168

51169
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]
170+
guard let item = itemsByTab[selectedTab], tabBar.items?.contains(item) == true else { return }
171+
guard tabBar.selectedItem !== item else { return }
172+
tabBar.selectedItem = item
55173
}
56174

57175
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
58-
onSelectionChange(["index": item.tag])
176+
guard tabs.indices.contains(item.tag) else { return }
177+
onSelectionChange(["tab": tabs[item.tag]])
59178
}
60179
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import {
8484
} from "./features/threads/ThreadSettingsSheet";
8585
import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
8686
import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
87+
import { SettingsNavigationRouteScreen } from "./features/settings/SettingsNavigationRouteScreen";
8788
import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
8889
import { SettingsClientStorageRouteScreen } from "./features/settings/SettingsClientStorageRouteScreen";
8990
import { SettingsDiagnosticsRouteScreen } from "./features/diagnostics/SettingsDiagnosticsRouteScreen";
@@ -292,6 +293,11 @@ const SettingsContentStack = createV5SheetStackNavigator({
292293
title: "Archived Threads",
293294
},
294295
}),
296+
SettingsNavigation: createNativeStackScreen({
297+
screen: SettingsNavigationRouteScreen,
298+
linking: "navigation-tabs",
299+
options: { title: "Navigation tabs" },
300+
}),
295301
SettingsAppearance: createNativeStackScreen({
296302
screen: SettingsAppearanceRouteScreen,
297303
linking: "appearance",

‎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)