diff --git a/core/lib/presentation/views/text/text_field_builder.dart b/core/lib/presentation/views/text/text_field_builder.dart index dbbc70eed..fbff332b4 100644 --- a/core/lib/presentation/views/text/text_field_builder.dart +++ b/core/lib/presentation/views/text/text_field_builder.dart @@ -7,6 +7,7 @@ class TextFieldBuilder extends StatefulWidget { final ValueChanged? onTextChange; final ValueChanged? onTextSubmitted; final VoidCallback? onTap; + final TapRegionCallback? onTapOutside; final TextStyle? textStyle; final TextInputAction? textInputAction; final InputDecoration? decoration; @@ -45,6 +46,7 @@ class TextFieldBuilder extends StatefulWidget { this.keyboardAppearance, this.mouseCursor, this.onTap, + this.onTapOutside, this.onTextChange, this.onTextSubmitted, }); @@ -102,6 +104,7 @@ class _TextFieldBuilderState extends State { }, onSubmitted: widget.onTextSubmitted, onTap: widget.onTap, + onTapOutside: widget.onTapOutside, ); } diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index b0cf800b9..359060e5e 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -386,6 +386,26 @@ class ComposerController extends BaseController { ); } + void onTapOutsideSubject(PointerDownEvent event) { + subjectEmailInputFocusNode?.unfocus(); + } + + void onTapOutsideRecipients(PrefixEmailAddress prefix) { + switch(prefix) { + case PrefixEmailAddress.to: + toAddressFocusNode?.unfocus(); + break; + case PrefixEmailAddress.cc: + ccAddressFocusNode?.unfocus(); + break; + case PrefixEmailAddress.bcc: + bccAddressFocusNode?.unfocus(); + break; + default: + break; + } + } + void onLoadCompletedMobileEditorAction(HtmlEditorApi editorApi, WebUri? url) { if (identitySelected == null) { _getAllIdentities(); @@ -1836,18 +1856,8 @@ class ComposerController extends BaseController { } void _onEditorFocusOnMobile() { - if (Platform.isAndroid) { - _collapseAllRecipient(); - _autoCreateEmailTag(); - removeFocusAllInputEditorHeader(); - } - } - - void removeFocusAllInputEditorHeader() { - subjectEmailInputFocusNode?.unfocus(); - toAddressFocusNode?.unfocus(); - ccAddressFocusNode?.unfocus(); - bccAddressFocusNode?.unfocus(); + _collapseAllRecipient(); + _autoCreateEmailTag(); } void _onChangeCursorOnMobile(List? coordinates, BuildContext context) { diff --git a/lib/features/composer/presentation/composer_view.dart b/lib/features/composer/presentation/composer_view.dart index 82bd999d2..2ed4a9c94 100644 --- a/lib/features/composer/presentation/composer_view.dart +++ b/lib/features/composer/presentation/composer_view.dart @@ -118,6 +118,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.to), ), if (controller.ccRecipientState.value == PrefixRecipientState.enabled) RecipientComposerWidget( @@ -138,6 +139,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.cc), ), if (controller.bccRecipientState.value == PrefixRecipientState.enabled) RecipientComposerWidget( @@ -158,6 +160,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.bcc), ), ], )), @@ -167,6 +170,7 @@ class ComposerView extends GetWidget { onTextChange: controller.setSubjectEmail, padding: ComposerStyle.mobileSubjectPadding, margin: ComposerStyle.mobileSubjectMargin, + onTapOutside: controller.onTapOutsideSubject, ), Obx(() => Center( child: InsertImageLoadingBarWidget( @@ -175,18 +179,13 @@ class ComposerView extends GetWidget { padding: ComposerStyle.insertImageLoadingBarPadding, ), )), - Obx(() => GestureDetector( - onTapDown: (_) { - controller.removeFocusAllInputEditorHeader(); - }, - child: Padding( - padding: ComposerStyle.mobileEditorPadding, - child: MobileEditorView( - arguments: controller.composerArguments.value, - contentViewState: controller.emailContentsViewState.value, - onCreatedEditorAction: controller.onCreatedMobileEditorAction, - onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction, - ), + Obx(() => Padding( + padding: ComposerStyle.mobileEditorPadding, + child: MobileEditorView( + arguments: controller.composerArguments.value, + contentViewState: controller.emailContentsViewState.value, + onCreatedEditorAction: controller.onCreatedMobileEditorAction, + onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction, ), )), Obx(() { @@ -259,6 +258,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.to), ), if (controller.ccRecipientState.value == PrefixRecipientState.enabled) RecipientComposerWidget( @@ -279,6 +279,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.cc), ), if (controller.bccRecipientState.value == PrefixRecipientState.enabled) RecipientComposerWidget( @@ -299,6 +300,7 @@ class ComposerView extends GetWidget { onUpdateListEmailAddressAction: controller.updateListEmailAddress, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onFocusNextAddressAction: controller.handleFocusNextAddressAction, + onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.bcc), ), ], )), @@ -308,6 +310,7 @@ class ComposerView extends GetWidget { onTextChange: controller.setSubjectEmail, padding: ComposerStyle.mobileSubjectPadding, margin: ComposerStyle.mobileSubjectMargin, + onTapOutside: controller.onTapOutsideSubject, ), Obx(() => Center( child: InsertImageLoadingBarWidget( @@ -316,18 +319,13 @@ class ComposerView extends GetWidget { padding: ComposerStyle.insertImageLoadingBarPadding, ), )), - Obx(() => GestureDetector( - onTapDown: (_) { - controller.removeFocusAllInputEditorHeader(); - }, - child: Padding( - padding: ComposerStyle.mobileEditorPadding, - child: MobileEditorView( - arguments: controller.composerArguments.value, - contentViewState: controller.emailContentsViewState.value, - onCreatedEditorAction: controller.onCreatedMobileEditorAction, - onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction, - ), + Obx(() => Padding( + padding: ComposerStyle.mobileEditorPadding, + child: MobileEditorView( + arguments: controller.composerArguments.value, + contentViewState: controller.emailContentsViewState.value, + onCreatedEditorAction: controller.onCreatedMobileEditorAction, + onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction, ), )), Obx(() { diff --git a/lib/features/composer/presentation/widgets/recipient_composer_widget.dart b/lib/features/composer/presentation/widgets/recipient_composer_widget.dart index 958ea64f4..110dd3ac8 100644 --- a/lib/features/composer/presentation/widgets/recipient_composer_widget.dart +++ b/lib/features/composer/presentation/widgets/recipient_composer_widget.dart @@ -58,6 +58,7 @@ class RecipientComposerWidget extends StatefulWidget { final VoidCallback? onFocusNextAddressAction; final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? margin; + final TapRegionCallback? onTapOutside; const RecipientComposerWidget({ super.key, @@ -82,6 +83,7 @@ class RecipientComposerWidget extends StatefulWidget { this.onFocusEmailAddressChangeAction, this.onFocusNextAddressAction, this.onRemoveDraggableEmailAddressAction, + this.onTapOutside, }); @override @@ -180,6 +182,7 @@ class _RecipientComposerWidgetState extends State { onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter), onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter), onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter), + onTapOutside: widget.onTapOutside, inputDecoration: const InputDecoration(border: InputBorder.none), tagBuilder: (context, index) { final currentEmailAddress = _currentListEmailAddress[index]; @@ -253,6 +256,7 @@ class _RecipientComposerWidgetState extends State { onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter), onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter), onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter), + onTapOutside: widget.onTapOutside, inputDecoration: const InputDecoration(border: InputBorder.none), tagBuilder: (context, index) { final currentEmailAddress = _currentListEmailAddress[index]; diff --git a/lib/features/composer/presentation/widgets/subject_composer_widget.dart b/lib/features/composer/presentation/widgets/subject_composer_widget.dart index cfc4d8a7a..6e6a1bae4 100644 --- a/lib/features/composer/presentation/widgets/subject_composer_widget.dart +++ b/lib/features/composer/presentation/widgets/subject_composer_widget.dart @@ -11,6 +11,7 @@ class SubjectComposerWidget extends StatelessWidget { final ValueChanged? onTextChange; final EdgeInsetsGeometry? margin; final EdgeInsetsGeometry? padding; + final TapRegionCallback? onTapOutside; const SubjectComposerWidget({ super.key, @@ -19,6 +20,7 @@ class SubjectComposerWidget extends StatelessWidget { required this.onTextChange, this.margin, this.padding, + this.onTapOutside, }); @override @@ -50,6 +52,7 @@ class SubjectComposerWidget extends StatelessWidget { textDirection: DirectionUtils.getDirectionByLanguage(context), textStyle: SubjectComposerWidgetStyle.inputTextStyle, controller: textController, + onTapOutside: onTapOutside, ) ) ] diff --git a/pubspec.lock b/pubspec.lock index c0009c468..d7e6f2f04 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1553,7 +1553,7 @@ packages: description: path: "." ref: master - resolved-ref: "6e066b29659c6d3a2f20686219bb131164ab2e51" + resolved-ref: "7a78bff62891a6bfcad08106c2e9034a2c9661d8" url: "https://github.com/dab246/super_tag_editor.git" source: git version: "0.2.0"