ZupIT/beagle

Add support to create context to screen in navigation

Closed this issue · 0 comments

Description

Internal project inside the company needs native support in the Beagle Core so that you can pass parameters from one screen to another without using the GlobalContext. This feature is also useful for the Beagle as a whole, even without internal projects. That's why it's important to implement it in the core, as open-source.

The navigation context is a simple concept: every navigation function accepts a "navigationContext" object which is the value and path to be setted in a special context in the next page. Inside the page, it must be possible to access the navigation parameters through the "navigationContext" context created in the root.

The navigation context of a page must be deallocated whenever the view is destroyed.

Example of a navigation:

route: "product"
navigationContext: { path: "productId", value: "abc" }

Example of a component accessing the value:

Text(text = "productId: @{navigationContext.productId}")

Contract in the backend

sealed class Navigate: AnalyticsAction {

    data class OpenExternalURL(val url: Bind<String>, override var analytics: ActionAnalyticsConfig? = null) : Navigate()
    class OpenNativeRoute( val route: Bind<String>, val shouldResetApplication: Boolean = false, val data: Map<String, String>? = null,override var analytics: ActionAnalyticsConfig? = null,) : Navigate() 

    data class PushStack(val route: Route,
                         val controllerId: String? = null,
                         val navigationContext: NavigationContext? = null,
                         override var analytics: ActionAnalyticsConfig? = null) : Navigate()

    data class PopStack(val navigationContext: NavigationContext? = null,
                        override var analytics: ActionAnalyticsConfig? = null) : Navigate()

    data class PushView(val route: Route,
                        val navigationContext: NavigationContext? = null,
                        override var analytics: ActionAnalyticsConfig? = null) : Navigate()

    data class PopView(val navigationContext: NavigationContext? = null,
                       override var analytics: ActionAnalyticsConfig? = null) : Navigate()

    data class PopToView(
        val route: Bind<String>,
        val navigationContext: NavigationContext? = null,
        override var analytics: ActionAnalyticsConfig? = null,
    ) : Navigate()

    data class ResetApplication(val route: Route,
                                val navigationContext: NavigationContext? = null,
                                val controllerId: String? = null,
                                override var analytics: ActionAnalyticsConfig? = null) : Navigate()

    data class ResetStack(val route: Route,
                          val controllerId: String? = null,
                          val navigationContext: NavigationContext? = null,
                          override var analytics: ActionAnalyticsConfig? = null) : Navigate()

}

data class NavigationContext(
    val value: Any,
    val path: String? = null,
)

What will be changed in the shipping contract:

The context parameter will be added: PushStack, PopStack, PushView, PopView, PopToView, ResetApplication, ResetStack
You don't need to do anything: OpenExternalURL, OpenNativeRoute,

Diagram

Navigation (2)

Answer to some questions:

Can the navigationContext passed by parameter be seen on another screen?
No, you can't.

Can I modify this context within my components?
Yes, you can.