ViewFactory

class ViewFactory<B : ViewDataBinding>(    inflateFunction: (LayoutInflater, container: ViewGroup?, attachToContainer: Boolean) -> B,     setSafeAreaFunction: B.(SafeArea?) -> Unit?,     bindDataFunction: (B) -> Unit? = null)

A helper class that takes care of common tasks for creating a view in an IviFragment, such as inflation, binding a lifecycle owner and ViewModel and extracting a root view.

If the binding accepts a viewModel property of the same type as VM, viewModel will automatically be assigned to it. If the binding has a different ViewModel setup or has to bind additional data, bindDataFunction can be used to do so.

Parameters

inflateFunction

A function that will inflate a view given a layout inflater, a container view, and whether the view should be attached to the container upon inflation. Matches the signature of a generated data binding class's inflate.

setSafeAreaFunction

A function that is called when the safe area is set, and updates the binding accordingly.

The safe area is updated as part of the layout pass of Android's view displaying process. The layout pass happens right after measuring and right before drawing. Data bindings post updates that happen during the layout pass, to happen after drawing. This prevents displaying content that doesn't fit in the previously measured and laid out view.

The safe area is an exception to this; only during the layout pass we can determine what the safe area is. Therefore, we have to update the contents in that phase to make sure we draw things correctly. By separating the safe area update from the ViewModel, we can independently update it and process that change immediately.

bindDataFunction

A function that will be called after view inflation, and can be used to bind data to the view.

Constructors

Link copied to clipboard
fun <B : ViewDataBinding> ViewFactory(inflateFunction: (LayoutInflater, container: ViewGroup?, attachToContainer: Boolean) -> B, bindDataFunction: (B) -> Unit? = null)
Link copied to clipboard
fun <B : ViewDataBinding> ViewFactory(    inflateFunction: (LayoutInflater, container: ViewGroup?, attachToContainer: Boolean) -> B,     setSafeAreaFunction: B.(SafeArea?) -> Unit?,     bindDataFunction: (B) -> Unit? = null)

Functions

Link copied to clipboard
fun bindData(    lifecycleOwner: LifecycleOwner,     viewModel: FrontendViewModel<*>,     panel: AnyPanel)

Binds a view that was previously inflated with inflate to its data, observed by the given LifecycleOwner.

Link copied to clipboard
fun inflate(inflater: LayoutInflater, container: ViewGroup?): View

Inflates the view using the given inflater and container. The view will not be attached to the container immediately as this has can lead to unexpected issues.