Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CollapsingToolbarLayout] Scroll state not preserved when recreating view and exitUntilCollapsed scroll flag is set #3473

Open
mateuszkwiecinski opened this issue Jul 10, 2023 · 4 comments

Comments

@mateuszkwiecinski
Copy link

mateuszkwiecinski commented Jul 10, 2023

Description:
I spotted multiple mentions of the same issue, i.e. here: #1019 (comment), so I assume this is not new, but since I couldn't find a proper bug report I'm creating a new one.
The issue is: CollapsingToolbarLayout with app:layout_scrollFlags="scroll|exitUntilCollapsed" doesn't preserve its scroll state when the view is destroyed and then recreated (i.e. when navigating back between fragments)

Expected behavior: Screenshots and/or description of expected behavior
The CollapsingToolbarLayout scroll state is exactly the same as it was before leaving the screen.

Expected

Screen.Recording.2023-07-10.at.20.38.19.mov

Actual

Screen.Recording.2023-07-10.at.20.34.58.mov

(the "should be hidden" label should not be visible. It is because CollapsingToolbar restores in an "expanded" state)

Source code:
My current repro is:

 <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false"
            >

            <TextView
                android:id="@+id/tipText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp"
                android:paddingBottom="?actionBarSize"
                android:text="Should be hidden"
                android:textColor="#fff"
                android:textSize="30sp"
                app:layout_collapseMode="parallax"
                />

            <com.google.android.material.appbar.MaterialToolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:layout_gravity="bottom"
                app:layout_collapseMode="pin"
                app:title="Always visible"
                />
        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

but the crucial part is the exitUntilCollapsed.

Interesting thing is setting minHeight to tipText TextView seems to restore proper behavior. This is very confusing 😅

Minimal sample app repro:
Full project: https://github.com/mateuszkwiecinski/collapsing_toolbar_doesnt_work

  1. ./gradlew installDebug
  2. Launch app
  3. Scroll up, so the "Should be hidden" label disappears
  4. Tap the "Navigate forward and back to recreate view" which commits another fragment and immediately pops it back
  5. 🐛 should be visible now

Android API version:
28, 31, 33

Material Library version:
1.11.0-alpha01, 1.9.0

Device:
Android emulator

@KarolCieslar
Copy link

I have the same issue

@andre-sergej-woerner-db

Is there any workaround for now?

@pekingme
Copy link
Contributor

I believe this is WAI. Once navigated to another fragment and back, the tool bar becomes visible to explicitly show what current fragment's title and actions. Imho, this is better for providing users a better orientation.

@mateuszkwiecinski
Copy link
Author

mateuszkwiecinski commented Oct 30, 2023

the tool bar becomes visible to explicitly show what current fragment's title and actions

The toolbar is already always visible (or to be more precise: is configurable by i.e layout_collapseMode=pin). The unwanted behavor is the library also expands the collapsing part unnecessairly.
If the collapsed information is that important it shouldn't be collapsible in the first place 🤷 + I must say that I've never seen UX approach that suggests to "expand everything user has just collapsed, because they could have forgotten what was there few seconds ago"

I'll also mention the current behavior can be considered confusing since from user's perspective the scroll position isn't preserved. After they tap at the element at the bottom, it's not visible anymore. Imagine going through a list of short cards with tall CollapsingToolbar on a small screen. Each time you tap a card to view the details and navigate back you see differeent set of elements than when you tap on a list list time.

Also, the official documentation pretty clearly suggests

A user expects an activity's UI state to remain the same throughout a configuration change

which currently is not the case (user sees different state of the screen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants