GenericPanel
A panel to visually represent a Frontend. Panels are intended to be presented to the user by the system UI, which does this by attaching the IviFragment returned by createInitialFragment to its layout. The created fragment will internally instantiate a ViewModel (FrontendViewModel) with a reference to this panel.
The system UI may choose to show and stop showing the panel more than once. E.g., a panel may be temporarily removed from the system UI if a similar panel with higher priority is offered to the system UI. Each time, a new fragment, along with its ViewModel, is created and destroyed. As such, it's important to consider whether data should be stored in the panel or the ViewModel. Data that is solely used by the fragment's view typically belongs in in the ViewModel, but note that it will be cleared when the panel is removed and presented again. Data that is important to persist should be kept in the panel instead.
Service connections for presenting data are commonly in the ViewModel rather than the panel to avoid keeping services alive for panels that are not presented. (Note that if the service requested in the ViewModel is already alive, creating another connection to it is a cheap operation.) It can however be beneficial for the panel to ask for a service connection in its constructor, allowing the service connection to be created by the Frontend and thus stay alive after the panel is destroyed. This allows panel contents to be populated immediately upon showing and is important when a service call must be performed upon the destruction of the panel or ViewModel, as those calls may fail when the service is closed as a result of the panel's or ViewModel's destruction. Similarly, if a call is needed when the panel is removed, it is not sufficient to perform it within ViewModel.onCleared because the ViewModel may never have been created during the panel's lifespan.
The panel starts as detached with the lifecycle in Lifecycle.State.CREATED. The lifecycle changes state to Lifecycle.State.STARTED when it is attached to the system UI. The panel can be detached and then attached again.
If the panel is dismissed or removed from the frontend, its lifecycle transitions to Lifecycle.State.DESTROYED after which it may not be added to a frontend again.
A panel instance can only be added to a single Frontend instance. The frontendContext must be the same Frontend.frontendContext instance of the frontend to which this panel will be added.
Parameters
An entry point for this GenericPanel to communicate with the rest of the system.
Constructors
Properties
Unique identifier of a GenericPanel. Each ID is an increment of the previously created panel's ID, allowing this value to be used for sorting purposes.
The PanelContext given when the panel is attached to the system UI.
Functions
The fragment used when initially showing the panel. The fragment may be recreated by the system UI upon configuration changes.
The PanelContext of an IviFragment identified by iviFragmentId.
Called when this panel is added to Frontend.panels, allowing it to be shown in the system UI.
Called when the panel is attached to the system UI.
Called when the panel has been detached from the system UI.
Called when this panel is removed from Frontend.panels, preventing it from being shown in the system UI.