Decompose-Router
Decompose-Router copied to clipboard
How can we implement it to transfer data to the previous screen
can you give examples?
I can share my solution: https://gist.github.com/Skeptick/7c354c80b9941576e85c3c3367c57f76
Usage
Screen declaration in graph
@Serializable
data object SomeScreen : Route, Returnable<SomeResult>
Push for result
val resultManager = LocalResultManager.current
val someScreenKey = resultManager.rememberResultKey<_, SomeScreen> { result ->
// handle result
}
router.pushForResult(
key = someScreenKey,
configuration = SomeScreen
)
Return result
val resultManager = LocalResultManager.current
router.popWithResult(
resultManager = resultManager,
result = SomeResult()
)
Automatically set result when the screen is closed (if result was not set explicitly via popWithResult)
router.setResultOnPop {
SomeResult()
}
[!NOTE]
Note that in my solution result is not serialized and will be lost when the Android process dies. If you want it to survive process death, you need to make changes toResultManagerand theRouteAwareKeypersistence mechanism.