Root Layout

It is not required to have a RootLayout to use Android UI but it is the recommended way of using this library.

AUI comes with some default pages for getting started. The default starter page StarterPage() and the fallback page Error() exists in the library but can be changed for custom pages.

Creating a simple RootLayout

Android UI comes with the function of using one Activity to run the whole application from.
Similar to React, a layout can be created and applied over many pages in an android application.
To create an application layout, start with creating a class and extend it with the RootLayout class.

class App : RootLayout(metadata = Meta()) {}

The RootLayout takes meta data as a parameter for determining fullscreen and edgeToEdge.
It can also be used to set a routing map and default error page.

val metadata = Meta(
	fullscreen = false,
	edgeToEdge = true,

	routing = HashMap<String, @Composable () -> Unit>().apply {
		put('/') { StarterPage() }
	},

	start = { StarterPage() },
	fallback = { Error() }
)

The fallback and start is to tell the router what page to load if a page could not be loaded and what page to load first when the application starts.

Creating an application Layout

The RootLayout has two abstract methods to help create the application.
The onSetup() is called before the layout is created, and can be used to set some application settings. And the Layout() method is where he application layout is placed.
By default a RouterProvider is created for the layout.

class MyApplication : RootLayout() {

	override fun onSetup() {}

	@Composable
	override fun Layout(children: @Composable () -> Unit) {
	}
}

When using RootLayout an instance for LocalStorage is automatically created. Normally with android it is required to have a context but thanks to RootLayout the LocalStorage is initialized with a context and therefore does not need one later on.

LocalStorage.put("<name>", "<data>") // Store data
LocalStorage.get("<name>") // Returns Data or null

LocalStorage can be accessed from anywhere and does not need its calling parent to be Composable to work.