-
- All Implemented Interfaces:
-
androidx.core.view.OnApplyWindowInsetsListener
public final class RootViewDeferringInsetsCallback extends WindowInsetsAnimationCompat.Callback implements OnApplyWindowInsetsListener
A class which extends/implements both WindowInsetsAnimationCompat.Callback and View.OnApplyWindowInsetsListener, which should be set on the root view in your layout.
This class enables the root view is selectively defer handling any insets which match deferredInsetTypes, to enable better looking WindowInsetsAnimationCompats.
An example is the following: when a WindowInsetsAnimationCompat is started, the system will dispatch a WindowInsetsCompat instance which contains the end state of the animation. For the scenario of the IME being animated in, that means that the insets contains the IME height. If the view's View.OnApplyWindowInsetsListener simply always applied the combination of WindowInsetsCompat.Type.ime and WindowInsetsCompat.Type.systemBars using padding, the viewport of any child views would then be smaller. This results in us animating a smaller (padded-in) view into a larger viewport. Visually, this results in the views looking clipped.
This class allows us to implement a different strategy for the above scenario, by selectively deferring the WindowInsetsCompat.Type.ime insets until the WindowInsetsAnimationCompat is ended. For the above example, you would create a RootViewDeferringInsetsCallback like so:
val callback = RootViewDeferringInsetsCallback( persistentInsetTypes = WindowInsetsCompat.Type.systemBars(), deferredInsetTypes = WindowInsetsCompat.Type.ime() )This class is not limited to just IME animations, and can work with any WindowInsetsCompat.Types.
-
-
Field Summary
Fields Modifier and Type Field Description private final IntegerpersistentInsetTypesprivate final IntegerdeferredInsetTypesprivate final WindowInsetsmDispachedInsets
-
Constructor Summary
Constructors Constructor Description RootViewDeferringInsetsCallback(Integer persistentInsetTypes, Integer deferredInsetTypes)
-
Method Summary
Modifier and Type Method Description final IntegergetPersistentInsetTypes()final IntegergetDeferredInsetTypes()WindowInsetsCompatonApplyWindowInsets(View v, WindowInsetsCompat windowInsets)UnitonPrepare(WindowInsetsAnimationCompat animation)WindowInsetsCompatonProgress(WindowInsetsCompat insets, List<WindowInsetsAnimationCompat> runningAnims)UnitonEnd(WindowInsetsAnimationCompat animation)-
-
Constructor Detail
-
RootViewDeferringInsetsCallback
RootViewDeferringInsetsCallback(Integer persistentInsetTypes, Integer deferredInsetTypes)
- Parameters:
persistentInsetTypes- the bitmask of any inset types which should always be handled through padding the attached viewdeferredInsetTypes- the bitmask of insets types which should be deferred until after any related WindowInsetsAnimationCompats have ended
-
-
Method Detail
-
getPersistentInsetTypes
final Integer getPersistentInsetTypes()
-
getDeferredInsetTypes
final Integer getDeferredInsetTypes()
-
onApplyWindowInsets
WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat windowInsets)
-
onPrepare
Unit onPrepare(WindowInsetsAnimationCompat animation)
-
onProgress
WindowInsetsCompat onProgress(WindowInsetsCompat insets, List<WindowInsetsAnimationCompat> runningAnims)
-
onEnd
Unit onEnd(WindowInsetsAnimationCompat animation)
-
-
-
-