Skip to content

Commit f125330

Browse files
authored
feat: add scroll animtion on mobile (#1154)
1 parent 5c4a6f9 commit f125330

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/src/editor/editor_component/service/scroll_service_widget.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,34 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
135135
final endTouchPoint = targetRect.centerRight;
136136

137137
if (PlatformExtension.isMobile) {
138+
// Determine if this is a drag operation
139+
final bool isDragOperation = dragMode != null &&
140+
(dragMode.toString() ==
141+
'MobileSelectionDragMode.leftSelectionHandle' ||
142+
dragMode.toString() ==
143+
'MobileSelectionDragMode.rightSelectionHandle');
144+
145+
// Use animation for drag operations, instant for others
146+
final scrollDuration =
147+
isDragOperation ? const Duration(milliseconds: 2) : Duration.zero;
148+
138149
// soft keyboard
139150
// workaround: wait for the soft keyboard to show up
140-
final duration = KeyboardHeightObserver.currentKeyboardHeight == 0
151+
final keyboardDelay = KeyboardHeightObserver.currentKeyboardHeight == 0
141152
? const Duration(milliseconds: 250)
142153
: Duration.zero;
143154

144-
Future.delayed(duration, () {
155+
Future.delayed(keyboardDelay, () {
145156
if (_forwardKey.currentContext == null) {
146157
return;
147158
}
159+
// Mobile needs to continuously update scroll position/direction during drag
160+
// Don't skip even if already scrolling, because direction may have changed
148161
startAutoScroll(
149162
endTouchPoint,
150163
edgeOffset: editorState.autoScrollEdgeOffset,
151164
direction: direction,
152-
duration: Duration.zero,
165+
duration: scrollDuration,
153166
);
154167
});
155168
} else {

lib/src/editor_state.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ class EditorState {
636636
late AutoScroller scroller;
637637
scroller = AutoScroller(
638638
scrollableState,
639-
velocityScalar: isDesktopOrWeb ? 0.15 : 0.02,
640-
minimumAutoScrollDelta: isDesktopOrWeb ? 0.07 : 0.004,
641-
maxAutoScrollDelta: isDesktopOrWeb ? 3.5 : 0.053,
639+
velocityScalar: 0.15,
640+
minimumAutoScrollDelta: 0.07,
641+
maxAutoScrollDelta: 3.5,
642642
animationDuration: Duration.zero,
643643
onScrollViewScrolled: () {
644644
_notifyScrollViewScrolledListeners();

0 commit comments

Comments
 (0)