TF-2191 Fix keyboard disappear when switch focus from subject to body in composer android

(cherry picked from commit 880c7f1ae9e96c5b3dedaca01bf3736e7dd869d4)
This commit is contained in:
dab246
2023-10-10 15:14:00 +07:00
committed by Dat H. Pham
parent f7ff075f82
commit 6095959181
6 changed files with 55 additions and 37 deletions
@@ -7,6 +7,7 @@ class TextFieldBuilder extends StatefulWidget {
final ValueChanged<String>? onTextChange; final ValueChanged<String>? onTextChange;
final ValueChanged<String>? onTextSubmitted; final ValueChanged<String>? onTextSubmitted;
final VoidCallback? onTap; final VoidCallback? onTap;
final TapRegionCallback? onTapOutside;
final TextStyle? textStyle; final TextStyle? textStyle;
final TextInputAction? textInputAction; final TextInputAction? textInputAction;
final InputDecoration? decoration; final InputDecoration? decoration;
@@ -45,6 +46,7 @@ class TextFieldBuilder extends StatefulWidget {
this.keyboardAppearance, this.keyboardAppearance,
this.mouseCursor, this.mouseCursor,
this.onTap, this.onTap,
this.onTapOutside,
this.onTextChange, this.onTextChange,
this.onTextSubmitted, this.onTextSubmitted,
}); });
@@ -102,6 +104,7 @@ class _TextFieldBuilderState extends State<TextFieldBuilder> {
}, },
onSubmitted: widget.onTextSubmitted, onSubmitted: widget.onTextSubmitted,
onTap: widget.onTap, onTap: widget.onTap,
onTapOutside: widget.onTapOutside,
); );
} }
@@ -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) { void onLoadCompletedMobileEditorAction(HtmlEditorApi editorApi, WebUri? url) {
if (identitySelected == null) { if (identitySelected == null) {
_getAllIdentities(); _getAllIdentities();
@@ -1836,18 +1856,8 @@ class ComposerController extends BaseController {
} }
void _onEditorFocusOnMobile() { void _onEditorFocusOnMobile() {
if (Platform.isAndroid) { _collapseAllRecipient();
_collapseAllRecipient(); _autoCreateEmailTag();
_autoCreateEmailTag();
removeFocusAllInputEditorHeader();
}
}
void removeFocusAllInputEditorHeader() {
subjectEmailInputFocusNode?.unfocus();
toAddressFocusNode?.unfocus();
ccAddressFocusNode?.unfocus();
bccAddressFocusNode?.unfocus();
} }
void _onChangeCursorOnMobile(List<int>? coordinates, BuildContext context) { void _onChangeCursorOnMobile(List<int>? coordinates, BuildContext context) {
@@ -118,6 +118,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.to),
), ),
if (controller.ccRecipientState.value == PrefixRecipientState.enabled) if (controller.ccRecipientState.value == PrefixRecipientState.enabled)
RecipientComposerWidget( RecipientComposerWidget(
@@ -138,6 +139,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.cc),
), ),
if (controller.bccRecipientState.value == PrefixRecipientState.enabled) if (controller.bccRecipientState.value == PrefixRecipientState.enabled)
RecipientComposerWidget( RecipientComposerWidget(
@@ -158,6 +160,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.bcc),
), ),
], ],
)), )),
@@ -167,6 +170,7 @@ class ComposerView extends GetWidget<ComposerController> {
onTextChange: controller.setSubjectEmail, onTextChange: controller.setSubjectEmail,
padding: ComposerStyle.mobileSubjectPadding, padding: ComposerStyle.mobileSubjectPadding,
margin: ComposerStyle.mobileSubjectMargin, margin: ComposerStyle.mobileSubjectMargin,
onTapOutside: controller.onTapOutsideSubject,
), ),
Obx(() => Center( Obx(() => Center(
child: InsertImageLoadingBarWidget( child: InsertImageLoadingBarWidget(
@@ -175,18 +179,13 @@ class ComposerView extends GetWidget<ComposerController> {
padding: ComposerStyle.insertImageLoadingBarPadding, padding: ComposerStyle.insertImageLoadingBarPadding,
), ),
)), )),
Obx(() => GestureDetector( Obx(() => Padding(
onTapDown: (_) { padding: ComposerStyle.mobileEditorPadding,
controller.removeFocusAllInputEditorHeader(); child: MobileEditorView(
}, arguments: controller.composerArguments.value,
child: Padding( contentViewState: controller.emailContentsViewState.value,
padding: ComposerStyle.mobileEditorPadding, onCreatedEditorAction: controller.onCreatedMobileEditorAction,
child: MobileEditorView( onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction,
arguments: controller.composerArguments.value,
contentViewState: controller.emailContentsViewState.value,
onCreatedEditorAction: controller.onCreatedMobileEditorAction,
onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction,
),
), ),
)), )),
Obx(() { Obx(() {
@@ -259,6 +258,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.to),
), ),
if (controller.ccRecipientState.value == PrefixRecipientState.enabled) if (controller.ccRecipientState.value == PrefixRecipientState.enabled)
RecipientComposerWidget( RecipientComposerWidget(
@@ -279,6 +279,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.cc),
), ),
if (controller.bccRecipientState.value == PrefixRecipientState.enabled) if (controller.bccRecipientState.value == PrefixRecipientState.enabled)
RecipientComposerWidget( RecipientComposerWidget(
@@ -299,6 +300,7 @@ class ComposerView extends GetWidget<ComposerController> {
onUpdateListEmailAddressAction: controller.updateListEmailAddress, onUpdateListEmailAddressAction: controller.updateListEmailAddress,
onSuggestionEmailAddress: controller.getAutoCompleteSuggestion, onSuggestionEmailAddress: controller.getAutoCompleteSuggestion,
onFocusNextAddressAction: controller.handleFocusNextAddressAction, onFocusNextAddressAction: controller.handleFocusNextAddressAction,
onTapOutside: (_) => controller.onTapOutsideRecipients(PrefixEmailAddress.bcc),
), ),
], ],
)), )),
@@ -308,6 +310,7 @@ class ComposerView extends GetWidget<ComposerController> {
onTextChange: controller.setSubjectEmail, onTextChange: controller.setSubjectEmail,
padding: ComposerStyle.mobileSubjectPadding, padding: ComposerStyle.mobileSubjectPadding,
margin: ComposerStyle.mobileSubjectMargin, margin: ComposerStyle.mobileSubjectMargin,
onTapOutside: controller.onTapOutsideSubject,
), ),
Obx(() => Center( Obx(() => Center(
child: InsertImageLoadingBarWidget( child: InsertImageLoadingBarWidget(
@@ -316,18 +319,13 @@ class ComposerView extends GetWidget<ComposerController> {
padding: ComposerStyle.insertImageLoadingBarPadding, padding: ComposerStyle.insertImageLoadingBarPadding,
), ),
)), )),
Obx(() => GestureDetector( Obx(() => Padding(
onTapDown: (_) { padding: ComposerStyle.mobileEditorPadding,
controller.removeFocusAllInputEditorHeader(); child: MobileEditorView(
}, arguments: controller.composerArguments.value,
child: Padding( contentViewState: controller.emailContentsViewState.value,
padding: ComposerStyle.mobileEditorPadding, onCreatedEditorAction: controller.onCreatedMobileEditorAction,
child: MobileEditorView( onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction,
arguments: controller.composerArguments.value,
contentViewState: controller.emailContentsViewState.value,
onCreatedEditorAction: controller.onCreatedMobileEditorAction,
onLoadCompletedEditorAction: controller.onLoadCompletedMobileEditorAction,
),
), ),
)), )),
Obx(() { Obx(() {
@@ -58,6 +58,7 @@ class RecipientComposerWidget extends StatefulWidget {
final VoidCallback? onFocusNextAddressAction; final VoidCallback? onFocusNextAddressAction;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry? margin; final EdgeInsetsGeometry? margin;
final TapRegionCallback? onTapOutside;
const RecipientComposerWidget({ const RecipientComposerWidget({
super.key, super.key,
@@ -82,6 +83,7 @@ class RecipientComposerWidget extends StatefulWidget {
this.onFocusEmailAddressChangeAction, this.onFocusEmailAddressChangeAction,
this.onFocusNextAddressAction, this.onFocusNextAddressAction,
this.onRemoveDraggableEmailAddressAction, this.onRemoveDraggableEmailAddressAction,
this.onTapOutside,
}); });
@override @override
@@ -180,6 +182,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter), onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter),
onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter), onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter),
onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter), onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter),
onTapOutside: widget.onTapOutside,
inputDecoration: const InputDecoration(border: InputBorder.none), inputDecoration: const InputDecoration(border: InputBorder.none),
tagBuilder: (context, index) { tagBuilder: (context, index) {
final currentEmailAddress = _currentListEmailAddress[index]; final currentEmailAddress = _currentListEmailAddress[index];
@@ -253,6 +256,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter), onDeleteTagAction: () => _handleDeleteLatestTagAction.call(stateSetter),
onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter), onSelectOptionAction: (item) => _handleSelectOptionAction.call(item, stateSetter),
onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter), onSubmitted: (value) => _handleSubmitTagAction.call(value, stateSetter),
onTapOutside: widget.onTapOutside,
inputDecoration: const InputDecoration(border: InputBorder.none), inputDecoration: const InputDecoration(border: InputBorder.none),
tagBuilder: (context, index) { tagBuilder: (context, index) {
final currentEmailAddress = _currentListEmailAddress[index]; final currentEmailAddress = _currentListEmailAddress[index];
@@ -11,6 +11,7 @@ class SubjectComposerWidget extends StatelessWidget {
final ValueChanged<String>? onTextChange; final ValueChanged<String>? onTextChange;
final EdgeInsetsGeometry? margin; final EdgeInsetsGeometry? margin;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
final TapRegionCallback? onTapOutside;
const SubjectComposerWidget({ const SubjectComposerWidget({
super.key, super.key,
@@ -19,6 +20,7 @@ class SubjectComposerWidget extends StatelessWidget {
required this.onTextChange, required this.onTextChange,
this.margin, this.margin,
this.padding, this.padding,
this.onTapOutside,
}); });
@override @override
@@ -50,6 +52,7 @@ class SubjectComposerWidget extends StatelessWidget {
textDirection: DirectionUtils.getDirectionByLanguage(context), textDirection: DirectionUtils.getDirectionByLanguage(context),
textStyle: SubjectComposerWidgetStyle.inputTextStyle, textStyle: SubjectComposerWidgetStyle.inputTextStyle,
controller: textController, controller: textController,
onTapOutside: onTapOutside,
) )
) )
] ]
+1 -1
View File
@@ -1553,7 +1553,7 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: "6e066b29659c6d3a2f20686219bb131164ab2e51" resolved-ref: "7a78bff62891a6bfcad08106c2e9034a2c9661d8"
url: "https://github.com/dab246/super_tag_editor.git" url: "https://github.com/dab246/super_tag_editor.git"
source: git source: git
version: "0.2.0" version: "0.2.0"