Skip to content

onOpened callback for registerForNavigationResult #200

@isaac-udy

Description

@isaac-udy

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" }
    )
    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions