diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 67d76dedc..175bd9275 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -2034,14 +2034,9 @@ class ChatController extends State MessagePracticeMode? mode, Event? nextEvent, Event? prevEvent, - }) { + }) async { if (event.redacted || event.status == EventStatus.sending) return; - // Close keyboard, if open - if (inputFocus.hasFocus && PlatformInfos.isMobile) { - inputFocus.unfocus(); - return; - } // Close emoji picker, if open if (showEmojiPicker) { hideEmojiPicker(); @@ -2079,8 +2074,24 @@ class ChatController extends State } stopMediaStream.add(null); - if (buttonEventID == event.eventId) { + final isButton = buttonEventID == event.eventId; + final keyboardOpen = inputFocus.hasFocus && PlatformInfos.isMobile; + + final delay = keyboardOpen + ? const Duration(milliseconds: 500) + : isButton + ? const Duration(milliseconds: 200) + : null; + + if (isButton) { depressMessageButton.value = true; + } + + if (keyboardOpen) { + inputFocus.unfocus(); + } + + if (delay != null) { OverlayUtil.showOverlay( context: context, child: TransparentBackdrop( @@ -2088,28 +2099,28 @@ class ChatController extends State onDismiss: clearSelectedEvents, blurBackground: true, animateBackground: true, - backgroundAnimationDuration: const Duration(milliseconds: 200), + backgroundAnimationDuration: delay, ), position: OverlayPositionEnum.centered, overlayKey: "button_message_backdrop", ); - Future.delayed(const Duration(milliseconds: 200), () { - if (_router.state.path != ':roomid') { - // The user has navigated away from the chat, - // so we don't want to show the overlay. - return; - } - OverlayUtil.showOverlay( - context: context, - child: overlayEntry, - position: OverlayPositionEnum.centered, - onDismiss: clearSelectedEvents, - blurBackground: true, - backgroundColor: Colors.black, - overlayKey: "message_toolbar_overlay", - ); - }); + await Future.delayed(delay); + + if (_router.state.path != ':roomid') { + // The user has navigated away from the chat, + // so we don't want to show the overlay. + return; + } + OverlayUtil.showOverlay( + context: context, + child: overlayEntry, + position: OverlayPositionEnum.centered, + onDismiss: clearSelectedEvents, + blurBackground: true, + backgroundColor: Colors.black, + overlayKey: "message_toolbar_overlay", + ); } else { OverlayUtil.showOverlay( context: context,