android-tvleanback

How to implement transition between two PageRow in leanback BrowseFragment?


I'm using a leanback BrowseFragment to implement a simple android tv app. I have two PageRows which are backed by custom fragments. When I switch between the two in the browse navigation area, the content side of the screen goes blank briefly before the new fragment's views appear. How can I fade from one view to the other without a delay in between?

I see some references to "entrance transition" in the docs which I think is what I need, but I can't find any examples of what to do in those callbacks.

https://developer.android.com/reference/android/support/v17/leanback/app/BrowseFragment.MainFragmentAdapter.html#setEntranceTransitionState(boolean)


I tried to implement setEntranceTransitionState on my PageRow Fragment's MainFragmentAdapter, but it is never invoked:

class GuideFragment: Fragment(), BrowseFragment.MainFragmentAdapterProvider {
    val fragmentAdapter = object: BrowseFragment.MainFragmentAdapter<GuideFragment>(this) {
        override fun setEntranceTransitionState(state: Boolean) {
            Log.v("TEST", "setEntrance($state)")
            fragment.setEntranceTransitionState(state)
        }
    }
    override fun getMainFragmentAdapter() = fragmentAdapter
}

Solution

  • There is no way to do this when using BrowseSupportFragment.

    If you look at the implementation of swapToMainFragment(), you'll see that while scrolling the content is set to an empty fragment. When SCROLL_STATE_IDLE is reached, a regular fragment transaction is used to replace the child fragment with the new content.