chore: optimize emoji align on mobile (#5852)

This commit is contained in:
Lucas.Xu 2024-08-01 15:36:21 +08:00 committed by GitHub
parent 0cd5af5ffa
commit 27aac2b911
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -260,6 +260,7 @@ class _SingleMobileInnerViewItemState extends State<SingleMobileInnerViewItem> {
child: FlowyText.regular( child: FlowyText.regular(
widget.view.name, widget.view.name,
fontSize: 16.0, fontSize: 16.0,
figmaLineHeight: 20.0,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
@ -297,12 +298,17 @@ class _SingleMobileInnerViewItemState extends State<SingleMobileInnerViewItem> {
? FlowyText.emoji( ? FlowyText.emoji(
widget.view.icon.value, widget.view.icon.value,
fontSize: 18.0, fontSize: 18.0,
figmaLineHeight: 20.0,
optimizeEmojiAlign: true,
) )
: Opacity( : Opacity(
opacity: 0.7, opacity: 0.7,
child: widget.view.defaultIcon(size: const Size.square(18)), child: widget.view.defaultIcon(size: const Size.square(18)),
); );
return SizedBox(width: 18.0, child: icon); return SizedBox(
width: 18.0,
child: icon,
);
} }
// > button or · button // > button or · button

View File

@ -26,6 +26,8 @@ class FlowyText extends StatelessWidget {
/// this is used to control the line height from Figma. /// this is used to control the line height from Figma.
final double? figmaLineHeight; final double? figmaLineHeight;
final bool optimizeEmojiAlign;
const FlowyText( const FlowyText(
this.text, { this.text, {
super.key, super.key,
@ -44,6 +46,7 @@ class FlowyText extends StatelessWidget {
this.withTooltip = false, this.withTooltip = false,
this.isEmoji = false, this.isEmoji = false,
this.strutStyle, this.strutStyle,
this.optimizeEmojiAlign = false,
}); });
FlowyText.small( FlowyText.small(
@ -62,6 +65,7 @@ class FlowyText extends StatelessWidget {
this.isEmoji = false, this.isEmoji = false,
this.strutStyle, this.strutStyle,
this.figmaLineHeight, this.figmaLineHeight,
this.optimizeEmojiAlign = false,
}) : fontWeight = FontWeight.w400, }) : fontWeight = FontWeight.w400,
fontSize = (Platform.isIOS || Platform.isAndroid) ? 14 : 12; fontSize = (Platform.isIOS || Platform.isAndroid) ? 14 : 12;
@ -82,6 +86,7 @@ class FlowyText extends StatelessWidget {
this.isEmoji = false, this.isEmoji = false,
this.strutStyle, this.strutStyle,
this.figmaLineHeight, this.figmaLineHeight,
this.optimizeEmojiAlign = false,
}) : fontWeight = FontWeight.w400; }) : fontWeight = FontWeight.w400;
const FlowyText.medium( const FlowyText.medium(
@ -101,6 +106,7 @@ class FlowyText extends StatelessWidget {
this.isEmoji = false, this.isEmoji = false,
this.strutStyle, this.strutStyle,
this.figmaLineHeight, this.figmaLineHeight,
this.optimizeEmojiAlign = false,
}) : fontWeight = FontWeight.w500; }) : fontWeight = FontWeight.w500;
const FlowyText.semibold( const FlowyText.semibold(
@ -120,6 +126,7 @@ class FlowyText extends StatelessWidget {
this.isEmoji = false, this.isEmoji = false,
this.strutStyle, this.strutStyle,
this.figmaLineHeight, this.figmaLineHeight,
this.optimizeEmojiAlign = false,
}) : fontWeight = FontWeight.w600; }) : fontWeight = FontWeight.w600;
// Some emojis are not supported on Linux and Android, fallback to noto color emoji // Some emojis are not supported on Linux and Android, fallback to noto color emoji
@ -139,6 +146,7 @@ class FlowyText extends StatelessWidget {
this.isEmoji = true, this.isEmoji = true,
this.fontFamily, this.fontFamily,
this.figmaLineHeight, this.figmaLineHeight,
this.optimizeEmojiAlign = false,
}) : fontWeight = FontWeight.w400, }) : fontWeight = FontWeight.w400,
fallbackFontFamily = null; fallbackFontFamily = null;
@ -176,6 +184,9 @@ class FlowyText extends StatelessWidget {
fontFamily: fontFamily, fontFamily: fontFamily,
fontFamilyFallback: fallbackFontFamily, fontFamilyFallback: fallbackFontFamily,
height: lineHeight, height: lineHeight,
leadingDistribution: isEmoji && optimizeEmojiAlign
? TextLeadingDistribution.even
: null,
); );
if (selectable) { if (selectable) {
@ -194,7 +205,8 @@ class FlowyText extends StatelessWidget {
textAlign: textAlign, textAlign: textAlign,
overflow: overflow ?? TextOverflow.clip, overflow: overflow ?? TextOverflow.clip,
style: textStyle, style: textStyle,
strutStyle: (Platform.isMacOS || Platform.isLinux) & !isEmoji strutStyle: ((Platform.isMacOS || Platform.isLinux) & !isEmoji) ||
(isEmoji && optimizeEmojiAlign)
? StrutStyle.fromTextStyle( ? StrutStyle.fromTextStyle(
textStyle, textStyle,
forceStrutHeight: true, forceStrutHeight: true,