Skip to content

Commit 3941835

Browse files
committed
fix(android): smooth rail label motion when expanding and collapsing
Labels swap between "PRs" and "Pull Requests" at the rail item's invisible midpoint and stay transparent while sliding across their icon. Collapsing starts on tap, so labels and the New thread button finish before the modal rail closes, and the button's text no longer lingers over its icon. Tab icons drop a duplicate content description.
1 parent eaf3b0f commit 3941835

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ class T3WorkspaceNavigationView(
146146
val railState = rememberWideNavigationRailState()
147147
val scope = rememberCoroutineScope()
148148
// Mirrors ModalWideNavigationRail's internal modalExpanded threshold, so labels and
149-
// FABs expand on the frame the modal container starts widening, not before.
149+
// FABs expand on the frame the modal container starts widening, not before. Closing
150+
// starts at once so they finish collapsing before the modal's window goes away.
151+
val railOpening = railState.targetValue == WideNavigationRailValue.Expanded
150152
val modalProgress by animateFloatAsState(
151-
targetValue = if (railState.targetValue == WideNavigationRailValue.Expanded) 1f else 0f,
153+
targetValue = if (railOpening) 1f else 0f,
152154
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
153155
)
154-
val expandingRail = modalProgress >= 0.3f
156+
val expandingRail = railOpening && modalProgress >= 0.3f
155157
// The header composes in both the inline rail and the modal's dialog window; only
156158
// the modal copy expands, so the inline rail under the scrim never reflows.
157159
val hostView = LocalView.current
@@ -162,6 +164,11 @@ class T3WorkspaceNavigationView(
162164
contentPadding = PaddingValues(bottom = 12.dp),
163165
header = {
164166
val expandedRail = expandingRail && LocalView.current !== hostView
167+
// The extended FAB fades its text slower than it shrinks; keep it off the icon.
168+
val fabTextAlpha by animateFloatAsState(
169+
targetValue = if (expandedRail) 1f else 0f,
170+
animationSpec = MaterialTheme.motionScheme.fastEffectsSpec(),
171+
)
165172
Column(
166173
modifier = Modifier.padding(start = 20.dp),
167174
verticalArrangement = Arrangement.spacedBy(12.dp),
@@ -179,7 +186,7 @@ class T3WorkspaceNavigationView(
179186
onClick = { if (newEnabled) scope.launch { railState.collapse(); onNewThread(emptyMap<String, Any>()) } },
180187
expanded = expandedRail,
181188
icon = { Icon(painterResource(R.drawable.t3_new), contentDescription = null) },
182-
text = { Text("New thread") },
189+
text = { Text("New thread", Modifier.alpha(fabTextAlpha)) },
183190
modifier = Modifier.height(56.dp).alpha(if (newEnabled) 1f else 0.4f).semantics { contentDescription = "New thread"; if (!newEnabled) disabled() },
184191
containerColor = Color(actionColor),
185192
contentColor = Color(actionContentColor),
@@ -192,13 +199,28 @@ class T3WorkspaceNavigationView(
192199
arrangement = Arrangement.Center,
193200
) {
194201
val expandedRail = expandingRail && LocalView.current !== hostView
202+
// Mirrors WideNavigationRailItem's icon-position spring. Its label is invisible at
203+
// the midpoint, so the text and size swap there, and the label stays transparent
204+
// while it slides across the icon.
205+
val labelProgress by animateFloatAsState(
206+
targetValue = if (expandedRail) 1f else 0f,
207+
animationSpec = MaterialTheme.motionScheme.defaultSpatialSpec(),
208+
)
209+
val expandedLabel = labelProgress >= 0.5f
210+
val labelAlpha = if (expandedLabel) ((labelProgress - 0.5f) / 0.35f).coerceIn(0f, 1f) else 1f
195211
tabs.forEach { tab ->
196212
WideNavigationRailItem(
197213
selected = selectedTab == tab,
198214
onClick = { scope.launch { railState.collapse(); onTabSelected(mapOf("tab" to tab)) } },
199215
railExpanded = expandedRail,
200216
icon = { tabIcon(tab) },
201-
label = { Text(if (tab == "pullRequests" && expandedRail) "Pull Requests" else tabTitle(tab), fontSize = ((if (expandedRail) 14 else 12) * textScale).sp) },
217+
label = {
218+
Text(
219+
if (tab == "pullRequests" && expandedLabel) "Pull Requests" else tabTitle(tab),
220+
Modifier.alpha(labelAlpha),
221+
fontSize = ((if (expandedLabel) 14 else 12) * textScale).sp,
222+
)
223+
},
202224
colors = WideNavigationRailItemDefaults.colors(
203225
selectedIconColor = Color(selectedColor),
204226
selectedTextColor = Color(selectedColor),
@@ -256,9 +278,10 @@ class T3WorkspaceNavigationView(
256278
"pullRequests" -> R.drawable.t3_pull_requests
257279
else -> R.drawable.t3_settings
258280
}
281+
// Every destination shows a label, which names it for accessibility.
259282
Icon(
260283
painter = painterResource(drawable),
261-
contentDescription = tabTitle(tab),
284+
contentDescription = null,
262285
)
263286
}
264287
}

0 commit comments

Comments
 (0)