Skip to content

Conversation

@Piinks
Copy link
Contributor

@Piinks Piinks commented Mar 9, 2023

Part of the 2D scrolling proposal: flutter.dev/go/2D-Foundation

Fixes #122348

Adds a .dual constructor to the scrollbar classes in order to support 2D scrolling

  • RawScrollbar
  • Scrollbar
  • CupertinoScrollbar

Also adds a method to scroll behaviors for calling on this in the 2D case. Relying on ScrollBehavior again will also enable other options in 2D scrolling, like if the developer does not want one or both of the scrollbars. This is consistent with other patterns in the framework.

  • ScrollBehavior
  • MaterialScrollBehavior
  • CupertinoScrollBehavior

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@Piinks Piinks added c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Mar 9, 2023
@flutter-dashboard flutter-dashboard bot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. labels Mar 9, 2023
// TODO(Piinks): Instead, `.dual` should be a constructor that internally
// creates two ScrollbarPainters so that they can respond to each other
// appropriately: https://github.com/flutter/flutter/issues/122345
return RawScrollbar(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TahaTesser @xu-baolin I wonder if you have any thoughts here.
There are a lot of properties in the RawScrollbar constructor that we would want to expose here for the dual constructor, but I do not want to enumerate them all twice (vertical ones and horizontal ones)

WDYT of a ScrollbarDetails or ScrollbarStyle class that can encapsulate all of the styling parameters and allowing folks to pass one for vertical and one for horizontal?
Alternatively, we could leave this for now in its simplest form and folks can override this?

Not sure. We do not have to do it all in one change either. But I am curious if you have thoughts. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another point to consider, there may be other unique ways users want to configure dual scrollbars. I filed #122351 for example as one thing I thought of.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should expose basic properties to satisfy the common usage.
Also, let it be able to do custom easily.

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 filed these for follow up, there is definitely going to be multiple changes to get to all of the features needed to do this right :)

// TODO(Piinks): Instead, `.dual` should be a constructor that internally
// creates two ScrollbarPainters so that they can respond to each other
// appropriately: https://github.com/flutter/flutter/issues/122345
return RawScrollbar(
Copy link
Member

Choose a reason for hiding this comment

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

We should override the outer RawScrollbar.notificationPredicate to let them work, right?

Maybe we can write a sample to show how to use this new feature : )

Copy link
Member

Choose a reason for hiding this comment

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

We should also remove the default bar for desktop platforms if users choose the dual bars.

Copy link
Contributor Author

@Piinks Piinks Mar 13, 2023

Choose a reason for hiding this comment

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

That should not be necessary, since the new TwoDimensionalScrollable maintains the same notification depth for both axes.
Plus, it overrides the default behavior with the buildDualScrollbars method instead of the 1D buildScrollbar. :)

See this for a rough example, finishing up some of the details this week:

Copy link
Member

Choose a reason for hiding this comment

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

Can we let this also support two nested scrollable widgets? Folks may not know this can only work for TwoDimensionalScrollable.

Just watched this, it's amazing!

Copy link
Member

Choose a reason for hiding this comment

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

the new TwoDimensionalScrollable maintains the same notification depth for both axes.

This may have an impact on the Scrollbar implementation because the scroll notification has the same depth but a different axis direction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may have an impact on the Scrollbar implementation because the scroll notification has the same depth but a different axis direction.

It actually works! I have been using it for months while I have been working on this. Just the corner space needs better handling (filed an issue linked above). And the scroll controllers must be assigned, there would be a lot of room for error if the scrollbar was just trying to respond blindly to notifications in this case. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we let this also support two nested scrollable widgets? Folks may not know this can only work for TwoDimensionalScrollable.

I think it is reasonable to expose the notification predicate in some way, but by default this dual composition should just listen to a depth of 1 as it is intended to be used with the 2D scrolling classes I am working on. Trying to self-compose 2D scrolling has a lot of issues (which is why we're working on making it easier!), and I don't want to overcomplicate a new feature by trying to account for every possible composition folks might have created themselves. I'll make sure this is documented really well, although I cannot reference TwoDimensionalScrollable until it lands (soon!).

Of course, we could get some feedback from users once this lands and decide to change it, that's why I love this project. 😊 Right now my goal is to get a solid basic foundation in place, and build from there.

@Piinks
Copy link
Contributor Author

Piinks commented Mar 14, 2023

I'm going to go ahead and pipe in the parameters here, updating soon.

@Piinks Piinks marked this pull request as draft March 14, 2023 19:51
@Piinks
Copy link
Contributor Author

Piinks commented Mar 15, 2023

Bah, I keep running into the same ugly feeling. There are so many properties on scrollbar, I don't want to enumerate them all twice on the dual constructor, so I try to wrap them all up in a details object, but then I get massive code smell from duped properties between the regular 1D scrollbar and the details object... which makes me feel like we should have the 1D constructor just take the details object for a clean API... which means we would have to deprecate everything.. and then I am sad.

We probably should have just exposed the painter rather than all of the individual properties...

I am not sure what the best approach is yet. Especially since the final dual scrollbar needs to have both painters working together internally.

I think for now I will close this and return to it when TwoDimensionalScrollable is in. For now, it can call ScrollBehavior.buildScrollbar twice and have the same result. Then we can follow up and do this the right way.

@Piinks Piinks closed this Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2D Follow up: Add dual scrollbar constructors and methods

2 participants