From faa22be83760fbd57c20395677c84eaa1fabe9a7 Mon Sep 17 00:00:00 2001 From: ManhNTX Date: Fri, 7 Oct 2022 06:47:02 +0700 Subject: [PATCH] TF-1033: replace hard code position by scrollController.position.pixels --- .../presentation/composer_controller.dart | 13 ++++---- .../identity_creator_controller.dart | 29 ++++++++++------- .../presentation/identity_creator_view.dart | 3 +- .../vacation/vacation_controller.dart | 31 ++++++++++++------- .../presentation/vacation/vacation_view.dart | 5 +-- pubspec.lock | 2 +- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 391c67ba5..d0b1bb718 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -1366,12 +1366,13 @@ class ComposerController extends BaseController { popBack(); } - void onEnterKeyDown() { - scrollController.animateTo( - keyboardRichTextController.currentLine * 20, - duration: const Duration(milliseconds: 300), - curve: Curves.linear, - ); + if(scrollController.position.pixels < scrollController.position.maxScrollExtent) { + scrollController.animateTo( + scrollController.position.pixels + 20, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + } } } \ No newline at end of file diff --git a/lib/features/identity_creator/presentation/identity_creator_controller.dart b/lib/features/identity_creator/presentation/identity_creator_controller.dart index 4c65ed197..dba255eaf 100644 --- a/lib/features/identity_creator/presentation/identity_creator_controller.dart +++ b/lib/features/identity_creator/presentation/identity_creator_controller.dart @@ -66,7 +66,7 @@ class IdentityCreatorController extends BaseController { String? _contentHtmlEditor; final ScrollController scrollController = ScrollController(); - double currentPositionYHTMLEditor = 250; + final GlobalKey htmlKey = GlobalKey(); void updateNameIdentity(BuildContext context, String? value) { _nameIdentity = value; @@ -405,19 +405,24 @@ class IdentityCreatorController extends BaseController { } } - void onFocusHTMLEditor() { - scrollController.animateTo( - currentPositionYHTMLEditor, - duration: const Duration(milliseconds: 300), - curve: Curves.linear, - ); + void onFocusHTMLEditor() async { + await Scrollable.ensureVisible(htmlKey.currentContext!); + await Future.delayed(const Duration(milliseconds: 500), () { + scrollController.animateTo( + scrollController.position.pixels + defaultKeyboardToolbarHeight, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + }); } void onEnterKeyDown() { - scrollController.animateTo( - currentPositionYHTMLEditor - keyboardRichTextController.currentLine * 20, - duration: const Duration(milliseconds: 300), - curve: Curves.linear, - ); + if(scrollController.position.pixels < scrollController.position.maxScrollExtent) { + scrollController.animateTo( + scrollController.position.pixels + 20, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + } } } \ No newline at end of file diff --git a/lib/features/identity_creator/presentation/identity_creator_view.dart b/lib/features/identity_creator/presentation/identity_creator_view.dart index 177531917..192ef7d2d 100644 --- a/lib/features/identity_creator/presentation/identity_creator_view.dart +++ b/lib/features/identity_creator/presentation/identity_creator_view.dart @@ -285,7 +285,6 @@ class IdentityCreatorView extends GetWidget { child: SingleChildScrollView( controller: controller.scrollController, physics: const ClampingScrollPhysics(), - reverse: true, child: Padding( padding: const EdgeInsets.all(24.0), child: Column(children: [ @@ -510,7 +509,7 @@ class IdentityCreatorView extends GetWidget { ); } else { return html_editor_mobile.HtmlEditor( - key:const Key('html_editor_mobile'), + key: controller.htmlKey, minHeight: 230, onCreated: (htmlEditorController) { controller.keyboardRichTextController.onCreateHTMLEditor( diff --git a/lib/features/manage_account/presentation/vacation/vacation_controller.dart b/lib/features/manage_account/presentation/vacation/vacation_controller.dart index 19682f089..d269b7c58 100644 --- a/lib/features/manage_account/presentation/vacation/vacation_controller.dart +++ b/lib/features/manage_account/presentation/vacation/vacation_controller.dart @@ -44,6 +44,9 @@ class VacationController extends BaseController { final messageTextController = TextEditingController(); final subjectTextController = TextEditingController(); final richTextControllerForMobile = RichTextController(); + final htmlEditorMinHeight = 150; + + final GlobalKey htmlKey = GlobalKey(); VacationResponse? currentVacation; String? _vacationMessageHtmlText; @@ -51,7 +54,6 @@ class VacationController extends BaseController { late Worker vacationWorker; final ScrollController scrollController = ScrollController(); - double currentPositionYHTMLEditor = 660; VacationController( this._getAllVacationInteractor, @@ -361,20 +363,25 @@ class VacationController extends BaseController { _settingController.backToUniversalSettings(); } - void onFocusHTMLEditor() { - scrollController.animateTo( - currentPositionYHTMLEditor, - duration: const Duration(milliseconds: 300), - curve: Curves.linear, - ); + void onFocusHTMLEditor() async { + await Scrollable.ensureVisible(htmlKey.currentContext!); + await Future.delayed(const Duration(milliseconds: 500), () { + scrollController.animateTo( + scrollController.position.pixels + defaultKeyboardToolbarHeight + htmlEditorMinHeight, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + }); } void onEnterKeyDown() { - scrollController.animateTo( - currentPositionYHTMLEditor + richTextControllerForMobile.currentLine * 20, - duration: const Duration(milliseconds: 300), - curve: Curves.linear, - ); + if(scrollController.position.pixels < scrollController.position.maxScrollExtent) { + scrollController.animateTo( + scrollController.position.pixels + 20, + duration: const Duration(milliseconds: 1), + curve: Curves.linear, + ); + } } @override diff --git a/lib/features/manage_account/presentation/vacation/vacation_view.dart b/lib/features/manage_account/presentation/vacation/vacation_view.dart index c2b2eb22c..81440f0d0 100644 --- a/lib/features/manage_account/presentation/vacation/vacation_view.dart +++ b/lib/features/manage_account/presentation/vacation/vacation_view.dart @@ -61,6 +61,7 @@ class VacationView extends GetWidget with RichTextButtonMixi : null, padding: SettingsUtils.getMarginViewForSettingDetails(context, _responsiveUtils), child: SingleChildScrollView( + physics: const ClampingScrollPhysics(), controller: controller.scrollController, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -469,8 +470,8 @@ class VacationView extends GetWidget with RichTextButtonMixi ); } else { return html_editor_mobile.HtmlEditor( - key: const Key('vacation_message_html_text_editor_mobile'), - minHeight: 150, + key: controller.htmlKey, + minHeight: controller.htmlEditorMinHeight, addDefaultSelectionMenuItems: false, initialContent: controller.vacationMessageHtmlText ?? '', onCreated: (htmlApi) { diff --git a/pubspec.lock b/pubspec.lock index a6595c728..609b1eac7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1012,7 +1012,7 @@ packages: name: permission_handler_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "3.8.0" + version: "3.9.0" permission_handler_windows: dependency: transitive description: