Skip to content

Commit

Permalink
Created Saver and autoSaver
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Feb 27, 2022
1 parent 80d29ab commit 0237e67
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.saveable.autoSaver

@Composable
@ExperimentalNavigationApi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:Suppress("unused")

package com.chrynan.navigation.compose

actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>

actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.chrynan.navigation.compose

/**
* A component that can convert the type of the [Original] into the type of [Saveable] so that it can be serialized,
* saved, restored. This component is meant to represent the androidx.compose.runtime.saveable.Saver interface, but
* that component is not available for Jetpack Compose Web, so this expected interface is defined in the common source
* set. The Android and JVM targets should simply use a typealias to delegate to the
* androidx.compose.runtime.saveable.Saver interface. The JavaScript target should provide a default implementation.
*/
expect interface Saver<Original, Saveable : Any>

/**
* Retrieves a default implementation of a [Saver] interface which does not perform any conversion. Similar to the
* [Saver] interface, this function is meant to represent the androidx.compose.runtime.saveable.autoSaver function, but
* that function is not available for Jetpack Compose Web, so this expected function is defined in the common source
* set. The Android and JVM targets should simply delegate to the androidx.compose.runtime.saveable.autoSaver function.
* The JavaScript target should provide a default implementation.
*/
expect fun <T> autoSaver(): Saver<T, Any>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:Suppress("unused")

package com.chrynan.navigation.compose

actual interface Saver<Original, Saveable : Any>

actual fun <T> autoSaver(): Saver<T, Any> = object : Saver<T, Any> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@file:Suppress("unused")

package com.chrynan.navigation.compose

actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>

actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()

0 comments on commit 0237e67

Please sign in to comment.