Skip to content

Commit 9391867

Browse files
rajveermalviyagnprice
authored andcommitted
emoji: Use "Apple Color Emoji" font on iOS/macOS for UnicodeEmojiWidget
Some unicode characters, like U+2764 (❤) or U+00AE (®) can have glyphs in non-Emoji fonts, resulting in incorrect rendering of such characters, where we specifically want an emoji to be displayed. So, explicitly mention "Apple Color Emoji" to be the font used on iOS/macOS for displaying the unicode emoji. This resolves part of #1104, namely for reaction chips and autocomplete results. [greg: wrote test] Fixes-partly: #1104
1 parent 19e83b5 commit 9391867

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/widgets/emoji.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class UnicodeEmojiWidget extends StatelessWidget {
5050

5151
case TargetPlatform.iOS:
5252
case TargetPlatform.macOS:
53-
// We expect the font "Apple Color Emoji" to be used. There are some
54-
// surprises in how Flutter ends up rendering emojis in this font:
53+
// We use the font "Apple Color Emoji". There are some surprises in how
54+
// Flutter ends up rendering emojis in this font:
5555
// - With a font size of 17px, the emoji visually seems to be about 17px
5656
// square. (Unlike on Android, with Noto Color Emoji, where a 14.5px font
5757
// size gives an emoji that looks 17px square.) See:
@@ -71,7 +71,9 @@ class UnicodeEmojiWidget extends StatelessWidget {
7171
SizedBox(height: boxSize, width: boxSize),
7272
PositionedDirectional(start: 0, child: Text(
7373
textScaler: textScaler,
74-
style: TextStyle(fontSize: size),
74+
style: TextStyle(
75+
fontFamily: 'Apple Color Emoji',
76+
fontSize: size),
7577
strutStyle: StrutStyle(fontSize: size, forceStrutHeight: true),
7678
emojiDisplay.emojiUnicode)),
7779
]);

test/widgets/emoji_reaction_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import '../flutter_checks.dart';
1818
import '../model/binding.dart';
1919
import '../model/test_store.dart';
2020
import '../test_images.dart';
21+
import 'content_test.dart';
2122
import 'test_app.dart';
2223
import 'text_test.dart';
2324

@@ -259,6 +260,23 @@ void main() {
259260
.isSameColorAs(EmojiReactionTheme.dark().bgUnselected);
260261
});
261262

263+
testWidgets('use emoji font', (tester) async {
264+
await prepare();
265+
await store.addUser(eg.selfUser);
266+
await setupChipsInBox(tester, reactions: [
267+
Reaction.fromJson({
268+
'user_id': eg.selfUser.userId,
269+
'emoji_name': 'heart', 'emoji_code': '2764', 'reaction_type': 'unicode_emoji'}),
270+
]);
271+
272+
check(mergedStyleOf(tester, '\u{2764}')).isNotNull()
273+
.fontFamily.equals(switch (defaultTargetPlatform) {
274+
TargetPlatform.android => 'Noto Color Emoji',
275+
TargetPlatform.iOS => 'Apple Color Emoji',
276+
_ => throw StateError('unexpected platform in test'),
277+
});
278+
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
279+
262280
// TODO more tests:
263281
// - Tapping a chip does the right thing
264282
// - When an image emoji fails to load, falls back to :text_emoji:

0 commit comments

Comments
 (0)