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

Collapse browser toolbar on scrolling the card list #18037

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oakkitten
Copy link
Contributor

Purpose / Description

Collapse browser toolbar on scrolling the card list. The toolbar takes space and may take even more space when browser chips are introduced (see #17355, #12554).

Screen_recording_20250301_155316.mp4

Approach

Pretty straightforward, use AppBarLayout. I used my old commit which had some issues, namely:

  • Sometimes the fling gesture would be treated as a scroll gesture, with things just stopping scrolling instead of continuing scrolling after finger was lifted off the screen, and
  • If the card list had only a few cards, it wouldn't move with gestures and the toolbar could be stuck in half-collapsed state.

I suspected that these issues would be resolved with moving to RecyclerView, and it seems that they have.

See also the commit message.

How Has This Been Tested?

Briefly tested on my device API 34 and emulator API 24. Requires more on-hand testing to ensure the above issues are truly gone.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Here I opted for an extra `LinearLayout` inside of the `AppBarLayout`
for a minimal and safe-contained change. Other options are available,
see the comment in the code.

I also moved the linear progress indicator to the bottom of the
`CoordinatorLayout` for the following reasons:

  * As a child of `CoordinatorLayout`, which is a “super-powered
    `FrameLayout`”, it doesn't shift other elements when it becomes
    visible and disappears;

  * It stays on the bottom and doesn't move with the scrolling cards;

  * Before, visually it was positioned just inside of the grid of the
    table, which looked a bit weird, and it has rounded corners and
    thus appeared shorter than the table;

  * It may be harder to move it along with the `RecyclerView`.
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Requesting @david-allison opinion as you worked on this extensively.


<!-- Note: AppBarLayout itself is a vertical LinearLayout, so strictly speaking
Copy link
Member

@lukstbit lukstbit Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is needed(maybe in the commit message).
We shouldn't look into optimizing by tying to specific implementations. We already had several crashes due to using specific LayoutParams(although a more general parent was available) and then changing the layout structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this information as a comment as having a vertical LinearLayout as a child of AppBarLayout is weird, and whoever reads the code later on will eventually wonder why it is here. While this could be in a commit message, it takes time and effort to go through the blame to find anything useful, and more often than not the explanation just isn't there.

(As per the tutorial, you would be setting app:layout_scrollFlags on the individual children of AppBarLayout.)

@lukstbit lukstbit added Needs Second Approval Has one approval, one more approval to merge Needs reviewer reply Waiting for a reply from another reviewer labels Mar 2, 2025
@lukstbit lukstbit requested a review from david-allison March 2, 2025 08:34
here it is not necessary to have another LinearLayout as a child.
Instead we could be setting app:layout_scrollFlags on the individual children.
However, the <include> tag can only override a very limited set of arguments,
so the alternatives here would be not using the <include> tag,
Copy link
Member

@BrayanDSO BrayanDSO Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my two cents: the alternative of not using <include> is super reasonable. Most of the new screens don't use it, if that matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick search says there are 15 files saying <include layout="@layout/toolbar" in the XML

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the new screens don't use it

A quick search says there are 15 files saying <include layout="@layout/toolbar" in the XML

Yes, it is still used in some places, but most of the "new" ones use MaterialToolbar instead of including the toolbar.xml layout, which has some extra sutff that normally is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I just went this way for the self-contained minimal change, otherwise I personally have no opinion on which way is the best one. 🤷‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs reviewer reply Waiting for a reply from another reviewer Needs Second Approval Has one approval, one more approval to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants