Custom Fragments

Knowledge of the system UI will help you to understand this guide. If you are not yet familiar with it, feel free to take a look at the system UI overview.

Customizing fragments allows you to change the look and feel of an existing GenericPanel. This can be done in 3 steps listed below. The full example can be found here.

Define a custom fragment

To define a custom fragment, you have to create an subclass of IviFragment, and a view binding for it. You can find the exact syntax for it in the example.

If the existing ViewModel is usable for the custom fragment, and you can reuse it if it's a public API. Otherwise, you can create your own ViewModel. The example referenced above uses the existing ViewModel.

Define a custom fragment rule

A custom fragment rule is a way to communicate to the system UI, that you want to create a certain IviFragment for a certain GenericPanel. The first rule that accepts the create of the fragment for a given panel creates the fragment. If no rule accepts, the panel creates the fragment.

To create a custom fragment rule, you have to extend the CustomFragmentRule, as you can see in the example.

Use a custom fragment rule in a system UI host

To make the system UI aware of the rule, fragmentFactory has to be overridden in your SystemUiHost, and the rule has to be added to it.

1override val fragmentFactory: IviFragmentFactory =
2 IviFragmentFactory.create {
3 addRule(CustomFragmentRule())
4 }

You can find an example of a custom SystemUiHost implementation with such an override here.