androidandroid-jetpack-composeandroid-collapsingtoolbarlayout

How to use Android Compose Scaffold AppBar CollapsedScrollBehavior with RecyclerView?


I am trying to implement the scaffold appBar collapsedScrollBehavior and it's working perfectly fine when the content is in compose like LazyColumn.

But in my use case, I am inflating the fragment with RecyclerView inside the Scaffold Content using Android Compose Interop APIs. Scaffold appBar is not collapsing/expanding when I am scrolling the RecyclerView which is inside the fragment.

I know it's a unique scenario and could found any documentation under Android Compose Interop APIs. Kindly let me know if there is anything I can try to make this work.


Solution

  • That should be possible using NestedScrollConnection. You'll need to do two things:

    1. Call ViewCompat.setNestedScrollEnabled in the root View you are inflating within AndroidView
    2. Apply the nestedScroll modifier to the parent Scaffold and provide your NestedScrollConnection

    You can read about this more in the documentation page A parent composable containing a child AndroidView.