Skip to content

Commit 722fca9

Browse files
authored
Remove deprecated bindToNavigation API from k/js and k/wasm implementations (#2675)
Fixes [CMP-8434](https://youtrack.jetbrains.com/issue/CMP-8434) ## Testing N/A ## Release Notes ### Migration Notes - Navigation - A deprecated `suspend fun Window.bindToNavigation` method has been removed
1 parent eb6e5f7 commit 722fca9

File tree

5 files changed

+10
-84
lines changed

5 files changed

+10
-84
lines changed

navigation/navigation-runtime/api/navigation-runtime.klib.api

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,3 @@ open annotation class androidx.navigation/ExperimentalBrowserHistoryApi : kotlin
111111

112112
// Targets: [js, wasmJs]
113113
final suspend fun (androidx.navigation/NavController).androidx.navigation/bindToBrowserNavigation(kotlin/Function1<androidx.navigation/NavBackStackEntry, kotlin/String>? = ...) // androidx.navigation/bindToBrowserNavigation|[email protected](kotlin.Function1<androidx.navigation.NavBackStackEntry,kotlin.String>?){}[0]
114-
115-
// Targets: [js, wasmJs]
116-
final suspend fun (org.w3c.dom/Window).androidx.navigation/bindToNavigation(androidx.navigation/NavController, kotlin/Function1<androidx.navigation/NavBackStackEntry, kotlin/String>? = ...) // androidx.navigation/bindToNavigation|[email protected](androidx.navigation.NavController;kotlin.Function1<androidx.navigation.NavBackStackEntry,kotlin.String>?){}[0]

navigation/navigation-runtime/build.gradle

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ androidXMultiplatform {
128128
nativeMain.dependsOn(nonJvmMain)
129129
nativeTest.dependsOn(nonJvmTest)
130130

131+
webMain.dependencies {
132+
implementation(libs.kotlinXw3c)
133+
}
131134
webMain.dependsOn(nonJvmMain)
132135
webTest.dependsOn(nonJvmTest)
133136

@@ -140,12 +143,8 @@ androidXMultiplatform {
140143
target.compilations["test"].defaultSourceSet.dependsOn(webTest)
141144
}
142145
}
143-
144-
wasmJsMain.dependencies {
145-
implementation(libs.kotlinXw3c)
146-
}
147-
148-
wasmJsTest.kotlin.srcDirs("src/jsTest/kotlin")
146+
jsTest.dependsOn(webTest)
147+
wasmJsTest.dependsOn(webTest)
149148
}
150149
}
151150

navigation/navigation-runtime/src/jsMain/kotlin/androidx/navigation/BrowserHistory.js.kt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,4 @@
1616

1717
package androidx.navigation
1818

19-
import org.w3c.dom.Window
20-
21-
/**
22-
* Binds the browser window state to the given navigation controller.
23-
*
24-
* If `getBackStackEntryRoute` is null, then:
25-
* 1) if a browser url contains a destination route on a start then navigates to destination
26-
* 2) if a user puts a new destination route to the browser address field then navigates to the new destination
27-
*
28-
* If there is a custom `getBackStackEntryRoute` implementation,
29-
* then we don't have a knowledge how to parse urls to support direct navigation via browser address input.
30-
* In that case, it should be done on the app's side:
31-
* ```
32-
* window.addEventListener("popstate") { event ->
33-
* event as PopStateEvent
34-
* if (event.state == null) { // empty state means manually entered address
35-
* val url = window.location.toString()
36-
* navController.navigate(...)
37-
* }
38-
* }
39-
* ```
40-
*
41-
* @param navController The [NavController] instance to bind to browser window navigation.
42-
* @param getBackStackEntryRoute An optional function that returns the route to show for a given [NavBackStackEntry].
43-
*/
44-
@Suppress("UnusedReceiverParameter")
45-
@Deprecated(message = "Use bindToBrowserNavigation", replaceWith = ReplaceWith("navController.bindToBrowserNavigation(getBackStackEntryRoute)"))
46-
@ExperimentalBrowserHistoryApi
47-
public suspend fun Window.bindToNavigation(
48-
navController: NavController,
49-
getBackStackEntryRoute: ((entry: NavBackStackEntry) -> String)? = null
50-
) {
51-
navController.bindToBrowserNavigation(getBackStackEntryRoute)
52-
}
53-
5419
internal actual fun refBrowserWindow(): BrowserWindow = js("window")

