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
DraggableScrollableSheet & NestedScrollView should respect NeverScrollableScrollPhysics #123109
Conversation
@@ -969,4 +972,7 @@ class NeverScrollableScrollPhysics extends ScrollPhysics { | |||
|
|||
@override | |||
bool get allowImplicitScrolling => false; | |||
|
|||
@override | |||
bool get allowUserScrolling => false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't shouldAcceptUserOffset
above provide the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the default implementation of shouldAcceptUserOffset might not work as this is intended. However, I think if adding this allowUserScrolling is the right way to resolve this, it should work with shouldAcceptUserOffset, or at least document what the difference between them is. Should shouldAcceptUserOffset also consider allowUserScrolling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Piinks Nice point! Let us review the original issue again : )
1, The framework warp a gesture recognizer only if physics.shouldAcceptUserOffset(this)
returns true.
flutter/packages/flutter/lib/src/widgets/scrollable.dart
Lines 645 to 649 in f266ccc
void setCanDrag(bool value) { | |
if (value == _lastCanDrag && (!value || widget.axis == _lastAxisDirection)) { | |
return; | |
} | |
if (!value) { |
So, If the DSS's extent becomes large enough, the scrollable will become unscrollable and the gesture will be removed (The extent's size is actually the scrollable viewport). Then the DSS is stuck and cannot be pulled back. This is the #31739 root cause.
2, Here is _DraggableScrollableSheetScrollPosition.applyUserOffset
's implement
flutter/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
Lines 877 to 882 in f266ccc
void applyUserOffset(double delta) { | |
if (!listShouldScroll && | |
(!(extent.isAtMin || extent.isAtMax) || | |
(extent.isAtMin && delta < 0) || | |
(extent.isAtMax && delta > 0))) { | |
extent.addPixelDelta(-delta, context.notificationContext!); |
It set the extent's size by the user scrolling. So, if we want fix the original issue we must let the scrollable always scrollable, right?
Regardless of whether #31832 or #109081, they essentially make the scrollable to be always scrollable, but #31832 is a bit hack and introduces issue #98314.
Unfortunately, #109081 introduces issue #121021 because it ignores the ‘NeverScrollableScrollPhysics’ case. This is why I make this change to introduce a method to distinguish the NeverScrollableScrollPhysics
and others.
In addition, I tried other solutions at the same time, such as caching the old physics, and then applying it to the user scrolling, but I gave up for it is a bit complicated.
Glad to here your thoughts : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thank you for this! I really appreciate the context. I came across #113753 which is a similar-ish case of the explicit physics being overridden by a widget applying other physics.
This makes me think, what do you think about some way for users to specify that physics should not be meddled with? And then maybe in applyTo
we check that? I dunno, just brainstorming..
However, this is slightly different from #113753 in that in the nested scroll view, we see userSuppliedPhysics.applyTo(extraImplementationPhysics), while here we see extraImplementationPhysics.applyTo(userSuppliedPhysics).. so this idea may not actually work...
Since it appears there is a pattern where the user may not want us to to change the scroll physics (I am sure there are other places where we do this, overriding the value explicitly set by the user), what are you thoughts on approaching this in a way that lets users preserve their preferred scroll physics? (not exclusive to just NeverScrollable and allowUserScrolling
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thank you for this! I really appreciate the context. I came across https://github.com/flutter/flutter/issues/113753 which is a similar-ish case of the explicit physics being overridden by a widget applying other physics.
It seems like physics overridden is not the root cause of that issue but this patch may help to fix that : )
This makes me think, what do you think about some way for users to specify that physics should not be meddled with?
Good idea but I'm concerned that doing this would be a breaking change?
56c008d
to
d33b342
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this is the right approach, I actually wonder if the original fix for #98314 was not the right solution. Applying AlwaysScrollableScrollPhysics may have other side effects like we are seeing here with NeverScrollableScrollPhysics.
I am not sure what the right change is, but I'd like to see if we can revisit the original issue and check to see if there is a better solution there first. What do you think @xu-baolin?
9e448a8
to
8fd6b36
Compare
@@ -781,7 +781,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController { | |||
ScrollPosition? oldPosition, | |||
) { | |||
return _DraggableScrollableSheetScrollPosition( | |||
physics: const AlwaysScrollableScrollPhysics().applyTo(physics), | |||
physics: physics.applyTo(const AlwaysScrollableScrollPhysics()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userSuppliedPhysics.applyTo(extraImplementationPhysics)
can fix DDS's issue simply : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
@@ -1439,7 +1439,8 @@ class _NestedScrollPosition extends ScrollPosition implements ScrollActivityDele | |||
} | |||
|
|||
void updateCanDrag(double totalExtent) { | |||
context.setCanDrag(totalExtent > (viewportDimension - maxScrollExtent) || minScrollExtent != maxScrollExtent); | |||
context.setCanDrag(physics.allowUserScrolling && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #113753
Here seems to be more suitable use physics.allowUserScrolling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience on this one. I really appreciate you taking a look at that other issue and including a full fix! LGTM!
auto label is removed for flutter/flutter, pr: 123109, due to - The status or check suite Mac customer_testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Thank you very much for fixing that! Could you please estimate when this fix is going to be officially released? |
…NeverScrollableScrollPhysics (flutter/flutter#123109)
…lableScrollPhysics (flutter#123109) DraggableScrollableSheet & NestedScrollView should respect NeverScrollableScrollPhysics
Fixes #121021
Fixes #113753
#121021 was introduce by #109081
Adding a
ScrollPhysics.allowUserScrolling
to indicate whether the physics allowed the user scrolling.