feat: add scroll animtion on mobile (#1154)
This commit is contained in:
parent
5c4a6f904c
commit
f125330265
2 changed files with 19 additions and 6 deletions
|
|
@ -135,21 +135,34 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
|
||||||
final endTouchPoint = targetRect.centerRight;
|
final endTouchPoint = targetRect.centerRight;
|
||||||
|
|
||||||
if (PlatformExtension.isMobile) {
|
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
|
// soft keyboard
|
||||||
// workaround: wait for the soft keyboard to show up
|
// workaround: wait for the soft keyboard to show up
|
||||||
final duration = KeyboardHeightObserver.currentKeyboardHeight == 0
|
final keyboardDelay = KeyboardHeightObserver.currentKeyboardHeight == 0
|
||||||
? const Duration(milliseconds: 250)
|
? const Duration(milliseconds: 250)
|
||||||
: Duration.zero;
|
: Duration.zero;
|
||||||
|
|
||||||
Future.delayed(duration, () {
|
Future.delayed(keyboardDelay, () {
|
||||||
if (_forwardKey.currentContext == null) {
|
if (_forwardKey.currentContext == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Mobile needs to continuously update scroll position/direction during drag
|
||||||
|
// Don't skip even if already scrolling, because direction may have changed
|
||||||
startAutoScroll(
|
startAutoScroll(
|
||||||
endTouchPoint,
|
endTouchPoint,
|
||||||
edgeOffset: editorState.autoScrollEdgeOffset,
|
edgeOffset: editorState.autoScrollEdgeOffset,
|
||||||
direction: direction,
|
direction: direction,
|
||||||
duration: Duration.zero,
|
duration: scrollDuration,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -636,9 +636,9 @@ class EditorState {
|
||||||
late AutoScroller scroller;
|
late AutoScroller scroller;
|
||||||
scroller = AutoScroller(
|
scroller = AutoScroller(
|
||||||
scrollableState,
|
scrollableState,
|
||||||
velocityScalar: isDesktopOrWeb ? 0.15 : 0.02,
|
velocityScalar: 0.15,
|
||||||
minimumAutoScrollDelta: isDesktopOrWeb ? 0.07 : 0.004,
|
minimumAutoScrollDelta: 0.07,
|
||||||
maxAutoScrollDelta: isDesktopOrWeb ? 3.5 : 0.053,
|
maxAutoScrollDelta: 3.5,
|
||||||
animationDuration: Duration.zero,
|
animationDuration: Duration.zero,
|
||||||
onScrollViewScrolled: () {
|
onScrollViewScrolled: () {
|
||||||
_notifyScrollViewScrolledListeners();
|
_notifyScrollViewScrolledListeners();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue