Joan Colmenero
08/24/2023, 6:50 AMBackdropScaffold
? 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.Joan Colmenero
08/24/2023, 8:38 AMvide
08/24/2023, 8:39 AMJoan Colmenero
08/24/2023, 8:42 AMJoan Colmenero
08/24/2023, 8:42 AMBackdropScaffold(
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:
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
}
},
)
}
}
Joan Colmenero
08/24/2023, 8:43 AMBackdropScaffold
into a composable
And finally the fragment is created with the following layout:
<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>
Joan Colmenero
08/24/2023, 8:43 AMCoordinatorLayout
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?