-
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.
Merge pull request #102 from kiwicom/savedstatehandle
Add SavedStateHandle.decodeArguments() extension
- Loading branch information
Showing
8 changed files
with
122 additions
and
20 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
15 changes: 15 additions & 0 deletions
15
core/src/main/kotlin/com/kiwi/navigationcompose/typed/internal/NavBuilder.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,15 @@ | ||
package com.kiwi.navigationcompose.typed.internal | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.kiwi.navigationcompose.typed.Destination | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
|
||
@ExperimentalSerializationApi | ||
@PublishedApi | ||
internal fun <T : Destination> SavedStateHandle.decodeArguments( | ||
serializer: KSerializer<T>, | ||
): T { | ||
val decoder = UriDataDecoder(SavedStateDataMap(this)) | ||
return decoder.decodeSerializableValue(serializer) | ||
} |
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
23 changes: 23 additions & 0 deletions
23
core/src/main/kotlin/com/kiwi/navigationcompose/typed/internal/UriDataMap.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,23 @@ | ||
package com.kiwi.navigationcompose.typed.internal | ||
|
||
import android.os.Bundle | ||
import androidx.lifecycle.SavedStateHandle | ||
|
||
internal interface UriDataMap { | ||
fun contains(key: String): Boolean | ||
fun get(key: String): String? | ||
} | ||
|
||
internal class BundleDataMap( | ||
private val bundle: Bundle, | ||
) : UriDataMap { | ||
override fun contains(key: String): Boolean = bundle.containsKey(key) | ||
override fun get(key: String): String? = bundle.getString(key) | ||
} | ||
|
||
internal class SavedStateDataMap( | ||
private val savedStateHandle: SavedStateHandle, | ||
) : UriDataMap { | ||
override fun contains(key: String): Boolean = savedStateHandle.contains(key) | ||
override fun get(key: String): String? = savedStateHandle[key] | ||
} |
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