- 
                Notifications
    You must be signed in to change notification settings 
- Fork 348
Add reusable EmojiWidget #1928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add reusable EmojiWidget #1928
Conversation
f25380a    to
    ef29c09      
    Compare
  
    | Revision pushed, fixing a bug where I forgot to use  ef29c09 settings [nfc]: Centralize logic for checking device animation settings | 
ef29c09    to
    9ab45a0      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chrisbobbe. Overall LGTM, just one comment.
        
          
                lib/widgets/user.dart
              
                Outdated
          
        
      | emojiDisplay: emojiDisplay, | ||
| squareDimension: size, | ||
| neverAnimateImage: neverAnimate, | ||
| imageAnimationMode: ImageAnimationMode.animateNever, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this respect the value of neverAnimate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, yes, thanks for the catch!
9ab45a0    to
    3d7da28      
    Compare
  
    | Thanks for the review! Revision pushed. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM, moving over to Greg's review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this cleanup! Here's a review of the first 6 commits:
dc5d5dd emoji [nfc]: Dartdoc EmojiStore.emojiDisplayFor
0813931 emoji [nfc]: Pull out textEmojiForEmojiName helper
23985d3 emoji_reaction [nfc]: Inline _UnicodeEmoji
ea3299a emoji_reaction [nfc]: Inline _ImageEmoji
59f4a86 emoji_reaction [nfc]: Give _TextEmoji the emoji name more straightforwardly
6311f4f emoji [nfc]: Add reusable EmojiWidget; use it in ReactionChip
Going AFK for the moment, so I'll leave for a later review the remaining 6 commits:
329c335 emoji [nfc]: Use EmojiWidget in emoji picker and autocomplete
26ac403 emoji_reaction [nfc]: Use EmojiWidget in view-reactions header
29aeecb user status: When we can't load image emoji, lay out a padded empty square
3fece59 user status [nfc]: Pull Padding outside the emojiDisplay switch
30110ba user status [nfc]: Use EmojiWidget
3d7da28 settings [nfc]: Centralize logic for checking device animation settings
(Also on an early skim the last commit looks like it'd be best as a separate PR — seems nontrivial, and thematically rather separate from the rest.)
| /// May be a [TextEmojiDisplay] even if the emojiset is not [Emojiset.text]; | ||
| /// this happens for image emojis whose URLs don't parse. | ||
| EmojiDisplay emojiDisplayFor({ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation, there are a few other cases where this happens, right? Seems like more generally it's when we can't understand the data that describes the emoji.
        
          
                lib/widgets/emoji.dart
              
                Outdated
          
        
      | UnicodeEmojiDisplay() => UnicodeEmojiWidget( | ||
| size: squareDimension, | ||
| emojiDisplay: emojiDisplay), | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this drops textScaler.
        
          
                lib/widgets/emoji.dart
              
                Outdated
          
        
      | ImageErrorWidgetBuilder _getImageErrorBuilder(double effectiveSize) { | ||
| return (_, _, _) => switch (imagePlaceholderStyle) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this indirection of a function returning a function can be simplified: we can wait to compute effectiveSize until the point where it turns out we need it.
This makes the caller a bit more verbose, but we're about to make it simpler than it was before.
This makes the caller a bit more verbose, but we're about to make it simpler than it was before.
There are several places where we switch on EmojiDisplay, mostly with TODOs to factor the switch out to something central. Here's a widget to accomplish that factoring, used first in ReactionChip.
…quare Instead of laying out - just padding, in the case where the network request failed, and - nothing, in the case where the URL didn't parse.
3d7da28    to
    1f92dfd      
    Compare
  
    | Thanks! Revision pushed, and I'll send that last commit in a separate PR. -> #1957 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just nits below.
| buildCustomTextEmoji: () { | ||
| // emojiDisplay is not TextEmojiDisplay, | ||
| // and imagePlaceholderStyle is not EmojiImagePlaceholderStyle.text. | ||
| assert(false); | ||
| return SizedBox.shrink(); | ||
| }, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this case can't happen, seems simpler to pass over it in silence 🙂 — I think the reader here won't naturally feel a need to think about it if the code doesn't bring it up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Particularly as if this case does happen, and the reader works out what this SizedBox.shrink produces in the layout, it seems like it'd be glitchy — we'd still have the 6px padding below but now around a zero-sized box.
| child: EmojiWidget( | ||
| emojiDisplay: emojiDisplay, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: over-indented as of the penultimate commit:
+      child: switch (emojiDisplay) {
+          UnicodeEmojiDisplay() => UnicodeEmojiWidget(size: size, emojiDisplay:
 emojiDisplay),
+          ImageEmojiDisplay() => ImageEmojiWidget(
| neverAnimate: neverAnimate, | ||
| // If image emoji fails to load, show nothing. | ||
| errorBuilder: (_, _, _) => placeholder)), | ||
| // The user-status feature doesn't support a :text_emoji:-style display. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line would be good as a replacement for the "Web doesn't seem to respect …" comment above. This one is stating a product/design choice we've made, which is what I think has effectively happened here.
Stacked on #1926.
This resolves a few TODOs, and will be useful toward