navigation/navigation-runtime/src/wasmJsMain/kotlin/androidx/navigation/BrowserHistory.wasmJs.kt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,4 @@
1616

1717
package androidx.navigation
1818

19-
import org.w3c.dom.Window
20-
21-
/**
22-
* Binds the browser window state to the given navigation controller.
23-
*
24-
* If `getBackStackEntryRoute` is null, then:
25-
* 1) if a browser url contains a destination route on a start then navigates to destination
26-
* 2) if a user puts a new destination route to the browser address field then navigates to the new destination
27-
*
28-
* If there is a custom `getBackStackEntryRoute` implementation,
29-
* then we don't have a knowledge how to parse urls to support direct navigation via browser address input.
30-
* In that case, it should be done on the app's side:
31-
* ```
32-
* window.addEventListener("popstate") { event ->
33-
* event as PopStateEvent
34-
* if (event.state == null) { // empty state means manually entered address
35-
* val url = window.location.toString()
36-
* navController.navigate(...)
37-
* }
38-
* }
39-
* ```
40-
*
41-
* @param navController The [NavController] instance to bind to browser window navigation.
42-
* @param getBackStackEntryRoute An optional function that returns the route to show for a given [NavBackStackEntry].
43-
*/
44-
@ExperimentalBrowserHistoryApi
45-
@Suppress("UnusedReceiverParameter")
46-
@Deprecated(message = "Use bindToBrowserNavigation", replaceWith = ReplaceWith("navController.bindToBrowserNavigation(getBackStackEntryRoute)"))
47-
public suspend fun Window.bindToNavigation(
48-
navController: NavController,
49-
getBackStackEntryRoute: ((entry: NavBackStackEntry) -> String)? = null
50-
) {
51-
navController.bindToBrowserNavigation(getBackStackEntryRoute)
52-
}
53-
5419
internal actual fun refBrowserWindow(): BrowserWindow = js("window")

navigation/navigation-runtime/src/jsTest/kotlin/androidx/navigation/BrowserHistoryTest.kt renamed to navigation/navigation-runtime/src/webTest/kotlin/androidx/navigation/BrowserHistoryTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BrowserHistoryTest {
6161
}
6262
val appAddress = with(window.location) { origin + pathname }
6363

64-
val bind = launch { window.bindToNavigation(navController) }
64+
val bind = launch { navController.bindToBrowserNavigation() }
6565
navController.setGraph(navController.createGraph(), null)
6666
advanceUntilIdle()
6767

@@ -112,7 +112,7 @@ class BrowserHistoryTest {
112112
navController.setGraph(navController.createGraph(), null)
113113

114114
val appAddress = with(window.location) { origin + pathname }
115-
val bind = launch { window.bindToNavigation(navController) }
115+
val bind = launch { navController.bindToBrowserNavigation() }
116116
advanceUntilIdle()
117117

118118
assertThat(window.history.length).isEqualTo(initHistoryLength)
@@ -211,7 +211,7 @@ class BrowserHistoryTest {
211211
navController.setGraph(navController.createGraph(), null)
212212

213213
val appAddress = with(window.location) { origin + pathname }
214-
val bind = launch { window.bindToNavigation(navController) { "" } }
214+
val bind = launch { navController.bindToBrowserNavigation() { "" } }
215215
advanceUntilIdle()
216216

217217
assertThat(window.history.length).isEqualTo(initHistoryLength)
@@ -286,7 +286,7 @@ class BrowserHistoryTest {
286286
val initAddress = "$appAddress#screen_4"
287287
window.history.replaceState(null, "", initAddress)
288288

289-
val bind = launch { window.bindToNavigation(navController) }
289+
val bind = launch { navController.bindToBrowserNavigation() }
290290
advanceUntilIdle()
291291

292292
assertThat(window.history.length).isEqualTo(initHistoryLength)
@@ -321,7 +321,7 @@ class BrowserHistoryTest {
321321
navController.setGraph(navController.createGraph(), null)
322322

323323
val appAddress = with(window.location) { origin + pathname }
324-
val bind = launch { window.bindToNavigation(navController) }
324+
val bind = launch { navController.bindToBrowserNavigation() }
325325
advanceUntilIdle()
326326

327327
assertThat(window.history.length).isEqualTo(initHistoryLength)

0 commit comments

Comments
 (0)