florent37 / ExpansionPanel

Android - Expansion panels contain creation flows and allow lightweight editing of an element.
https://material.io/guidelines/components/expansion-panels.html
Apache License 2.0
1.98k stars 239 forks source link

onSaveInstanceState don't save the state of ExpansionLayout #67

Open yura-f opened 4 years ago

yura-f commented 4 years ago

I've set "id" for the ExpansionHeader and ExpansionLayout and expanded(opened) my item, but after return on fragment I get closed item with right state of "headerIndicator".

Why and how fix it?

The right behavior is the item should be open after return. Thx

@florent37 After debugging, I've caught a break point into setHeight (ExpansionLayout) and height always equals 0!

My XML is:

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/mainContainer"
    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"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nestedScrollView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:windowSoftInputMode="adjustResize"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/applyBtn">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.github.florent37.expansionpanel.viewgroup.ExpansionsViewGroupLinearLayout
                android:id="@+id/expansionsViewGroupLinearLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginTop="24dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent">

                <com.github.florent37.expansionpanel.ExpansionHeader
                    android:id="@+id/priceExpansionHeader"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:expansion_layout="@id/rangePriceExpansion"
                    app:expansion_headerIndicator="@id/arrow"
                    app:expansion_headerIndicatorRotationExpanded="0"
                    app:expansion_headerIndicatorRotationCollapsed="-90"
                    app:expansion_toggleOnClick="true">

                    <com.app.ui.widgets.RangeHeaderLayout
                        android:id="@+id/priceRangeHeader"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:title="@string/price"
                        app:subtitle="@string/from_num_to_num"/>

                </com.github.florent37.expansionpanel.ExpansionHeader>

                <com.github.florent37.expansionpanel.ExpansionLayout
                    android:id="@+id/rangePriceExpansion"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white">

                    <com.jaygoo.widget.RangeSeekBar
                        android:id="@+id/rangePrice"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="16dp"
                        app:rsb_gravity="center"
                        app:rsb_mode="range"
                        app:rsb_indicator_show_mode="alwaysHide"
                        app:rsb_progress_color="@color/black50"
                        app:rsb_progress_default_color="@color/divider"
                        app:rsb_progress_height="2dp" />

                </com.github.florent37.expansionpanel.ExpansionLayout>
yura-f commented 4 years ago

@florent37 Also, if U expanded anyone item then the method: private void setHeight(float height) {...} (ExpansionLayout) is calling on the infinity loop.

I think it's a strange behavior.