How to display a screen

In this section, you will find how to display a server-driven screen.

Display a screen through a URL

Each platform has its own way to display a server-driven screen on frontend by using Beagle. You can see how it’s done in iOS below:

To render a server-driven screen, just create an instance BeagleScreenViewController and the type is remote, then you make the initialization with your BFF’s URL, like the example below:

let beagleViewController = Beagle.screen(
    .remote(
        .init(url: "// URL AQUI")
    )
)

After that, now present it where you want. In this case, you must follow the command:

present(beagleViewController, animated: true, completion: nil)

The answer of your BFF must be a JSON that represent a visual component locally defined in the application.

Now, run the application and see a defined screen in a remoted rendered URL in your local application.

Display a screen through a JSON

To render a screen of a JSON, you just have to create a BeagleScreenViewController instance of the declarativeText type and initialize with the JSON, see the example below:

let beagleViewController = Beagle.screen(
    .declarativeText(
        .init(text: "// JSON HERE")
    )
)

After that, now just present it where you want to. On this case, you have to follow the command in the example below:

present(beagleViewController, animated: true, completion: nil)