Skip to content

Commit

Permalink
Remove notification dispatch logic from beginActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed Jul 21, 2024
1 parent f920746 commit 3dc78b9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
75 changes: 31 additions & 44 deletions package/lib/src/foundation/sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:meta/meta.dart';

import '../internal/double_utils.dart';
import 'sheet_activity.dart';
import 'sheet_controller.dart';
import 'sheet_drag.dart';
import 'sheet_extent_scope.dart';
import 'sheet_gesture_tamperer.dart';
Expand Down Expand Up @@ -384,24 +383,20 @@ abstract class SheetExtent extends ChangeNotifier
final isDragging = activity.status == SheetStatus.dragging;

// TODO: Make more typesafe
switch ((wasDragging, isDragging)) {
case (true, true):
assert(currentDrag != null);
assert(activity is SheetDragControllerTarget);
currentDrag!.updateTarget(activity as SheetDragControllerTarget);

case (true, false):
assert(currentDrag != null);
dispatchDragEndNotification();
currentDrag!.dispose();
currentDrag = null;

case (false, true):
assert(currentDrag != null);
dispatchDragStartNotification();

case (false, false):
assert(currentDrag == null);
assert(() {
final wasActuallyDragging =
currentDrag != null && oldActivity is SheetDragControllerTarget;
final isActuallyDragging =
currentDrag != null && activity is SheetDragControllerTarget;
return wasDragging == wasActuallyDragging &&
isDragging == isActuallyDragging;
}());

if (wasDragging && isDragging) {
currentDrag!.updateTarget(activity as SheetDragControllerTarget);
} else if (wasDragging && !isDragging) {
currentDrag!.dispose();
currentDrag = null;
}

oldActivity.dispose();
Expand Down Expand Up @@ -436,10 +431,7 @@ abstract class SheetExtent extends ChangeNotifier
}
}

Drag drag(
DragStartDetails details,
VoidCallback dragCancelCallback,
) {
Drag drag(DragStartDetails details, VoidCallback dragCancelCallback) {
assert(currentDrag == null);
final dragActivity = DragSheetActivity();
var startDetails = SheetDragStartDetails(
Expand All @@ -465,6 +457,7 @@ abstract class SheetExtent extends ChangeNotifier
motionStartDistanceThreshold: physics.dragStartDistanceMotionThreshold,
);
beginActivity(dragActivity);
dispatchDragStartNotification(details: startDetails);
return drag;
}

Expand All @@ -482,11 +475,6 @@ abstract class SheetExtent extends ChangeNotifier
correctPixels(pixels);
if (oldPixels != pixels) {
notifyListeners();
if (currentDrag?.lastDetails is SheetDragUpdateDetails) {
dispatchDragUpdateNotification();
} else {
dispatchUpdateNotification();
}
}
}

Expand Down Expand Up @@ -532,46 +520,45 @@ abstract class SheetExtent extends ChangeNotifier
}
}

void dispatchDragStartNotification() {
void dispatchDragStartNotification({
required SheetDragStartDetails details,
}) {
assert(metrics.hasDimensions);
assert(currentDrag != null);
final details = currentDrag!.lastDetails;
assert(details is SheetDragStartDetails);
_dispatchNotification(
SheetDragStartNotification(
metrics: metrics,
dragDetails: details as SheetDragStartDetails,
dragDetails: details,
),
);
}

void dispatchDragEndNotification() {
void dispatchDragEndNotification({
required SheetDragEndDetails details,
}) {
assert(metrics.hasDimensions);
assert(currentDrag != null);
final details = currentDrag!.lastDetails;
assert(details is SheetDragEndDetails);
_dispatchNotification(
SheetDragEndNotification(
metrics: metrics,
dragDetails: details as SheetDragEndDetails,
dragDetails: details,
),
);
}

void dispatchDragUpdateNotification() {
void dispatchDragUpdateNotification({
required SheetDragUpdateDetails details,
}) {
assert(metrics.hasDimensions);
assert(currentDrag != null);
final details = currentDrag!.lastDetails;
assert(details is SheetDragUpdateDetails);
_dispatchNotification(
SheetDragUpdateNotification(
metrics: metrics,
dragDetails: details as SheetDragUpdateDetails,
dragDetails: details,
),
);
}

void dispatchOverflowNotification(double overflow) {
void dispatchOverflowNotification({
required double overflow,
}) {
assert(metrics.hasDimensions);
_dispatchNotification(
SheetOverflowNotification(
Expand Down
25 changes: 17 additions & 8 deletions package/lib/src/navigation/navigation_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

import '../foundation/sheet_drag.dart';
import '../foundation/sheet_extent.dart';
import '../internal/transition_observer.dart';
import 'navigation_route.dart';
Expand Down Expand Up @@ -110,34 +111,42 @@ class NavigationSheetExtent extends SheetExtent {
}

@override
void dispatchDragStartNotification() {
void dispatchDragStartNotification({
required SheetDragStartDetails details,
}) {
// Do not dispatch a notifications if a local extent is active.
if (activity is! NavigationSheetActivity) {
super.dispatchDragStartNotification();
super.dispatchDragStartNotification(details: details);
}
}

@override
void dispatchDragEndNotification() {
void dispatchDragEndNotification({
required SheetDragEndDetails details,
}) {
// Do not dispatch a notifications if a local extent is active.
if (activity is! NavigationSheetActivity) {
super.dispatchDragEndNotification();
super.dispatchDragEndNotification(details: details);
}
}

@override
void dispatchDragUpdateNotification() {
void dispatchDragUpdateNotification({
required SheetDragUpdateDetails details,
}) {
// Do not dispatch a notifications if a local extent is active.
if (activity is! NavigationSheetActivity) {
super.dispatchDragUpdateNotification();
super.dispatchDragUpdateNotification(details: details);
}
}

@override
void dispatchOverflowNotification(double overflow) {
void dispatchOverflowNotification({
required double overflow,
}) {
// Do not dispatch a notifications if a local extent is active.
if (activity is! NavigationSheetActivity) {
super.dispatchOverflowNotification(overflow);
super.dispatchOverflowNotification(overflow: overflow);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package/lib/src/scrollable/scrollable_sheet_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ abstract class ScrollableSheetActivity
final overflow = owner.physics.computeOverflow(delta, owner.metrics);
if (overflow.abs() > 0) {
position.didOverscrollBy(overflow);
owner.dispatchOverflowNotification(overflow);
owner.dispatchOverflowNotification(overflow: overflow);
return overflow;
}

Expand Down
1 change: 1 addition & 0 deletions package/lib/src/scrollable/scrollable_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ScrollableSheetExtent extends SheetExtent
),
);
beginActivity(dragActivity);
dispatchDragStartNotification(details: startDetails);
return drag;
}

Expand Down

0 comments on commit 3dc78b9

Please sign in to comment.