diff --git a/lib/screens/channel/chat/widgets/chat_bottom_bar.dart b/lib/screens/channel/chat/widgets/chat_bottom_bar.dart index 046e1fdf..beb9e024 100644 --- a/lib/screens/channel/chat/widgets/chat_bottom_bar.dart +++ b/lib/screens/channel/chat/widgets/chat_bottom_bar.dart @@ -34,13 +34,6 @@ class ChatBottomBar extends StatelessWidget { minLines: 1, maxLines: 5, enabled: chatStore.auth.isLoggedIn ? true : false, - onTap: () { - chatStore.assetsStore.showEmoteMenu = false; - Future.delayed( - const Duration(milliseconds: 200), - () => chatStore.scrollController.jumpTo(chatStore.scrollController.position.maxScrollExtent), - ); - }, decoration: InputDecoration( suffixIcon: IconButton( tooltip: 'Emote Menu', diff --git a/lib/screens/channel/chat/widgets/chat_user_modal.dart b/lib/screens/channel/chat/widgets/chat_user_modal.dart index 61c42274..f6088f28 100644 --- a/lib/screens/channel/chat/widgets/chat_user_modal.dart +++ b/lib/screens/channel/chat/widgets/chat_user_modal.dart @@ -49,10 +49,6 @@ class ChatUserModal extends StatelessWidget { chatStore.textController.text = '@$username '; Navigator.pop(context); chatStore.textFieldFocusNode.requestFocus(); - Future.delayed( - const Duration(milliseconds: 200), - () => chatStore.scrollController.jumpTo(chatStore.scrollController.position.maxScrollExtent), - ); }, child: const Text('Reply'), ), diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index 7b837814..5aa25260 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -111,6 +111,20 @@ abstract class _ChatStoreBase with Store { if (_autoScroll == false) _autoScroll = true; } }); + + // Add a listener to the textfield that will do the following when focused: + // 1. Hide the emote menu if it is currently shown + // 2. Scroll to the latest message (after a brief delay) + textFieldFocusNode.addListener(() { + if (textFieldFocusNode.hasFocus) { + if (assetsStore.showEmoteMenu) assetsStore.showEmoteMenu = false; + + Future.delayed( + const Duration(milliseconds: 500), + () => scrollController.jumpTo(scrollController.position.maxScrollExtent), + ); + } + }); } /// Handle and process the provided string-representation of the IRC data. @@ -280,6 +294,7 @@ abstract class _ChatStoreBase with Store { } /// Sends the given string message by the logged-in user and adds it to [_messages]. + @action void sendMessage(String message) { // Do not send if the message is blank/empty. if (message.isEmpty) return; diff --git a/lib/screens/channel/stores/chat_store.g.dart b/lib/screens/channel/stores/chat_store.g.dart index 915f3162..9cb2a66a 100644 --- a/lib/screens/channel/stores/chat_store.g.dart +++ b/lib/screens/channel/stores/chat_store.g.dart @@ -85,6 +85,17 @@ mixin _$ChatStore on _ChatStoreBase, Store { } } + @override + void sendMessage(String message) { + final _$actionInfo = _$_ChatStoreBaseActionController.startAction( + name: '_ChatStoreBase.sendMessage'); + try { + return super.sendMessage(message); + } finally { + _$_ChatStoreBaseActionController.endAction(_$actionInfo); + } + } + @override String toString() { return '''