fix: callout emoji size should follow the document font size (#6590)

This commit is contained in:
Lucas 2024-10-21 18:00:32 +08:00 committed by GitHub
parent 068500df84
commit 5e09e96f7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 132 additions and 43 deletions

View File

@ -21,6 +21,7 @@ class EmojiPickerButton extends StatelessWidget {
this.showBorder = true, this.showBorder = true,
this.enable = true, this.enable = true,
this.margin, this.margin,
this.buttonSize,
}); });
final String emoji; final String emoji;
@ -35,10 +36,66 @@ class EmojiPickerButton extends StatelessWidget {
final bool showBorder; final bool showBorder;
final bool enable; final bool enable;
final EdgeInsets? margin; final EdgeInsets? margin;
final Size? buttonSize;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (UniversalPlatform.isDesktopOrWeb) { if (UniversalPlatform.isDesktopOrWeb) {
return _DesktopEmojiPickerButton(
emoji: emoji,
onSubmitted: onSubmitted,
emojiPickerSize: emojiPickerSize,
emojiSize: emojiSize,
defaultIcon: defaultIcon,
offset: offset,
direction: direction,
title: title,
showBorder: showBorder,
enable: enable,
buttonSize: buttonSize,
);
}
return _MobileEmojiPickerButton(
emoji: emoji,
onSubmitted: onSubmitted,
emojiSize: emojiSize,
enable: enable,
title: title,
margin: margin,
);
}
}
class _DesktopEmojiPickerButton extends StatelessWidget {
_DesktopEmojiPickerButton({
required this.emoji,
required this.onSubmitted,
this.emojiPickerSize = const Size(360, 380),
this.emojiSize = 18.0,
this.defaultIcon,
this.offset,
this.direction,
this.title,
this.showBorder = true,
this.enable = true,
this.buttonSize,
});
final String emoji;
final double emojiSize;
final Size emojiPickerSize;
final void Function(String emoji, PopoverController? controller) onSubmitted;
final PopoverController popoverController = PopoverController();
final Widget? defaultIcon;
final Offset? offset;
final PopoverDirection? direction;
final String? title;
final bool showBorder;
final bool enable;
final Size? buttonSize;
@override
Widget build(BuildContext context) {
return AppFlowyPopover( return AppFlowyPopover(
controller: popoverController, controller: popoverController,
constraints: BoxConstraints.expand( constraints: BoxConstraints.expand(
@ -58,8 +115,8 @@ class EmojiPickerButton extends StatelessWidget {
), ),
), ),
child: Container( child: Container(
width: 30.0, width: buttonSize?.width ?? 30.0,
height: 30.0, height: buttonSize?.height ?? 30.0,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
border: showBorder border: showBorder
@ -81,7 +138,27 @@ class EmojiPickerButton extends StatelessWidget {
), ),
); );
} }
}
class _MobileEmojiPickerButton extends StatelessWidget {
const _MobileEmojiPickerButton({
required this.emoji,
required this.onSubmitted,
this.emojiSize = 18.0,
this.enable = true,
this.title,
this.margin,
});
final String emoji;
final double emojiSize;
final void Function(String emoji, PopoverController? controller) onSubmitted;
final String? title;
final bool enable;
final EdgeInsets? margin;
@override
Widget build(BuildContext context) {
return FlowyButton( return FlowyButton(
useIntrinsicWidth: true, useIntrinsicWidth: true,
margin: margin:

View File

@ -173,6 +173,7 @@ class _CalloutBlockComponentWidgetState
final textDirection = calculateTextDirection( final textDirection = calculateTextDirection(
layoutDirection: Directionality.maybeOf(context), layoutDirection: Directionality.maybeOf(context),
); );
final (emojiSize, emojiButtonSize) = calculateEmojiSize();
Widget child = Container( Widget child = Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -190,14 +191,14 @@ class _CalloutBlockComponentWidgetState
if (UniversalPlatform.isDesktopOrWeb) const HSpace(4.0), if (UniversalPlatform.isDesktopOrWeb) const HSpace(4.0),
// the emoji picker button for the note // the emoji picker button for the note
EmojiPickerButton( EmojiPickerButton(
key: ValueKey( // force to refresh the popover state
emoji.toString(), key: ValueKey(widget.node.id + emoji),
), // force to refresh the popover state
enable: editorState.editable, enable: editorState.editable,
title: '', title: '',
emoji: emoji, emoji: emoji,
emojiSize: 15.0, emojiSize: emojiSize,
showBorder: false, showBorder: false,
buttonSize: emojiButtonSize,
onSubmitted: (emoji, controller) { onSubmitted: (emoji, controller) {
setEmoji(emoji); setEmoji(emoji);
controller?.close(); controller?.close();
@ -277,4 +278,15 @@ class _CalloutBlockComponentWidgetState
); );
await editorState.apply(transaction); await editorState.apply(transaction);
} }
(double, Size) calculateEmojiSize() {
const double defaultEmojiSize = 16.0;
const Size defaultEmojiButtonSize = Size(30.0, 30.0);
final double emojiSize =
editorState.editorStyle.textStyleConfiguration.text.fontSize ??
defaultEmojiSize;
final emojiButtonSize =
defaultEmojiButtonSize * emojiSize / defaultEmojiSize;
return (emojiSize, emojiButtonSize);
}
} }