Skip to content

Commit 649232a

Browse files
committed
emoji: Make emoji picker return the selected emoji, for reuse
Instead of using the selected emoji deep down the widget tree, simply return it where the emoji picker sheet is opened, to use it for different purposes.
1 parent 0104cd1 commit 649232a

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

lib/widgets/action_sheet.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,22 @@ class ReactionButtons extends StatelessWidget {
738738
: zulipLocalizations.errorReactionAddingFailedTitle);
739739
}
740740

741-
void _handleTapMore() {
741+
void _handleTapMore() async {
742742
// TODO(design): have emoji picker slide in from right and push
743743
// action sheet off to the left
744744

745745
// Dismiss current action sheet before opening emoji picker sheet.
746746
Navigator.of(pageContext).pop();
747747

748-
showEmojiPickerSheet(pageContext: pageContext, message: message);
748+
final emoji = await showEmojiPickerSheet(pageContext: pageContext);
749+
if (emoji == null || !pageContext.mounted) return;
750+
unawaited(doAddOrRemoveReaction(
751+
context: pageContext,
752+
doRemoveReaction: false,
753+
messageId: message.id,
754+
emoji: emoji,
755+
errorDialogTitle:
756+
ZulipLocalizations.of(pageContext).errorReactionAddingFailedTitle));
749757
}
750758

751759
Widget _buildButton({

lib/widgets/emoji_reaction.dart

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,11 @@ Future<void> doAddOrRemoveReaction({
398398
}
399399

400400
/// Opens a browsable and searchable emoji picker bottom sheet.
401-
void showEmojiPickerSheet({
401+
Future<EmojiCandidate?> showEmojiPickerSheet({
402402
required BuildContext pageContext,
403-
required Message message,
404-
}) {
403+
}) async {
405404
final store = PerAccountStoreWidget.of(pageContext);
406-
showModalBottomSheet<void>(
405+
return showModalBottomSheet<EmojiCandidate>(
407406
context: pageContext,
408407
// Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect
409408
// on my iPhone 13 Pro but is marked as "much slower":
@@ -423,20 +422,15 @@ void showEmojiPickerSheet({
423422
// For _EmojiPickerItem, and RealmContentNetworkImage used in ImageEmojiWidget.
424423
child: PerAccountStoreWidget(
425424
accountId: store.accountId,
426-
child: EmojiPicker(pageContext: pageContext, message: message)));
425+
child: EmojiPicker(pageContext: pageContext)));
427426
});
428427
}
429428

430429
@visibleForTesting
431430
class EmojiPicker extends StatefulWidget {
432-
const EmojiPicker({
433-
super.key,
434-
required this.pageContext,
435-
required this.message,
436-
});
431+
const EmojiPicker({super.key, required this.pageContext});
437432

438433
final BuildContext pageContext;
439-
final Message message;
440434

441435
@override
442436
State<EmojiPicker> createState() => _EmojiPickerState();
@@ -534,8 +528,7 @@ class _EmojiPickerState extends State<EmojiPicker> with PerAccountStoreAwareStat
534528
itemCount: _resultsToDisplay.length,
535529
itemBuilder: (context, i) => EmojiPickerListEntry(
536530
pageContext: widget.pageContext,
537-
emoji: _resultsToDisplay[i].candidate,
538-
message: widget.message)))),
531+
emoji: _resultsToDisplay[i].candidate)))),
539532
]))),
540533
]);
541534
}
@@ -547,27 +540,15 @@ class EmojiPickerListEntry extends StatelessWidget {
547540
super.key,
548541
required this.pageContext,
549542
required this.emoji,
550-
required this.message,
551543
});
552544

553545
final BuildContext pageContext;
554546
final EmojiCandidate emoji;
555-
final Message message;
556547

557548
static const _emojiSize = 24.0;
558549

559550
void _onPressed() {
560-
// Dismiss the enclosing action sheet immediately,
561-
// for swift UI feedback that the user's selection was received.
562-
Navigator.pop(pageContext);
563-
564-
doAddOrRemoveReaction(
565-
context: pageContext,
566-
doRemoveReaction: false,
567-
messageId: message.id,
568-
emoji: emoji,
569-
errorDialogTitle:
570-
ZulipLocalizations.of(pageContext).errorReactionAddingFailedTitle);
551+
Navigator.pop(pageContext, emoji);
571552
}
572553

573554
@override

0 commit comments

Comments
 (0)