Hey! Anyone have worked with `BackdropScaffold`? I...
# compose
j
Hey! Anyone have worked with
BackdropScaffold
? I'm having some troubles with the interop with XML. I am using a
BackdropScaffold
in compose where my front layer is an xml layout that I am integrating. The main problem is that when the front layer is active and the back layer concealed, the scroll behaviour is not properly propagated to the front layer and because of that the front layer is not scrollable (Only few times is working) I have tried to follow the following documentation, a parent composable containing a child AndroidView, but still it is not working.
@vide with that reaction you mean to add all of the code in the thread and just leave the question?
v
Yeah, I would generally do this when the amount of code exceeds a few lines. This channel has a lot of traffic and it makes it easier to see everyone's questions 😄
j
Sure, apologies Elias, I'm fixing it 🙂
Copy code
BackdropScaffold(
    modifier = Modifier.fillMaxSize(),
    appBar = { AnyAppBar() },
    scaffoldState = rememberBackdropScaffoldState(BackdropValue.Revealed),
    backLayerContent = {
        Spacer(modifier = Modifier.height(8.dp))
        LazyRow(
            horizontalArrangement = Arrangement.spacedBy(8.dp),
            contentPadding = PaddingValues(horizontal = 16.dp),
        ) {
            items(cards) { card ->
                AnyCardItem(card = card)
            }
        }
        Spacer(modifier = Modifier.height(24.dp))
    },
    frontLayerContent = content,
)
The
content
is a
@Composable () -> Unit
as follow:
Copy code
fun listComposable(): @Composable () -> Unit {
    return {
        val containerId by rememberSaveable { mutableStateOf(View.generateViewId()) }
        val container = remember { mutableStateOf<FragmentContainerView?>(null) }
        AndroidView(
            modifier = Modifier.fillMaxSize(),
            factory = { context ->
                FragmentContainerView(context)
                    .apply { id = containerId }
                    .also {
                        fragmentManager.commit { add(it.id, AnyFragment.newInstance()) }
                        container.value = it
                    }
            },
        )
    }
}
In the code above I am just converting the fragment that I need to integrate in the
BackdropScaffold
into a composable And finally the fragment is created with the following layout:
Copy code
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
    xmlns:app="<http://schemas.android.com/apk/res-auto>"
    xmlns:tools="<http://schemas.android.com/tools>"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:layout_behavior="es.lidlplus.common.FixedAppBarLayoutBehavior"
        >

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            style="@style/AppBar.CollapsingLayout"
            android:layout_width="match_parent"
            android:layout_height="108dp"
            app:collapsedTitleGravity="start"
            app:expandedTitleMarginStart="14dp"
            app:expandedTitleMarginTop="0dp"
            app:toolbarId="@+id/toolbar"
            >

            <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/white"
                app:layout_collapseMode="pin"
                />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/activated_count_text_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginStart="18dp"
                android:layout_marginVertical="10dp"
                />

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:orientation="vertical"
        android:paddingBottom="75dp"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
It is a
CoordinatorLayout
that contains a
CollapsingToolbarLayout
and a
RecyclerView
. Everything is displayed correctly but once the front layer is active the recycler view is not scrolling. I tried to set
ViewCompat.setNestedScrollingEnabled(view, true)
and the
BackdropScaffold
internally is using a
nestedScroll
state, but still the delta is not propagated to the fragment. Any ideas?