Skip to content

Commit

Permalink
feat: support scroll without animation
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jul 25, 2023
1 parent 3e99f19 commit cce8745
Show file tree
Hide file tree
Showing 5 changed files with 545 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:appflowy_editor/src/flutter/scrollable_helpers.dart';
import 'package:flutter/material.dart' hide EdgeDraggingAutoScroller;

abstract class AutoScrollerService {
void startAutoScroll(
Offset offset, {
double edgeOffset = 200,
AxisDirection? direction,
Duration? duration,
});

void stopAutoScroll();
Expand All @@ -27,11 +29,13 @@ class AutoScroller extends EdgeDraggingAutoScroller
Offset offset, {
double edgeOffset = 200,
AxisDirection? direction,
Duration? duration,
}) {
if (direction != null) {
if (direction == AxisDirection.up) {
startAutoScrollIfNecessary(
offset & Size(1, edgeOffset),
duration: duration,
);
}
} else {
Expand All @@ -41,7 +45,10 @@ class AutoScroller extends EdgeDraggingAutoScroller
width: edgeOffset,
height: edgeOffset,
);
startAutoScrollIfNecessary(dragTarget);
startAutoScrollIfNecessary(
dragTarget,
duration: duration,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ class _DesktopScrollServiceState extends State<DesktopScrollService>
Offset offset, {
double edgeOffset = 200,
AxisDirection? direction,
Duration? duration,
}) {
widget.autoScroller.startAutoScroll(
offset,
edgeOffset: edgeOffset,
direction: direction,
duration: duration,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class _MobileScrollServiceState extends State<MobileScrollService>
Offset offset, {
double edgeOffset = 200,
AxisDirection? direction,
Duration? duration,
}) {
widget.autoScroller.startAutoScroll(
offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,23 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
startAutoScroll(endTouchPoint, edgeOffset: 50);
});
} else {
startAutoScroll(endTouchPoint, edgeOffset: 100);
if (editorState.selectionType == SelectionType.block) {
final box = editorState.renderBox;
final editorOffset = box?.localToGlobal(Offset.zero);
final editorHeight = box?.size.height;
double offset = 100;
if (editorOffset != null && editorHeight != null) {
// try to center the highlight area
offset = editorOffset.dy + editorHeight / 2.0;
}
startAutoScroll(
endTouchPoint,
edgeOffset: offset,
duration: Duration.zero,
);
} else {
startAutoScroll(endTouchPoint, edgeOffset: 100);
}
}
} else {
startAutoScroll(endTouchPoint);
Expand Down Expand Up @@ -159,11 +175,13 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
Offset offset, {
double edgeOffset = 100,
AxisDirection? direction,
Duration? duration,
}) =>
forward.startAutoScroll(
offset,
edgeOffset: edgeOffset,
direction: direction,
duration: duration,
);

@override
Expand Down
Loading

0 comments on commit cce8745

Please sign in to comment.