ViewFactory

class ViewFactory<B : ViewDataBinding>(inflateFunction: (LayoutInflater, container: ViewGroup?, attachToContainer: Boolean) -> B, 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, IviFragmentId and ViewModel and extracting a root view.

If the binding accepts a viewModel variable of the same type as VM, viewModel will automatically be assigned to it. If the bindings accepts an iviFragmentId variable of the type IviFragmentId, iviFragmentId will automatically be assigned to it. If the binding has other or additional variables, 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.

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
constructor(inflateFunction: (LayoutInflater, container: ViewGroup?, attachToContainer: Boolean) -> B, bindDataFunction: (B) -> Unit? = null)

Functions

Link copied to clipboard
fun bindData(lifecycleOwner: LifecycleOwner, viewModel: FrontendViewModel<*>, iviFragmentId: IviFragmentId? = null)

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 can lead to unexpected issues.