Search code examples
androidkotlinwindowinsets

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

  • 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.