Skip to content

Commit f205ed8

Browse files
NavController.bindToBrowserNavigation() API (#501)
1 parent dc0f0cd commit f205ed8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

topics/compose/compose-navigation-routing.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ See the [](compose-lifecycle.md) page for details of the current implementation
5757
## Support for browser navigation in web apps
5858
<secondary-label ref="Experimental"/>
5959

60-
Compose Multiplatform for web fully supports the common Navigation library APIs,
61-
and on top of that allows your apps to receive navigational input from the browser.
60+
Compose Multiplatform for web fully supports the common Navigation library APIs
61+
and allows your apps to receive navigational input from the browser.
6262
Users can use the **Back** and **Forward** buttons in the browser to move between navigation routes reflected in the browser history,
6363
as well as use the address bar to understand where they are and get to a destination directly.
6464

6565
To bind the web app to the navigation graph defined in your common code,
66-
you can use the `window.bindToNavigation()` method in your Kotlin/Wasm code.
66+
you can use the `NavController.bindToBrowserNavigation()` method in your Kotlin/Wasm code.
6767
You can use the same method in Kotlin/JS, but wrap it in the `onWasmReady {}` block to ensure
6868
that the Wasm application is initialized and Skia is ready to render graphics.
6969
Here is an example of how to set this up:
@@ -90,7 +90,7 @@ fun main() {
9090
val body = document.body ?: return
9191
ComposeViewport(body) {
9292
App(
93-
onNavHostReady = { window.bindToNavigation(it) }
93+
onNavHostReady = { it.bindToBrowserNavigation() }
9494
)
9595
}
9696
}
@@ -103,14 +103,14 @@ fun main() {
103103
val body = document.body ?: return@onWasmReady
104104
ComposeViewport(body) {
105105
App(
106-
onNavHostReady = { window.bindToNavigation(it) }
106+
onNavHostReady = { it.bindToBrowserNavigation() }
107107
)
108108
}
109109
}
110110
}
111111
```
112112

113-
After a `window.bindToNavigation(navController)` call:
113+
After calling `navController.bindToBrowserNavigation()`:
114114
* The URL displayed in the browser reflects the current route (in the URL fragment, after the `#` character).
115115
* The app parses URLs entered manually to translate them into destinations within the app.
116116

@@ -141,7 +141,7 @@ you can assign the name to a screen directly or develop fully custom processing
141141

142142
To implement a fully custom route to URL transformation:
143143

144-
1. Pass the optional `getBackStackEntryRoute` lambda to the `window.bindToNavigation()` function
144+
1. Pass the optional `getBackStackEntryRoute` lambda to the `navController.bindToBrowserNavigation()` function
145145
to specify how routes should be converted into URL fragments when necessary.
146146
2. If needed, add code that catches URL fragments in the address bar (when someone clicks or pastes your app's URL)
147147
and translates URLs into routes to navigate users accordingly.
@@ -191,7 +191,7 @@ internal fun App(
191191
```
192192
{default-state="collapsed" collapsible="true" collapsed-title="NavHost(navController = navController, startDestination = StartScreen)"}
193193

194-
In `wasmJsMain/kotlin/main.kt`, add the lambda to the `.bindToNavigation()` call:
194+
In `wasmJsMain/kotlin/main.kt`, add the lambda to the `.bindToBrowserNavigation()` call:
195195

196196
```kotlin
197197
@OptIn(
@@ -204,7 +204,7 @@ fun main() {
204204
ComposeViewport(body) {
205205
App(
206206
onNavHostReady = { navController ->
207-
window.bindToNavigation(navController) { entry ->
207+
navController.bindToBrowserNavigation() { entry ->
208208
val route = entry.destination.route.orEmpty()
209209
when {
210210
// Identifies the route using its serial descriptor
@@ -239,7 +239,7 @@ fun main() {
239239
}
240240
}
241241
```
242-
<!--{default-state="collapsed" collapsible="true" collapsed-title="window.bindToNavigation(navController) { entry ->"}-->
242+
<!--{default-state="collapsed" collapsible="true" collapsed-title="navController.bindToBrowserNavigation() { entry ->"}-->
243243

244244
> Make sure that every string that corresponds to a route starts with the `#` character to keep the data
245245
> within URL fragments.
@@ -250,8 +250,8 @@ fun main() {
250250

251251
If your URLs have custom formatting, you should add the reverse processing
252252
to match manually entered URLs to destination routes.
253-
The code that does the matching needs to run before the `window.bindToNavigation()` call binds
254-
`window.location` to the navigation graph:
253+
The code that does the matching needs to run before the `navController.bindToBrowserNavigation()` call binds
254+
the browser location to the navigation graph:
255255

256256
<tabs>
257257
<tab title="Kotlin/Wasm">
@@ -284,7 +284,7 @@ The code that does the matching needs to run before the `window.bindToNavigation
284284
navController.navigate(Patient(name, id))
285285
}
286286
}
287-
window.bindToNavigation(navController) { ... }
287+
navController.bindToBrowserNavigation() { ... }
288288
}
289289
)
290290
}
@@ -322,7 +322,7 @@ The code that does the matching needs to run before the `window.bindToNavigation
322322
navController.navigate(Patient(name, id))
323323
}
324324
}
325-
window.bindToNavigation(navController) { ... }
325+
navController.bindToBrowserNavigation() { ... }
326326
}
327327
)
328328
}

topics/whats-new/whats-new-compose-190.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Here are the highlights for this EAP feature release:
44

55
* [Parameters for the `@Preview` annotation](#parameters-for-the-preview-annotation)
66
* [Customizable shadows](#customizable-shadows)
7-
* [Customizable context menu](#customizable-context-menu)
7+
* [New context menu API](#new-context-menu-api)
88
* [Material 3 Expressive theme](#material-3-expressive-theme)
99
* [Frame rate configuration on iOS](#frame-rate-configuration)
1010
* [Accessibility support on web targets](#accessibility-support)
@@ -85,7 +85,7 @@ You can draw shadows of any shape and color, or even use shadow geometry as a ma
8585

8686
For details, see the [shadow API reference](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/package-summary.html).
8787

88-
### Customizable context menu
88+
### New context menu API
8989

9090
We've adopted Jetpack Compose's new API for custom context menus in `SelectionContainer` and `BasicTextField`.
9191
The implementation is complete for iOS and web, while desktop has initial support.

0 commit comments

Comments
 (0)