Back navigation with arguments #124
Replies: 5 comments 1 reply
-
Hello, can you find any solution for this case? |
Beta Was this translation helpful? Give feedback.
-
Feel free to watch this issue #39 |
Beta Was this translation helpful? Give feedback.
-
I suggest using how fragment in android is instantiate. Which is i already tested and works on private project. @Serializable
data class DataAToB(
val name: String,
val surename: String,
)
val DataAToBSaver = Saver<DataAToB?, String>(
save = {
if (it != null) {
Json.encodeToString(serializer(), it)
} else {
""
}
},
restore = {
if (it.isNotEmpty()) {
Json.decodeFromString(it)
} else {
null
}
}
)
class ScreenB : Screen {
companion object {
fun newInstance(data: DataAToB): ScreenB {
val screen = ScreenB()
screen._data = data
return screen
}
}
override val key: ScreenKey
get() = uniqueScreenKey
private var _data: DataAToB = null
@Composable
override fun Content() {
var savableDataAToB by rememberSaveable(stateSaver = DataAToBSaver) {
mutableStateOf(null)
}
//this is for handling when application in background
if (_data != null) {
savableDataAToB = _data
//do something
} else if (savableDataAToB != null) {
//do something
}
// so you do something to pass result from B to A
val navigator = LocalNavigator.currentOrThrow
navigator.pop()
navigator.replace(ScreenA(Result))
}
}
class ScreenA() : Screen {
companion object {
fun newInstance(data: ResultB): ScreenA {
val screen = ScreenA()
screen._data = data
return screen
}
}
override val key: ScreenKey
get() = uniqueScreenKey
private var _data: ResultB = null
@Composable
override fun Content() {
// the rest of code ...
}
}
|
Beta Was this translation helpful? Give feedback.
-
@Syer10 hope this help you all, @Smoothie1-ini @0xZhangKe @Syer10 |
Beta Was this translation helpful? Give feedback.
-
If you are looking for a Looking forward to any contribution to a more type safe result extension. |
Beta Was this translation helpful? Give feedback.
-
Is it possible with Voyager to navigate back with arguments like navigating forward?
Beta Was this translation helpful? Give feedback.
All reactions