ViewFactory

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


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

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.