Skip to content

Updated Interactive Scrollbars #71664

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

Merged
merged 33 commits into from
Dec 11, 2020
Merged

Conversation

Piinks
Copy link
Contributor

@Piinks Piinks commented Dec 3, 2020

Description

Originally from #71181
Started to split up into multiple changes starting with #71242
Splitting this up did not make review easier, so I have applied the feedback that has been received so far into this new PR.
Design doc: https://flutter.dev/go/update-scrollbars

This is the first of several changes planned for #70866

This change will refactor the Scrollbar and CupertinoScrollbar widgets to use RawScrollbar as a base class.
I wanted to complete this refactoring first since these widgets have so many common lines of code.

The RawScrollbar widget will provide the basic fade in-out scrollbar thumb the framework currently provides, with the option to customize and add additional behavior by extending the class.

RawScrollbar will enable dragging on the thumb for RawScrollbar, Scrollbar, and CupertinoScrollbar since everyone is sharing. (Previously only CupertinoScrollbar supported dragging the thumb). It will also enable tapping on the scrollbar track to page the scroll view.

This will also remove the adaptive nature of the Scrollbar widget. I want to separate the CupertinoScrollbar from Scrollbar since as we expand on these widgets and look forward to additional platforms, having special handling in Scrollbar for CupertinoScrollbar was going to get even more complicated. Adaptive widgets like these do not scale well, and are easier to maintain and debug when separated. The new Material Design Scrollbar is very similar to the CupertinoScrollbar, so I am hoping the change will have a minimal effect.

Planned Changes for Scrollbars

(Order may change as these are reviewed and land)

1. Refactor to RawScrollbar
2. Update Scrollbar to match Material Design spec
3. Add track gestures
4. Add code samples, etc.
5. Add ScrollbarTheme
6. Create Scrollbars by default for relevant scrollables on desktop and web
7. ++ There will be more iterations and other bugs/behaviors people have been sending my way. We'll get to these, the above listed items are the primary focus for now. :)

Related Issues

Part of #70866
Fixes #70105

Tests

Existing tests pass after refactoring. :)
Added tests for

  • gestures, dragging and tapping scrollbar.
  • new material behavior and styles
    • drag color
    • hover animation
    • track shown with hover + thickness change

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • No existing tests have failed including google testing

Sorry, something went wrong.

@flutter-dashboard flutter-dashboard bot added a: internationalization Supporting other languages or locales. (aka i18n) f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 3, 2020
@google-cla google-cla bot added the cla: yes label Dec 3, 2020
@Piinks Piinks marked this pull request as draft December 3, 2020 16:44
@Piinks Piinks changed the title WIP - Scrollbars Updated Interactive Scrollbars Dec 8, 2020
@Piinks Piinks added f: scrolling Viewports, list views, slivers, etc. c: new feature Nothing broken; request for a new capability a: desktop Running on desktop platform-web Web applications specifically and removed a: internationalization Supporting other languages or locales. (aka i18n) labels Dec 8, 2020
@xu-baolin
Copy link
Member

I have tested the Android native APP behavior, It will also come out stacked bars(but not support interactive actions):
20201209_120916

I agree with the documentation that stacked the scrollbars is not recommended, and it is easy for developers to stagger their positions through padding or margin.

Additional, the chrome browser will automatic layout bars side by side:
image

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

This looks good; most of the feedback is just nitpickery to prove that I've read it.

The main non-trivial feedback is about making RawScrollbar's protected gesture API less touch-specific and using the Theme's color scheme to compute defaults in the Material scrollbar.

}

/// Same as hitTest, but includes some padding to make sure that the region
/// isn't too small to be interacted with by the user.
bool hitTestInteractive(Offset position) {
if (_thumbRect == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that eventually this will obviate the _thumbRect! expressions.

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 have updated to remove all of the ! by making the _thumbRect late. :) Good call!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That actually broke, switching back to nullable. 😅

_currentController = null;
}

void _handleTrackTapDown(TapDownDetails details) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Eventually we'll want subclasses to be able to handle track gestures via more protected methods.

if (_hoverIsActive) MaterialState.hovered,
};

MaterialStateProperty<Color> get _thumbColor {
Copy link
Contributor

Choose a reason for hiding this comment

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

The default values of the _thumbColor, _trackColor, etc properties should be based on the theme's color scheme because dark mode and consistency with other Material components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! :)

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

/// or use a PrimaryScrollController to share it.
///
/// Here is an example of using the `controller` parameter to enable
/// scrollbar dragging for multiple independent ListViews:
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's just an example that we've moved, it's OK to leave it as is. This example and the one for the controller property seem unnecessarily complicated. And they should be written in terms of RawScrollbar. We can improve them in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"activity?.isScrolling is not true" exception with CupertinoScrollbar
5 participants