'WindowInsetsControllerCompat.OnControllableInsetsChangedListener don't fire on insets show action

I have this listener:

val listener = WindowInsetsControllerCompat.OnControllableInsetsChangedListener { controller: WindowInsetsControllerCompat, typeMask: Int ->
                Log.i(FragmentVodPlayer.TAG, "onControllableInsetsChanged: changed")
                if (typeMask and WindowInsetsCompat.Type.statusBars()
                    == WindowInsetsCompat.Type.statusBars()
                    || typeMask and WindowInsetsCompat.Type.navigationBars()
                    == WindowInsetsCompat.Type.navigationBars()
                ) {
                    hideAfterAWhile.postDelayed({
                        controller.hide(
                            WindowInsetsCompat.Type.navigationBars()
                                    or WindowInsetsCompat.Type.statusBars()
                        )
                    }, 3000)
                }
            }

And I'm adding it to instetsController like this:

insetsController.addOnControllableInsetsChangedListener(listener)

It works fine when I'm executing:

insetsController.hide(
                    WindowInsetsCompat.Type.statusBars()
                            or WindowInsetsCompat.Type.navigationBars()
                )

But when I tap my screen and the navigation bar shows up, this listener never triggers, and from what I read in docs it should.

I know that this listener works when I hide system bars cos I can see it prints messages into my logcat.



Solution 1:[1]

So, after many, many tries to get this to working i gave up but i foun out that if You change systemBarsBehaviour

insetsController.systemBarsBehavior =
                    WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

system hides everything by itself and I'm getting desired effect much easier and probbably this is how it was intended.

Solution 2:[2]

I was facing the same issue and questions so I ended up using View.OnApplyWindowInsetsListener and detecting the status bars visibility with WindowInsets.isVisible(WindowInsets.Type.statusBars()).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arek Kubi?ski
Solution 2 moneytoo