feat: add scroll animtion on mobile (#1154)

This commit is contained in:
Lucas 2025-11-07 11:28:42 +08:00 • committed by GitHub
commit f125330265
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View file

@ -135,21 +135,34 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
final endTouchPoint = targetRect.centerRight;
if (PlatformExtension.isMobile) {
// Determine if this is a drag operation
final bool isDragOperation = dragMode != null &&
(dragMode.toString() ==
'MobileSelectionDragMode.leftSelectionHandle' ||
dragMode.toString() ==
'MobileSelectionDragMode.rightSelectionHandle');
// Use animation for drag operations, instant for others
final scrollDuration =
isDragOperation ? const Duration(milliseconds: 2) : Duration.zero;
// soft keyboard
// workaround: wait for the soft keyboard to show up
final duration = KeyboardHeightObserver.currentKeyboardHeight == 0
final keyboardDelay = KeyboardHeightObserver.currentKeyboardHeight == 0
? const Duration(milliseconds: 250)
: Duration.zero;
Future.delayed(duration, () {
Future.delayed(keyboardDelay, () {
if (_forwardKey.currentContext == null) {
return;
}
// Mobile needs to continuously update scroll position/direction during drag
// Don't skip even if already scrolling, because direction may have changed
startAutoScroll(
endTouchPoint,
edgeOffset: editorState.autoScrollEdgeOffset,
direction: direction,
duration: Duration.zero,
duration: scrollDuration,
);
});
} else {

View file

@ -636,9 +636,9 @@ class EditorState {
late AutoScroller scroller;
scroller = AutoScroller(
scrollableState,
velocityScalar: isDesktopOrWeb ? 0.15 : 0.02,
minimumAutoScrollDelta: isDesktopOrWeb ? 0.07 : 0.004,
maxAutoScrollDelta: isDesktopOrWeb ? 3.5 : 0.053,
velocityScalar: 0.15,
minimumAutoScrollDelta: 0.07,
maxAutoScrollDelta: 3.5,
animationDuration: Duration.zero,
onScrollViewScrolled: () {
_notifyScrollViewScrolledListeners();