Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I save the state in a previous view? #60

Closed
zunjae opened this issue May 20, 2021 · 9 comments
Closed

How do I save the state in a previous view? #60

zunjae opened this issue May 20, 2021 · 9 comments

Comments

@zunjae
Copy link

zunjae commented May 20, 2021

Assuming you have two destinations, A and B. A displays a long list. You click on an item in the list to navigate to B. Once in B you click on the back button. The A view is entirely recreated. The list is at the top again. I am unsure if this is by design or not.

sealed class Routing {
  object A: Routing()
  data class B(val slug: String) : Routing()
}
@Composable
fun AppStore(routing: Routing = Routing.A) {
  Router(routing) { backStack ->
    val onItemClicked: (String) = { slug ->
      backStack.push(Routing.B(slug))
    }
    when (val value = backStack.last()) {
      is Routing.A-> AController(onItemClicked)
      is Routing.B-> BController(value.slug)
    }
  }
}

I've already added a rememberLazyListState but this seems to be recreated entirely as well

I am using version 0.24.2

@zunjae
Copy link
Author

zunjae commented May 20, 2021

I notice that the Pokedex sample app has the same behavior, very interesting.

I don't know a single app in existence with this unusual behavior. Why would you want to recreate a screen and lose all state? I've been developing for android for 6 years now and I've made apps used by over a million people and this is the first time I'm seeing this.

@zunjae
Copy link
Author

zunjae commented May 22, 2021

Fixed by switching to another library

@zunjae zunjae closed this as completed May 22, 2021
@noe
Copy link

noe commented May 22, 2021

Fixed by switching to another library

Which one?

@zunjae
Copy link
Author

zunjae commented May 27, 2021

Fixed by switching to another library

Which one?

Any library will work. Just avoid this one as it's riddled with bugs and the developer seems to be dead

@noe
Copy link

noe commented May 27, 2021

Any library will work. Just avoid this one as it's riddled with bugs and the developer seems to be dead

For me, this library works well and without problems, but I like the functionality you mentioned. If there are other libraries that implement the same behavior, maybe the author or someone else can implement the same approach here. Can you point me to any specific jetpack compose library with that functionality?

@zunjae
Copy link
Author

zunjae commented May 27, 2021

Can you point me to any specific jetpack compose library with that functionality?

It's built into Jetpack Compose called "state". It allows stateless widgets to remember its state. Every time I use this compose-router library it seems to "forget" the state and recreate the entire view from scratch. Once I removed this library, the state is remembered again.

@zunjae
Copy link
Author

zunjae commented May 27, 2021

For me, this library works well and without problems

That seems to be factually incorrect. You can even try out the sample apps made by the same developer. You will see the same issue there where navigating back, the view and its (scroll) state is recreated entirely.

@noe
Copy link

noe commented May 27, 2021

We have different opinions, that's ok. Anyway, can you point me to any specific jetpack compose library with that functionality? I think that the standard compose navigation can do this with scoped view models but I am not sure, and it doesn't support animations, which are supported by compose-router when used in combination with compose-backstack. Therefore, I am genuinely interested in knowing other libraries that do support this.

@zunjae
Copy link
Author

zunjae commented May 27, 2021

Sorry, I am not willing to discuss with someone who sees incorrect facts as "different opinion". Consider yourself blocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants