unfocus textfield when outside tap on mobile

This commit is contained in:
Henry Hiles 2026-11-23 14:23:00 -05:00
commit 720e538dbc
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
2 changed files with 501 additions and 473 deletions

View file

@ -477,7 +477,8 @@ class const Composer(
fontWeight: .bold,
);
return Padding(
return TextFieldTapRegion(
child: Padding(
padding: .all(12),
child: Column(
children: [
@ -569,7 +570,11 @@ class const Composer(
(context) => EmojiPicker(
roomId: roomId,
onSelection:
(value, {shortcode, description}) {
(
value, {
shortcode,
description,
}) {
Navigator.of(context).pop();
if (shortcode == null) {
controller.text += value;
@ -622,7 +627,9 @@ class const Composer(
onTap: () => attach(
source == .gallery
? ref
.read(FileDialogHelper.provider)
.read(
FileDialogHelper.provider,
)
.pickFile(images: true)
: ref
.read(
@ -692,8 +699,9 @@ class const Composer(
onPick: (picked) {
Navigator.of(context).pop();
draftNotifier.update(
(draft) =>
draft.copyWith(location: picked),
(draft) => draft.copyWith(
location: picked,
),
);
},
),
@ -722,7 +730,8 @@ class const Composer(
removeTooltip: "Remove poll",
onRemove: () {
draftNotifier.update(
(draft) => draft.copyWith(poll: null),
(draft) =>
draft.copyWith(poll: null),
);
node?.requestFocus();
},
@ -742,7 +751,12 @@ class const Composer(
),
),
),
((final shortcode, final image)?, _, _, _) =>
(
(final shortcode, final image)?,
_,
_,
_,
) =>
ComposerReplacement(
removeTooltip: "Remove sticker",
onRemove: () {
@ -829,7 +843,8 @@ class const Composer(
overlay: TaggerOverlay(
query.value,
roomId: roomId,
triggerCharacter: triggerCharacter.value,
triggerCharacter:
triggerCharacter.value,
addTag: ({required id, required name}) {
controller.addTag(id: id, name: name);
node?.requestFocus();
@ -842,7 +857,9 @@ class const Composer(
..value = controller.value.replaced(
.new(
start:
end - query.value.length - 1,
end -
query.value.length -
1,
end: end,
),
"$text ",
@ -851,7 +868,8 @@ class const Composer(
},
),
controller: controller,
onSearch: (newQuery, newTriggerCharacter) {
onSearch:
(newQuery, newTriggerCharacter) {
triggerCharacter.value =
newTriggerCharacter;
query.value = newQuery;
@ -881,14 +899,17 @@ class const Composer(
materialTapTargetSize:
.shrinkWrap,
onDeleted: () =>
removeTextCommand(command),
removeTextCommand(
command,
),
),
),
Expanded(
child: TextField(
maxLines: 12,
minLines: 1,
textCapitalization: .sentences,
textCapitalization:
.sentences,
onChanged: pickTypedCommand,
autofocus:
(Platform.isLinux ||
@ -902,6 +923,9 @@ class const Composer(
controller: controller,
key: key,
focusNode: node,
// Touch taps outside don't unfocus on mobile by default
onTapOutside: (_) =>
node?.unfocus(),
// The toolbar's paste button doesn't use the shortcut's action, so replace it too
contextMenuBuilder:
(
@ -985,6 +1009,7 @@ class const Composer(
),
],
),
),
);
}
}

View file

@ -16,7 +16,9 @@ class const TaggerOverlay(
}) extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return Padding(
// Lives in an overlay, so taps on it would otherwise unfocus the composer
return TextFieldTapRegion(
child: Padding(
padding: .all(8),
child: ClipRRect(
borderRadius: .all(.circular(12)),
@ -40,6 +42,7 @@ class const TaggerOverlay(
),
),
),
),
);
}
}