From b636422d37be9f0a2f566d47b0bc3e50a2c34fe1 Mon Sep 17 00:00:00 2001 From: DatDang Date: Tue, 26 Mar 2024 15:42:30 +0700 Subject: [PATCH] TF-2671 Fix scroll jumping when typing on composer (cherry picked from commit 2ab217d8b6193f61dfde0451ed49486cf51d664b) --- .../composer/presentation/composer_controller.dart | 11 +++++++---- lib/features/composer/presentation/composer_view.dart | 2 +- .../composer/presentation/styles/composer_style.dart | 1 - pubspec.lock | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 30b9f6fb7..44fb52d8e 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -1651,7 +1651,7 @@ class ComposerController extends BaseController with DragDropFileMixin { if (coordinates?[1] != null && coordinates?[1] != 0) { final coordinateY = max((coordinates?[1] ?? 0) - defaultPaddingCoordinateYCursorEditor, 0); final realCoordinateY = coordinateY + (headerEditorMobileSize?.height ?? 0); - final outsideHeight = Get.height - ComposerStyle.keyboardMaxHeight - ComposerStyle.keyboardToolBarHeight; + final outsideHeight = Get.height - MediaQuery.viewInsetsOf(context).bottom - ComposerStyle.keyboardToolBarHeight; final webViewEditorClientY = max(outsideHeight, 0) + scrollController.position.pixels; if (scrollController.position.pixels >= realCoordinateY) { _scrollToCursorEditor( @@ -1675,9 +1675,12 @@ class ComposerController extends BaseController with DragDropFileMixin { double headerEditorMobileHeight, BuildContext context, ) { - scrollController.jumpTo( - realCoordinateY - (responsiveUtils.isLandscapeMobile(context) ? 0 : headerEditorMobileHeight / 2), - ); + final scrollTarget = realCoordinateY - + (responsiveUtils.isLandscapeMobile(context) + ? 0 + : headerEditorMobileHeight / 2); + final maxScrollExtend = scrollController.position.maxScrollExtent; + scrollController.jumpTo(min(scrollTarget, maxScrollExtend)); } void _onEnterKeyDown() { diff --git a/lib/features/composer/presentation/composer_view.dart b/lib/features/composer/presentation/composer_view.dart index 765f9c5f0..064acd3b3 100644 --- a/lib/features/composer/presentation/composer_view.dart +++ b/lib/features/composer/presentation/composer_view.dart @@ -217,7 +217,7 @@ class ComposerView extends GetWidget { onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction, ), )), - const SizedBox(height: ComposerStyle.keyboardMaxHeight), + SizedBox(height: MediaQuery.viewInsetsOf(context).bottom), ], ), ), diff --git a/lib/features/composer/presentation/styles/composer_style.dart b/lib/features/composer/presentation/styles/composer_style.dart index d88eca6c8..ca246c3c0 100644 --- a/lib/features/composer/presentation/styles/composer_style.dart +++ b/lib/features/composer/presentation/styles/composer_style.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; class ComposerStyle { static const double radius = 28; - static const double keyboardMaxHeight = 500; static const double keyboardToolBarHeight = 200; static const double popupMenuRadius = 8; diff --git a/pubspec.lock b/pubspec.lock index 0850dc19e..bce43d73a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -429,7 +429,7 @@ packages: description: path: "." ref: cnb_supported - resolved-ref: "669cfd989498cf398c88a6618eebb089967b9e28" + resolved-ref: "69996e32a708a62b8a613f2524c5635f5c556617" url: "https://github.com/linagora/enough_html_editor.git" source: git version: "0.0.5"