question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fragment transaction breaks layout if exitUntilCollapsed flag is set

See original GitHub issue

Description: The pretty much standard layout of

CoordinatorLayout
    AppBarLayout
        CollapsingToolbarLayout [app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"]
            Toolbar
NestedScrollView [app:layout_behavior="@string/appbar_scrolling_view_behavior"]

in fragment works pretty well until fragment transaction happens (e.g. switch to another fragment and come back).

With no exitUntilCollapsed flag set original fragment got restored as it should keeping the scroll position etc. But if this flag is set various issues happen after the fragment transaction including scroll position reset (sometimes) and (pretty much always) inability to move scrolled content (including overscroll effect) to the view port.

Removal of exitUntilCollapsed flag makes the whole thing work again but at the price of Toolbar visibility.

Source code: https://github.com/material-components/material-components-android/blob/master/catalog/java/io/material/catalog/tableofcontents/res/layout/cat_toc_fragment.xml

Android API version: 23

Material Library version: master branch

Device: LG G3

Demo: After I’ve switched to another fragment and came back the part of content (“Transitions” label, overscroll etc) became unavailable:

example

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

1reaction
crocsandcoffeecommented, Feb 4, 2021

I don’t believe this issue has been fixed yet. I am using the layout below:

<CoordinatorLayout

    <RecyclerView app:layout_behavior="@string/appbar_scrolling_view_behavior"
    
    <AppBarLayout
     
        <CollapsingToolbarLayout app:layout_scrollFlags="scroll|exitUntilCollapsed"
    

and let’s say the toolbar is in collapsed state, and user has scrolled somewhere in the list, taps a list item and navigates to another fragment. Hitting back, the fragment transaction is reversed, and upon returning to this fragment, the collapsing toolbar is in expanded state but scroll pos in recycler view has been retained. it almost looks like the Collapsing toolbar expands as the fragment is exiting, so when returning to it, it’s now in expanded state.

I tested with version 1.3.0-rc01 which was tagged above as having a commit that fixes this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragment transactions - Android Developers
Enabling the flag ensures that if multiple transactions are executed together, any intermediate fragments (i.e. ones that are added and then ...
Read more >
Going mad with Android Fragment Transaction - Stack Overflow
When the app launches, the first Tab (Guide) is added and shown correctly. Then I tap on Map (next Fragment), this is added...
Read more >
Building dynamic user interfaces in Android with fragments
The FragmentManager class allows you to add, remove and replace fragments in the layout of your activity. It can accessed in an activity...
Read more >
1.1: Creating a Fragment with a UI · GitBook
Use the layout editor to create a UI with a ConstraintLayout . Inflate the UI layout for an Activity . Add a set...
Read more >
Fragment transaction custom animations have wrong z ordering
</set> (The zAdjustment tag does nothing) The exiting fragment will be on top of the entering fragment, which is the opposite behavior than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found