Skip to content

Commit

Permalink
Use shouldIgnorePointer of scroll position
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed Jul 21, 2024
1 parent ab1894b commit 00539af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions package/lib/src/scrollable/scrollable_sheet_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import 'scrollable_sheet_extent.dart';
import 'sheet_content_scroll_activity.dart';
import 'sheet_content_scroll_position.dart';

/// A [SheetActivity] that is associated with a [SheetContentScrollPosition].
///
/// This activity is responsible for both scrolling a scrollable content
/// in the sheet and dragging the sheet itself.
///
/// [shouldIgnorePointer] and [SheetContentScrollPosition.shouldIgnorePointer]
/// of the associated scroll position may be synchronized, but not always.
/// For example, [BallisticScrollDrivenSheetActivity]'s [shouldIgnorePointer]
/// is always `false` while the associated scroll position sets it to `true`
/// in most cases to ensure that the pointer events, which potentially
/// interrupt the ballistic scroll animation, are not stolen by clickable
/// items in the scroll view.
@internal
abstract class ScrollableSheetActivity
extends SheetActivity<ScrollableSheetExtent> {
Expand Down Expand Up @@ -196,7 +208,6 @@ class DragScrollDrivenSheetActivity extends ScrollableSheetActivity
..didDragEnd(details)
..goBallisticWithScrollPosition(
velocity: -1 * details.velocityY,
shouldIgnorePointer: false,
scrollPosition: scrollPosition,
);
}
Expand All @@ -215,14 +226,10 @@ class BallisticScrollDrivenSheetActivity extends ScrollableSheetActivity
super.scrollPosition, {
required this.simulation,
required double initialPixels,
required this.shouldIgnorePointer,
}) : _oldPixels = initialPixels;

final Simulation simulation;

@override
final bool shouldIgnorePointer;

double _oldPixels;

@override
Expand Down Expand Up @@ -271,7 +278,6 @@ class BallisticScrollDrivenSheetActivity extends ScrollableSheetActivity
void _end() {
owner.goBallisticWithScrollPosition(
velocity: 0,
shouldIgnorePointer: shouldIgnorePointer,
scrollPosition: scrollPosition,
);
}
Expand Down
4 changes: 1 addition & 3 deletions package/lib/src/scrollable/scrollable_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class ScrollableSheetExtent extends SheetExtent
@override
void goBallisticWithScrollPosition({
required double velocity,
required bool shouldIgnorePointer,
required SheetContentScrollPosition scrollPosition,
}) {
assert(metrics.hasDimensions);
Expand Down Expand Up @@ -196,13 +195,12 @@ class ScrollableSheetExtent extends SheetExtent
scrollPosition,
simulation: scrollSimulation,
initialPixels: scrollPixelsForScrollPhysics,
shouldIgnorePointer: shouldIgnorePointer,
),
);
scrollPosition.beginActivity(
SheetContentBallisticScrollActivity(
delegate: scrollPosition,
shouldIgnorePointer: shouldIgnorePointer,
shouldIgnorePointer: scrollPosition.shouldIgnorePointer,
getVelocity: () => activity.velocity,
),
);
Expand Down
6 changes: 4 additions & 2 deletions package/lib/src/scrollable/sheet_content_scroll_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ abstract class SheetContentScrollPositionOwner {

void goBallisticWithScrollPosition({
required double velocity,
required bool shouldIgnorePointer,
required SheetContentScrollPosition scrollPosition,
});
}
Expand Down Expand Up @@ -69,6 +68,10 @@ class SheetContentScrollPosition extends ScrollPositionWithSingleContext {
double _heldPreviousVelocity = 0.0;
double get heldPreviousVelocity => _heldPreviousVelocity;

/// Whether the scroll view should prevent its contents from receiving
/// pointer events.
bool get shouldIgnorePointer => activity!.shouldIgnorePointer;

/// Sets the user scroll direction.
///
/// This exists only to expose `updateUserScrollDirection`
Expand Down Expand Up @@ -123,7 +126,6 @@ class SheetContentScrollPosition extends ScrollPositionWithSingleContext {
if (owner != null && owner.hasPrimaryScrollPosition && !calledByOwner) {
owner.goBallisticWithScrollPosition(
velocity: velocity,
shouldIgnorePointer: activity?.shouldIgnorePointer ?? true,
scrollPosition: this,
);
return;
Expand Down

0 comments on commit 00539af

Please sign in to comment.