feat: add scroll animtion on mobile (#1154)
This commit is contained in:
parent
5c4a6f904c
commit
f125330265
1 changed files with 19 additions and 6 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue