Skip to content

Commit 3eebeed

Browse files
SimonMarquiscopybara-github
authored andcommitted
[GH] Fix regression in dynamic labels with non-string typed arguments
Regression introduced in androidx@0c9bf6b Reported in https://issuetracker.google.com/issues/316676794 Test: ./gradlew navigation:navigation-ui:cC Fixes: 316676794 [AndroidX Navigation 2.6.0 broke dynamic app bar title for non String arguments](https://issuetracker.google.com/issues/316676794) This is an imported pull request from androidx#636. Resolves JetBrains#636 Github-Pr-Head-Sha: f455c6d GitOrigin-RevId: 3ad8f76 Change-Id: I94b4e28bb847632663be32b11e481d13789e8c1b
1 parent 7bb6946 commit 3eebeed

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎navigation/navigation-common/src/main/java/androidx/navigation/NavDestination.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ public open class NavDestination(
635635
val value = context.getString(bundle.getInt(argName))
636636
builder.append(value)
637637
} else {
638-
builder.append(bundle.getString(argName))
638+
@Suppress("DEPRECATION")
639+
builder.append(bundle[argName].toString())
639640
}
640641
} else {
641642
throw IllegalArgumentException(

‎navigation/navigation-ui/src/androidTest/java/androidx/navigation/ui/NavigationUITest.kt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,33 @@ class NavigationUITest {
193193
assertThat(toolbar.title.toString()).isEqualTo(labelString)
194194
}
195195

196+
@UiThreadTest
197+
@Test
198+
fun navigateWithNonStringArg() {
199+
val context = ApplicationProvider.getApplicationContext<Context>()
200+
val navController = NavHostController(context)
201+
navController.navigatorProvider.addNavigator(TestNavigator())
202+
203+
val startDestination = "start_destination"
204+
val endDestination = "end_destination"
205+
206+
navController.graph = navController.createGraph(startDestination = startDestination) {
207+
test(startDestination)
208+
test("$endDestination/{test}") {
209+
label = "{test}"
210+
argument(name = "test") {
211+
type = NavType.LongType
212+
}
213+
}
214+
}
215+
216+
val toolbar = Toolbar(context).apply { setupWithNavController(navController) }
217+
navController.navigate("$endDestination/123")
218+
219+
val expected = "123"
220+
assertThat(toolbar.title.toString()).isEqualTo(expected)
221+
}
222+
196223
private fun createToolbarOnDestinationChangedListener(
197224
toolbar: Toolbar,
198225
bundle: Bundle?,

0 commit comments

Comments
 (0)