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

Updating PrimaryScrollController for Desktop #102099

Merged
merged 6 commits into from
Jun 9, 2022
Merged

Conversation

Piinks
Copy link
Contributor

@Piinks Piinks commented Apr 18, 2022

This updates the PrimaryScrollController to not automatically attach to scroll views on desktop as it does on mobile platforms.
This behavior has caused a lot of issues for users developing desktop applications that have multiple parallel vertical ScrollViews.
This adds two parameters to PrimaryScrollController

  • automaticallyInheritForPlatforms
    • specifies a set of TargetPlatforms that will engage automatic inheritance
  • scrollDirection
    • This adds the ability to specify which axis the PrimaryScrollController should be inherited for.

Also adds static method shouldInherit, which uses the two properties above to determine if automatically inheriting the ScrollController is appropriate for the current configuration.

This design and other approaches is discussed at length in this design document.

Fixes #100264
Related (among others):

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 f: scrolling Viewports, list views, slivers, etc. a: desktop Running on desktop labels Apr 18, 2022
@flutter-dashboard flutter-dashboard bot added a: text input Entering text in a text field or keyboard related problems d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Apr 18, 2022
@Piinks Piinks changed the title Psc 2 Updating PrimaryScrollController for Desktop Apr 18, 2022
@@ -96,6 +96,7 @@ class PaletteTabView extends StatelessWidget {
final TextStyle blackTextStyle = textTheme.bodyText2!.copyWith(color: Colors.black);
return Scrollbar(
child: ListView(
primary: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These integration tests are run on mobile and desktop platforms, so I have added primary: true so they all inherit the PrimaryScrollController as they did so automatically prior to this change.

Copy link
Member

Choose a reason for hiding this comment

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

Why is this important, though? Would anything break if we don't do this? Does this mean we are breaking users as well and they need to go in to make this change in their apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only on desktop, which is the point of this change.

The automatic attachment of the PrimaryScrollController will no longer happen on desktop. Thee integration test expect that behavior across all of the platforms. The tests could be refactored for each platform, but that seemed outside of the scope for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, the test will fail when run configured to desktop, because it is no longer automatic.

@@ -34,14 +44,18 @@ class PrimaryScrollController extends InheritedWidget {
const PrimaryScrollController({
super.key,
required ScrollController this.controller,
this.autoForPlatforms = _kMobilePlatforms,
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 do not like this name, but have not thought of something else yet.

Copy link
Member

Choose a reason for hiding this comment

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

+1 - brainstorming some other suggestions:

  • enabledPlatforms - can you do anything with this of running on a platform that's not part of this set?
  • inheritOnPlatforms

... naming is hard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is tricky because it can be inherited on any platform, this is specific to the automatic inheritance.

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 you do anything with this of running on a platform that's not part of this set?

I am not sure I understand this question

@Piinks Piinks removed f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Apr 18, 2022
@flutter-dashboard flutter-dashboard bot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. labels Apr 25, 2022
@Piinks Piinks requested a review from goderbauer April 25, 2022 23:42
@@ -96,6 +96,7 @@ class PaletteTabView extends StatelessWidget {
final TextStyle blackTextStyle = textTheme.bodyText2!.copyWith(color: Colors.black);
return Scrollbar(
child: ListView(
primary: true,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this important, though? Would anything break if we don't do this? Does this mean we are breaking users as well and they need to go in to make this change in their apps?

&& Scrollable.of(primaryScrollController.position.context.notificationContext!) != null;
}
final ScrollController? primaryScrollController = PrimaryScrollController.of(focus.context!);
return primaryScrollController != null && primaryScrollController.hasClients;
Copy link
Member

Choose a reason for hiding this comment

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

for my own understanding: why were you able to simplify this so much?

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 moved much of this logic to the invoke method. Accessing the position here would throw an error (the bug we are fixing), but the error did not make sense in the stack trace that would result from throwing here.
By throwing from invoke, I thought it would make more sense.

packages/flutter/lib/src/widgets/scrollable.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollbar.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/widgets/scrollbar.dart Outdated Show resolved Hide resolved
packages/flutter/test/widgets/scroll_view_test.dart Outdated Show resolved Hide resolved
///
/// If a [ScrollController] has already been provided to
/// [ScrollView.controller], or [ScrollView.primary] is false, this is
/// disregarded.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more docs, let me know what you think.

&& Scrollable.of(primaryScrollController.position.context.notificationContext!) != null;
}
final ScrollController? primaryScrollController = PrimaryScrollController.of(focus.context!);
return primaryScrollController != null && primaryScrollController.hasClients;
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 moved much of this logic to the invoke method. Accessing the position here would throw an error (the bug we are fixing), but the error did not make sense in the stack trace that would result from throwing here.
By throwing from invoke, I thought it would make more sense.

Comment on lines 1199 to 1706
&& Scrollable.of(primaryScrollController.position.context.notificationContext!) == null) {
return;
}
state = Scrollable.of(primaryScrollController.position.context.notificationContext!);
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 is where I relocated some of the logic from isEnabled, after we know it is safe to access the position.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

packages/flutter/lib/src/widgets/scrollbar.dart Outdated Show resolved Hide resolved
}());

if (primaryScrollController!.position.context.notificationContext == null
&& Scrollable.of(primaryScrollController.position.context.notificationContext!) == null) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: indentation is off here (condition continuation and body should not have same indentation level). I think I would just indent this line by 2 more spaces...

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • This commit is not mergeable and has conflicts. Please rebase your PR and fix all the conflicts.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jun 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 14, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
@Piinks Piinks mentioned this pull request Feb 14, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Primary Scroll Controller for Flutter Desktop apps
3 participants