-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for SavedStateHandle
- Loading branch information
1 parent
6e107e7
commit 622c585
Showing
9 changed files
with
52 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
voyager-androidx/src/main/java/cafe/adriel/voyager/androidx/ScreenLifecycleOwner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cafe.adriel.voyager.androidx | ||
|
||
import androidx.compose.ui.platform.LocalSavedStateRegistryOwner | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.LifecycleRegistry | ||
import androidx.lifecycle.ViewModelStore | ||
import androidx.lifecycle.ViewModelStoreOwner | ||
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner | ||
import androidx.savedstate.SavedStateRegistry | ||
import androidx.savedstate.SavedStateRegistryController | ||
import androidx.savedstate.SavedStateRegistryOwner | ||
import cafe.adriel.voyager.core.hook.ScreenHook | ||
|
||
public val ScreenLifecycleOwner.screenLifecycleHooks: List<ScreenHook> | ||
get() = listOf( | ||
ScreenHook.OnProvide { LocalViewModelStoreOwner provides this }, | ||
ScreenHook.OnProvide { LocalSavedStateRegistryOwner provides this }, | ||
ScreenHook.OnDispose { viewModelStore.clear() } | ||
) | ||
|
||
public interface ScreenLifecycleOwner : LifecycleOwner, ViewModelStoreOwner, SavedStateRegistryOwner | ||
|
||
public class ScreenLifecycleHolder : ScreenLifecycleOwner { | ||
|
||
private val store = ViewModelStore() | ||
|
||
private val registry = LifecycleRegistry(this) | ||
|
||
private val controller = SavedStateRegistryController.create(this) | ||
|
||
init { | ||
controller.performRestore(null) | ||
} | ||
|
||
override fun getViewModelStore(): ViewModelStore = store | ||
|
||
override fun getLifecycle(): Lifecycle = registry | ||
|
||
override fun getSavedStateRegistry(): SavedStateRegistry = controller.savedStateRegistry | ||
} |
19 changes: 0 additions & 19 deletions
19
voyager-androidx/src/main/java/cafe/adriel/voyager/androidx/ViewModelStoreOwner.kt
This file was deleted.
Oops, something went wrong.