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

Fix instance and save state handler to remember using key #11

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A detailed breakdown available in this [Medium article](https://proandroiddev.co

## Features
- 🚏 A `Router` that manages a FILO stack for your screen configurations
- 📦 `rememberViewModel()` lets you retain your view model across configuration changes and gets cleared when the user leaves the screen
- 📦 `rememberOnRoute()` lets you retain your view model across configuration changes and gets cleared when the user leaves the screen
- ☠️ A `SavedStateHandle` to restore state gracefully after the process death. (for Android)
- 🚉 Multiplatform! Supports Android, WearOS, Desktop, iOS and Web

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ fun <T : Instance> rememberOnRoute(

val packageName: String =
requireNotNull(instanceClass.simpleName) { "Unable to retain anonymous instance of $instanceClass"}
val instanceKey = "$packageName.instance"
val stateKey = "$packageName.savedState"

val keyName = "$packageName.($key)"
val instanceKey = "$keyName.instance"
val stateKey = "$keyName.savedState"

val (instance, savedState) = remember(key) {
val savedState: SavedStateHandle = instanceKeeper
Expand Down