NavigationContext

Describes the NavigationContext functions

What is it?

It is a structure present in most navigation actions. It defines a special context, called "navigationContext", which is created on the target screen only.

See its structure below:

AttributeTypeRequiredDefinition
valueAnyValue to be set at the NavigationContext
pathStringPath on the NavigationContext structure

How to use it?

The Navigation Context is better used when you want to send information from one screen into another. Next, we have a screen with a button, that when clicked, loads a new view (which represents another screen). The information contained in the “navigationContext” value attribute will be saved in the scope of this new screen. This information can be accessed through the expression "@{navigationContext.text}" in the new screen only.

See the example below:

Screen(
    child = Button(
        text = "Click me!",
        onPress = listOf(
            Navigate.PushView(
                route = Route.Local(
                    Screen(
                        child = Text(expressionOf("@{navigationContext.text}"))
                    )
                ),
                navigationContext = NavigationContext(
                    value = "textFromNavigation",
                    path = "text"
                )
            )
        )
    )
)