-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from parcelable and parcelize to kotlinx serializable
- Loading branch information
Showing
19 changed files
with
59 additions
and
61 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
13 changes: 6 additions & 7 deletions
13
app/src/commonMain/kotlin/io/github/xxfast/decompose/router/app/screens/HomeStateModels.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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
package io.github.xxfast.decompose.router.app.screens | ||
|
||
import com.arkivanov.essenty.parcelable.Parcelable | ||
import com.arkivanov.essenty.parcelable.Parcelize | ||
import kotlinx.serialization.Serializable | ||
|
||
@Parcelize | ||
sealed class HomeScreens: Parcelable { | ||
data object List: HomeScreens() | ||
data object Nested: HomeScreens() | ||
data class Details(val number: Int): HomeScreens() | ||
@Serializable | ||
sealed class HomeScreens { | ||
@Serializable data object List: HomeScreens() | ||
@Serializable data object Nested: HomeScreens() | ||
@Serializable data class Details(val number: Int): HomeScreens() | ||
} | ||
|
7 changes: 3 additions & 4 deletions
7
...monMain/kotlin/io/github/xxfast/decompose/router/app/screens/details/DetailStateModels.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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package io.github.xxfast.decompose.router.app.screens.details | ||
|
||
import com.arkivanov.essenty.parcelable.Parcelable | ||
import com.arkivanov.essenty.parcelable.Parcelize | ||
import kotlinx.serialization.Serializable | ||
|
||
@Parcelize | ||
data class DetailState(val count: Int): Parcelable | ||
@Serializable | ||
data class DetailState(val count: Int) |
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
6 changes: 2 additions & 4 deletions
6
...c/commonMain/kotlin/io/github/xxfast/decompose/router/app/screens/list/ListStateModels.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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package io.github.xxfast.decompose.router.app.screens.list | ||
|
||
import com.arkivanov.essenty.parcelable.Parcelable | ||
import com.arkivanov.essenty.parcelable.Parcelize | ||
import kotlinx.serialization.Serializable | ||
|
||
@Parcelize | ||
data class ListState(val items: List<Int>? = Loading): Parcelable | ||
@Serializable data class ListState(val items: List<Int>? = Loading) | ||
|
||
val Loading: Nothing? = null |
7 changes: 3 additions & 4 deletions
7
...monMain/kotlin/io/github/xxfast/decompose/router/app/screens/nested/NestedScreenModels.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
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
22 changes: 6 additions & 16 deletions
22
decompose-router/src/commonMain/kotlin/io/github/xxfast/decompose/router/SavedState.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 |
---|---|---|
@@ -1,25 +1,15 @@ | ||
package io.github.xxfast.decompose.router | ||
|
||
import com.arkivanov.essenty.instancekeeper.InstanceKeeper | ||
import com.arkivanov.essenty.parcelable.Parcelable | ||
import com.arkivanov.essenty.parcelable.Parcelize | ||
|
||
/*** | ||
* A wrapper to retain [Parcelable] across process death | ||
* | ||
* @param value parcelable to retain | ||
*/ | ||
@Parcelize | ||
data class SavedState(val value: Parcelable): Parcelable | ||
import kotlinx.serialization.Serializable | ||
|
||
/*** | ||
* Handle to help the view models manage saved state | ||
*/ | ||
@Suppress("UNCHECKED_CAST") // I know what i'm doing | ||
class SavedStateHandle(default: SavedState?): InstanceKeeper.Instance { | ||
private var savedState: SavedState? = default | ||
val value: Parcelable? get() = savedState | ||
fun <T: Parcelable> get(): T? = savedState?.value as? T? | ||
fun set(value: Parcelable) { this.savedState = SavedState(value) } | ||
class SavedStateHandle(default: @Serializable Any?): InstanceKeeper.Instance { | ||
private var savedState: @Serializable Any? = default | ||
val value: @Serializable Any? get() = savedState | ||
fun <T: @Serializable Any> get(): T? = savedState as? T | ||
fun set(value: @Serializable Any) { this.savedState = value } | ||
override fun onDestroy() { savedState = null } | ||
} |
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