Skip to content

Instantly share code, notes, and snippets.

@GMetaxakis
Created May 20, 2022 05:52
Show Gist options
  • Save GMetaxakis/87cd23e372eb91f6cd2c94c93a05c829 to your computer and use it in GitHub Desktop.
Save GMetaxakis/87cd23e372eb91f6cd2c94c93a05c829 to your computer and use it in GitHub Desktop.
JsonNavType for passing json as navtype in JeptackNavigation Compose
abstract class JsonNavType<T> : NavType<T>(isNullableAllowed = false) {
abstract fun fromJsonParse(value: String): T
abstract fun T.getJsonParse(): String
override fun get(bundle: Bundle, key: String): T? =
bundle.getString(key)?.let { parseValue(it) }
override fun parseValue(value: String): T = fromJsonParse(value)
override fun put(bundle: Bundle, key: String, value: T) {
bundle.putString(key, value.getJsonParse())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment