Skip to content

Commit

Permalink
TW-1031: fix problem when tap to emoji close the emoji picker
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Feb 19, 2024
1 parent e44378d commit 8473d32
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
33 changes: 16 additions & 17 deletions lib/pages/chat/chat_emoji_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,34 @@ class ChatEmojiPicker extends StatelessWidget {
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: showEmojiPickerNotifier,
builder: (context, showEmojiPicker, child) {
if (!showEmojiPicker) return child!;

builder: (context, showEmojiPicker, _) {
return AnimatedContainer(
decoration: BoxDecoration(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(
color: Theme.of(context).colorScheme.primary,
color: Colors.transparent,
width: 1,
),
),
),
duration: TwakeThemes.animationDuration,
curve: TwakeThemes.animationCurve,
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height / 3,
child: EmojiPicker(
onEmojiSelected: (_, emoji) => onEmojiSelected(emoji),
onBackspacePressed: emojiPickerBackspace,
config: Config(
backspaceColor: Theme.of(context).colorScheme.primary,
bgColor: Theme.of(context).colorScheme.surface,
indicatorColor: Theme.of(context).colorScheme.primary,
iconColorSelected: Theme.of(context).colorScheme.primary,
),
),
height: showEmojiPicker ? MediaQuery.sizeOf(context).height / 3 : 0,
child: showEmojiPicker
? EmojiPicker(
onEmojiSelected: (_, emoji) => onEmojiSelected(emoji),
onBackspacePressed: emojiPickerBackspace,
config: Config(
backspaceColor: Theme.of(context).colorScheme.primary,
bgColor: Theme.of(context).colorScheme.surface,
indicatorColor: Theme.of(context).colorScheme.primary,
iconColorSelected: Theme.of(context).colorScheme.primary,
),
)
: null,
);
},
child: const SizedBox.shrink(),
);
}
}
1 change: 1 addition & 0 deletions lib/pages/chat/chat_input_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class ChatInputRow extends StatelessWidget {
controller: controller.sendController,
focusSuggestionController: controller.focusSuggestionController,
suggestionScrollController: controller.suggestionScrollController,
showEmojiPickerNotifier: controller.showEmojiPickerNotifier,
decoration: InputDecoration(
hintText: L10n.of(context)!.chatMessage,
hintMaxLines: 1,
Expand Down
8 changes: 6 additions & 2 deletions lib/pages/chat/input_bar/input_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
final ValueChanged<String>? onChanged;
final bool autofocus;
final ValueKey? typeAheadKey;
final ValueNotifier<bool>? showEmojiPickerNotifier;
final SuggestionsController<Map<String, String?>>? suggestionsController;

InputBar({
Expand All @@ -55,6 +56,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
this.typeAheadKey,
this.rawKeyboardFocusNode,
this.suggestionsController,
this.showEmojiPickerNotifier,
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -387,7 +389,6 @@ class InputBar extends StatelessWidget with PasteImageMixin {
suggestionsController: suggestionsController,
controller: controller,
focusNode: typeAheadFocusNode,
// show suggestions after 50ms idle time (default is 300)
builder: (context, controller, focusNode) => TextField(
minLines: minLines,
maxLines: maxLines,
Expand Down Expand Up @@ -429,7 +430,10 @@ class InputBar extends StatelessWidget with PasteImageMixin {
suggestionsController?.open();
} else {
suggestionsController?.close();
typeAheadFocusNode?.requestFocus();
if (PlatformInfos.isWeb ||
showEmojiPickerNotifier?.value == false) {
typeAheadFocusNode?.requestFocus();
}
}
focusSuggestionController.suggestions = suggestions;
return suggestions;
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/chat_draft/draft_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class DraftChatController extends State<DraftChat>
sendController.dispose();
forwardListController.dispose();
focusSuggestionController.dispose();
inputText.dispose();
showEmojiPickerNotifier.dispose();
super.dispose();
}

Expand Down

0 comments on commit 8473d32

Please sign in to comment.