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

Preserve scroll position on Android Activity restoration #1494

Closed
wants to merge 1 commit into from

Conversation

veyndan
Copy link
Contributor

@veyndan veyndan commented Sep 19, 2023

This doesn't work yet, as rememberSaveable needs to support saving of values that aren't MutableState's. Currently, when trying to save the state, we get the following error:

app.cash.zipline.ZiplineException: IllegalStateException: unexpected type: {-exvejj=[MutableState(value=medal)@632700585], udeaau=[0]}
                 	at captureStack (runtime/coreRuntime.kt:12)
                 	at IllegalStateException_init_$Create$_0 (kotlin-kotlin-stdlib-js-ir.js)
                 	at toStateSnapshot (commonMainSources/libraries/stdlib/src/kotlin/collections/Maps.kt:84)
                 	at <anonymous> (redwood-treehouse-guest/src/commonMain/kotlin/app/cash/redwood/treehouse/treehouseCompose.kt:114)
                 	at <anonymous> (redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/ZiplineTreehouseUi.kt)
                 	…

One trade-off here is that we're just saving the first visible item index, and thus we only restore the first visible item index when we come back. What this means is that if we scroll past 4 items, and the top of the LazyList has scrolled half of the fifth item, when we restore the scroll position, we will show the whole of the fifth item instead of half of it. I think this is perfectly okay for now, as the gains we get from restoring the scroll index is ginormous.

@jingwei99
Copy link

this PR right now is pending on StateSnapshot being able to save types (values) that's not MutableState. last time @veyndan and I talked on this (it was a month or so ago? maybe more), Veyndan brought an idea about handling serialization for types in StateSnapshot (it's just I forgot the details of the idea 🤦🏻‍♀️), I'm talking with Veyndan to get that part done, and then we can land this PR to make the scroll position work!

@veyndan
Copy link
Contributor Author

veyndan commented Sep 19, 2023

The idea we were discussing is summarised in #1384. We can either go that route of making arbitrary content serializable, or we can just add serialization support for non-MutableState values, and implement that issue another day!

@veyndan veyndan force-pushed the veyndan/2023-09-19/rememberSaveable-LazyList branch from 7179f2e to c197418 Compare September 27, 2023 08:17
@jingwei99
Copy link

I tested this change locally, with the change for view id, now scroll position is saved!! ✨

@veyndan veyndan force-pushed the veyndan/2023-09-19/rememberSaveable-LazyList branch from d6a566f to a987712 Compare October 4, 2023 10:39
@veyndan
Copy link
Contributor Author

veyndan commented Oct 4, 2023

@jingwei99 Did you test this with the Activity screen, or one of the sample apps? I'm just asking because I tried testing it on Emoji Search and it isn't working

@jingwei99
Copy link

@jingwei99 Did you test this with the Activity screen, or one of the sample apps? I'm just asking because I tried testing it on Emoji Search and it isn't working

I was testing it on the sample app, and it worked.

🤔 maybe I didn't have the Don't keep activities setting on? (I think that's what it is, my emulator has been weird, and I've been wiping its data often)

@veyndan
Copy link
Contributor Author

veyndan commented Nov 13, 2023

Superseded by #1599

@veyndan veyndan closed this Nov 13, 2023
@veyndan veyndan deleted the veyndan/2023-09-19/rememberSaveable-LazyList branch November 13, 2023 15:41
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

Successfully merging this pull request may close these issues.

3 participants