library / dev.chrisbanes.insetter / Insetter

Insetter

open class Insetter

A collection of utility functions to make handling android.view.WindowInsets easier.

Functions

applyInsetsToView

open static fun applyInsetsToView(view: View, insets: WindowInsetsCompat, initialState: ViewState, paddingSystemWindowInsets: EnumSet<InsetDimension>, marginSystemWindowInsets: EnumSet<InsetDimension>, paddingSystemGestureInsets: EnumSet<InsetDimension>, marginSystemGestureInsets: EnumSet<InsetDimension>): Unit

A convenience function which applies insets to a view.

How the given insets are applied depends on the options provided via the various parameters. Each of paddingSystemWindowInsets, marginSystemWindowInsets, paddingSystemGestureInsets and marginSystemGestureInsets take an EnumSet of InsetDimension values.

open static fun applyInsetsToView(view: View, insets: WindowInsetsCompat, initialState: ViewState, paddingSystemWindowLeft: Boolean, paddingSystemWindowTop: Boolean, paddingSystemWindowRight: Boolean, paddingSystemWindowBottom: Boolean, paddingSystemGestureLeft: Boolean, paddingSystemGestureTop: Boolean, paddingSystemGestureRight: Boolean, paddingSystemGestureBottom: Boolean, marginSystemWindowLeft: Boolean, marginSystemWindowTop: Boolean, marginSystemWindowRight: Boolean, marginSystemWindowBottom: Boolean, marginSystemGestureLeft: Boolean, marginSystemGestureTop: Boolean, marginSystemGestureRight: Boolean, marginSystemGestureBottom: Boolean): Unit

requestApplyInsetsWhenAttached

open static fun requestApplyInsetsWhenAttached(view: View): Unit

A wrapper around ViewCompat#requestApplyInsets(View) which ensures the request will happen, regardless of whether the view is attached or not.

setEdgeToEdgeSystemUiFlags

open static fun setEdgeToEdgeSystemUiFlags(view: View, enabled: Boolean): Unit

Set this view's system-ui visibility, with the flags required to be laid out 'edge-to-edge'.

setOnApplyInsetsListener

open static fun setOnApplyInsetsListener(view: View, listener: OnApplyInsetsListener): Unit

A wrapper around ViewCompat#setOnApplyWindowInsetsListener(View, * OnApplyWindowInsetsListener) which stores the initial view state, and provides them whenever a android.view.WindowInsets instance is dispatched to the listener provided.

This allows the listener to be able to append inset values to any existing view state properties, rather than overwriting them.