BeagleScreenViewController
is a class that controls how views will be presented at the application. It works exactly as a UIViewController
.
Create an object with a BeagleScreenViewController type listing a screenType on its initialization, there are three ways this can be done:
1. Remote: Receives an URL with a server-driven component. If there was an error when loading your server-driven screen, an optional fallback view can be configured, which would be a screen build on the frontend.
You can also configure a header through additionalData
parameter.
2. Declarative: Receives a declarative screen (created on your frontend side on Swift).
3. DeclarativeText: Receives a screen in a JSON format.
class BeagleScreenViewController {
public convenience init(
_ screenType: ScreenType,
controllerId: String? = nil
) {
self.init(
viewModel: .init(screenType: screenType), controllerId: controllerId
)
self.navigationControllerId = controllerId
}
}
public enum ScreenType {
case remote(Remote)
case declarative(Screen)
case declarativeText(String)
}
// Declarative
let viewController = BeagleScreenViewController(
.declarative(Home.screen())
)
// Remote with relative URL
let viewController = BeagleScreenViewController(
.remote( .init(
url: "/home",
fallback: nil))
)
// Remote with a absolute URL
let viewController = BeagleScreenViewController(
.remote(.init(
url: "http://localhost:8080/home",
fallback: Home().screen))
)
// DeclarativeText
let viewController = BeagleScreenViewController(
.declarativeText(
"""
{
"_beagleComponent_": "beagle:text",
"text": "Hello World!"
}
"""
)
)
The first example instantiate a BeagleScreenViewController
with a declarative screenType that will receive a declarative screen.
The second example instantiate a BeagleScreenViewController
with a remote screenType using a relative URL. You must have implemented a base URL to use a relative path.
The third example instantiate a BeagleScreenViewController
also with a remote screenType using an absolute URL and listing a fallback view.
The last example instantiate a BeagleScreenViewController
with a declarativeText screenType that receives a screen on a JSON format.
The BeagleNavigationController
is a UINavigationController class
focused on observing server-driven screen states to know when it starts or ends.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.