Skip to content

Add Cupertino scrollbar - #13290

Merged
xster merged 15 commits into
flutter:masterfrom
xster:cupertino-scrollbar
Dec 22, 2017
Merged

xster merged 15 commits into
flutter:masterfrom
xster:cupertino-scrollbar

Conversation

@xster

@xster xster commented Dec 1, 2017 •

Copy link
Copy Markdown
Member

Fixes #8774

  • Extract the scrollbar painter to widget
  • Add a bunch of new configurables like margins, sizing, when to fade etc
  • Create CupertinoScrollbar
  • Let material Scrollbar change look dynamically

@xster

xster commented Dec 7, 2017

Copy link
Copy Markdown
Member Author

Rebased from upstream

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please run flutter analyze --dartdocs to catch new members that are missing documentation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah crap, thanks for catching. Added a bunch missing. Surprised it wasn't in travis.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it make sense for this just to be a private member on the state?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Material scrollbar actually draws with cupertino painter on iOS. Seems consistent with googlekit on iOS.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, got it.

@xster
xster force-pushed the cupertino-scrollbar branch from 2fc0f22 to f5693e9 Compare December 7, 2017 23:09
@xster

xster commented Dec 7, 2017

Copy link
Copy Markdown
Member Author

Oops, didn't actually force push after rebasing. Pushed for real now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can remove this TODO (and the matching one on the other side), we're not likely to do this any time soon.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is easier to do now. Is it worth doing and reshaping the tree each time opacity comes in and out of = 0.0?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should just wait until we have a reason to do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done. PTAL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO we really shouldn't make the original _ScrollbarPainter class public. It's a crazy class with crazy semantics (e.g. it's a custom painter but you have to dispose it).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If I left 2 implementations in 2 separate files, it seems to alleviate your concern here and on the next comment. Do you prefer that approach? A bit copy paste-y I initially thought.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't make any sense for a CustomPainter to have externally mutable state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe that's too strong a statement. Let me say instead, it's very much contrary to how CustomPainter was intended to work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seems like the existing custom painter in material already mutates the painter (when the inherited theme changes). I didn't see any class docs on CustomPainter on its desired immutability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

false is wrong here. It should be comparing every constructor argument, and they should all be immutable fields, so that when you create a new instance of this custom painter, the painting logic knows whether it's different or not.

@xster
xster force-pushed the cupertino-scrollbar branch from f5693e9 to 563a0a3 Compare December 15, 2017 00:24
@xster

xster commented Dec 16, 2017

Copy link
Copy Markdown
Member Author

I did the refactor we talked about.

Basically the ScrollbarPainter is mostly immutable minus opacity and scroll metrics.
Material scrollbar just nests cupertino scrollbar on iOS.

Moved animation, controller, timer out to the widget states.

@Hixie

Hixie commented Dec 21, 2017

Copy link
Copy Markdown
Contributor

This is on my list to review, sorry I haven't gotten to it yet.

final ThemeData theme = Theme.of(context);
_currentPlatform = theme.platform;

if (_currentPlatform == TargetPlatform.iOS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here and in various other places: where you currently us an if to check the platform, use a switch so that the analyzer tells us if we missed handling a new platform when we add one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done


/// A [CustomPainter] for painting scrollbars.
///
/// Unlike [CustomPainter]s that sub-classes [CustomPainter] and only repaints

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/sub-classes/subclass/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/repaints/repaint/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

/// An opacity [Animation] that dictates the opacity of the thumb.
/// Changes in value of this [Listenable] will automatically trigger repaints.
/// Mustn't be null.
Animation<double> fadeoutOpacityAnimation;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be final

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah right, thanks

///
/// * the scroll position changes; and
/// * when the scrollbar fades away.
///

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These docs should talk about update() and how to use it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

assert(mainAxisMargin != null),
assert(crossAxisMargin != null),
assert(minLength != null) {
fadeoutOpacityAnimation.addListener(notifyListeners);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when do you removeListener?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you need to override dispose() and call removeListener there.

Also, the docs need to talk about how it's important to call dispose() on this object when you're done with it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added doc about needing to dispose.
ChangeNotifier.dispose already more or less does removeListener.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How does ChangeNotifier know about fadeoutOpacityAnimation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah you're right. Sorry, I mixed the 2 layers of listeners up.

@Hixie

Hixie commented Dec 21, 2017

Copy link
Copy Markdown
Contributor

LGTM modulo some minor issues.

@xster

xster commented Dec 21, 2017

Copy link
Copy Markdown
Member Author

Thanks for reviewing

@xster
xster merged commit 4fcdb50 into flutter:master Dec 22, 2017
@xster
xster deleted the cupertino-scrollbar branch December 22, 2017 00:44
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
* Create CupertinoScrollbar

* handle main axis margin

* Adaptive material scrollbar and tests

* Small tweaks

* reapply changes on head

* Docs

* start

* Refactored ScrollbarPainter to be more immutable

* fix tests

* fix bug: one animationcontroller pointed to multiple painters

* some docs tweak

* remove unused import

* review

* review

* add dispose
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Material scrollbars should adopt a platform-specific look and feel

3 participants