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

Fragment transaction breaks layout if exitUntilCollapsed flag is set #1019

Closed
mikhailmelnik opened this issue Feb 14, 2020 · 8 comments
Closed
Labels

Comments

@mikhailmelnik
Copy link

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

@lvcmenezes
Copy link

Same problem here, did you manage to find a fix for it?

@mikhailmelnik
Copy link
Author

@lvcmenezes nope, and I wonder how does world live with that without any complain.

@mikhailmelnik
Copy link
Author

@lvcmenezes looks like I found a workaround, not sure though if it works in all circumstances:

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val view = ...
    view.postDelayed(0) { view.requestLayout() }
    return view
}

@mikhailmelnik
Copy link
Author

@chrisbanes could be this issue related the issue you've fixed with #299 ?

@mariuspena
Copy link

I have almost the same issue. I have tried version 1.1.0, and 1.2.0-alpha06

See video:
https://youtu.be/Q_LaMnwhOyU

  1. 1st view: a Fragment that has CoordinatorLayout, it scrolls fine.
  2. go to another activity (same setup.. )
    2.1. if I do not touch any view in the activity and go back, the fragment scrolls fine
    2.2. if I focus on an EditText, or click on a Button and then go back > the header scrolls, the content stays in the same place.

PS: since the 1st view (the fragment) is part of a Navigation (with NavHostFragment and BottomNavigationView) ... sometimes the other fragments have 0 width and height (so a blank page.. although the api calls work, recyclers are populated, etc)

@mikhailmelnik
Copy link
Author

Fixed by a21a300

@crocsandcoffee
Copy link

crocsandcoffee commented 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.

@OhhhThatVarun
Copy link

Yes, it is not fixed. I tested it with 1.13.0-alpha02. I'm having the same issue as @crocsandcoffee. The CollapsingToolbarLayout just doesn't stay collapsed.

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

No branches or pull requests

5 participants