Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 348 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to handle navigation in Jetpack Compose?

#1
In Jetpack Compose, how is navigation supposed to be done? All (and there aren’t many) examples (including the official sample from Google) use sealed classes and loading new screens in reaction to observing the change in the current screen. This does (sort of) work, but provides no navigation backstack, and the phone’s back button is totally unaware, just closes the app instead of going back to the previous screen. Is this supposed to somehow converge with the navigation component from AndroidX - but it’s XML based, and Compose is all about moving away from XML? Or is there a brand new navigation concept coming, perhaps similar to SwiftUI (navigationlink, etc)? This seems to be one of the biggest roadblocks - as without navigation you can only have a toy app. Anyone aware of the roadmap here?
Reply

#2
Here is an unofficial approach of navigation in Jetpack Compose. Try it out until you get an official word from the Google android devs.

**compose-router**

[To see links please register here]

Reply

#3
I have writed how to handle Navigation with Jetpack Compose

Link :

[To see links please register here]

Reply

#4
New Jetpack lib has published for Compose navigation. It is still in alpha.

In this new library, now user can able to navigation between different composables with navigation components features.

Using **navigation-compose**:

```
dependencies {
def nav_compose_version = "1.0.0-alpha01"
implementation "androidx.navigation:navigation-compose:$nav_compose_version"
}

```

**Example:**

**Step 1:** create a `NavController` by using the `rememberNavController()` method in your composable: [Link](

[To see links please register here]

):

```
val navController = rememberNavController()
```

**Step 2:** Creating the `NavHost` requires the `NavController` previously created via `rememberNavController()` and the route of the starting destination of your graph:[Link](

[To see links please register here]

).

```
NavHost(navController, startDestination = "profile") {
composable("profile") { Profile(...) }
composable("friendslist") { FriendsList(...) }
...
}
```
**Step 3:** To navigate to a composable use `navigate()`:

```
fun Profile(navController: NavController) {
...
Button(onClick = { navController.navigate("friends") }) {
Text(text = "Navigate next")
}
...
}
```

check more

[To see links please register here]

Reply

#5
Use `androidx.navigation:navigation-compose`. See @pRaNaY's answer.

#### Original Answer

It seems that they are moving away from XML.

The new official samples released after the release of 1.0.0-alpha, have a shared code to manage backstack and navigation. This code is not part of the library yet.

[To see links please register here]

[To see links please register here]


#### Update

Because sample projects are migrated to `androidx.navigation:navigation-compose`, links are dead.
I tried to find the most up to date commits which links are not dead.

[To see links please register here]


[To see links please register here]

Reply

#6
Here is another good alternative library for Compose Navigation:

[To see links please register here]


I've created it because some parts of the official Navigation Component are too much weird.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through