Friday, 25 June 2021

Android Compose - Use traditional View with ComposeView

I use Compose with existed fragment. My structure in xml

<CoordinatorLayout>
    <AppBarLayout>
        <CollapsingToolbarLayout>
            <ImageView />
            <MaterialToolbar />
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.compose.ui.platform.ComposeView
            android:id="@+id/composeContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </androidx.core.widget.NestedScrollView>
</CoordinatorLayout>

In ComposeView, I use LazyColum, it crashed with log

java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed. If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then the list of items via items().

I think reason of that bug is LazyColum (scrollable) put inside other scrollable (NestedScrollView). But if I remove NestedScrollView, it look like

<androidx.compose.ui.platform.ComposeView
    android:id="@+id/composeContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

When I scroll list in LazyColumn, CollapsingToolbarLayout isn't scrolling. That is next bug.

How to fix it?

Please help me. Thanks.



from Android Compose - Use traditional View with ComposeView

No comments:

Post a Comment