From b35babd79d75385f836ac74da15713e7573f1d20 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 20 Oct 2020 17:01:33 +0530 Subject: [PATCH] feat: Shrink actions on type --- lib/src/message_input.dart | 45 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index f2fdda3f..2c27665a 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -169,7 +169,8 @@ class MessageInputState extends State { bool _commandEnabled = false; OverlayEntry _commandsOverlay, _mentionsOverlay; - Command chosenCommand; + Command _chosenCommand; + bool _actionsShrunk = false; /// The editing controller passed to the input TextField TextEditingController textEditingController; @@ -202,14 +203,8 @@ class MessageInputState extends State { direction: Axis.horizontal, crossAxisAlignment: CrossAxisAlignment.center, children: [ - if (!_commandEnabled) - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - if (!widget.disableAttachments) _buildAttachmentButton(), - if (widget.editMessage == null) _buildCommandButton(), - ], - ), + if(!_commandEnabled) + _buildExpandActionsButton(), if (widget.actionsLocation == ActionsLocation.left) ...widget.actions ?? [], _buildTextInput(context), @@ -233,6 +228,31 @@ class MessageInputState extends State { ); } + Widget _buildExpandActionsButton() { + return AnimatedCrossFade( + crossFadeState: _actionsShrunk + ? CrossFadeState.showFirst + : CrossFadeState.showSecond, + firstChild: IconButton( + onPressed: () { + setState(() { + _actionsShrunk = false; + }); + }, + icon: Icon(StreamIcons.arrow_right, color: StreamChatTheme.of(context).accentColor,), + ), + secondChild: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + if (!widget.disableAttachments) _buildAttachmentButton(), + if (widget.editMessage == null) _buildCommandButton(), + ], + ), + duration: Duration(milliseconds: 300), + alignment: Alignment.center, + ); + } + Expanded _buildTextInput(BuildContext context) { return Expanded( child: Center( @@ -254,6 +274,7 @@ class MessageInputState extends State { setState(() { _messageIsPresent = s.trim().isNotEmpty; + _actionsShrunk = true; }); _commandsOverlay?.remove(); @@ -298,7 +319,7 @@ class MessageInputState extends State { child: Chip( backgroundColor: StreamChatTheme.of(context).accentColor, label: Text( - chosenCommand?.name ?? "", + _chosenCommand?.name ?? "", style: TextStyle(color: Colors.white), ), avatar: Icon( @@ -521,7 +542,7 @@ class MessageInputState extends State { void _setCommand(Command c) { textEditingController.clear(); setState(() { - chosenCommand = c; + _chosenCommand = c; _commandEnabled = true; }); _commandsOverlay?.remove(); @@ -946,7 +967,7 @@ class MessageInputState extends State { } if(_commandEnabled) { - text = '/${chosenCommand.name} ' + text; + text = '/${_chosenCommand.name} ' + text; } final attachments = List<_SendingAttachment>.from(_attachments);