registerForNavigationResult creates a NavigationResultChannel that allows a NavigationKey to be opened in the context of that NavigationResultChannel. When a NavigationKey's destination is closed or completed after being opened in the context of a NavigationResultChannel, that NavigationResultChannel will call the onClose/onCompleted callbacks provided to registerForNavigationResult.
In addition to these "terminal" callbacks that execute when a NavigationKey's destination closes/completes, it would also be useful to provide an "onOpened" callback, which would allow registerForNavigationResult to register a side effect to occur when a NavigationKey is opened in the context of the NavigationResultChannel. For example, when launching a NavigationKey for a result, the "onOpened" callback could be used to clear existing saved/remembered data related to previous results.
@Composable
fun Example() {
var resultState by remember { mutableStateOf<String?>(null) }
val resultChannel = registerForNavigationResult(
onOpened = { resultState = null },
onClosed = { resultState = "Closed" },
onCompleted = { resultState = "Completed" }
)
// ...
}
registerForNavigationResultcreates aNavigationResultChannelthat allows a NavigationKey to be opened in the context of thatNavigationResultChannel. When a NavigationKey's destination is closed or completed after being opened in the context of a NavigationResultChannel, that NavigationResultChannel will call the onClose/onCompleted callbacks provided toregisterForNavigationResult.In addition to these "terminal" callbacks that execute when a NavigationKey's destination closes/completes, it would also be useful to provide an "onOpened" callback, which would allow
registerForNavigationResultto register a side effect to occur when a NavigationKey is opened in the context of the NavigationResultChannel. For example, when launching a NavigationKey for a result, the "onOpened" callback could be used to clear existing saved/remembered data related to previous results.