mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-08-01 13:30:21 +00:00
fix: callout emoji size should follow the document font size (#6590)
This commit is contained in:
parent
068500df84
commit
5e09e96f7b
@ -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,53 +36,129 @@ 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 AppFlowyPopover(
|
return _DesktopEmojiPickerButton(
|
||||||
controller: popoverController,
|
emoji: emoji,
|
||||||
constraints: BoxConstraints.expand(
|
onSubmitted: onSubmitted,
|
||||||
width: emojiPickerSize.width,
|
emojiPickerSize: emojiPickerSize,
|
||||||
height: emojiPickerSize.height,
|
emojiSize: emojiSize,
|
||||||
),
|
defaultIcon: defaultIcon,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
margin: EdgeInsets.zero,
|
direction: direction,
|
||||||
direction: direction ?? PopoverDirection.rightWithTopAligned,
|
title: title,
|
||||||
popupBuilder: (_) => Container(
|
showBorder: showBorder,
|
||||||
width: emojiPickerSize.width,
|
enable: enable,
|
||||||
height: emojiPickerSize.height,
|
buttonSize: buttonSize,
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: EmojiSelectionMenu(
|
|
||||||
onSubmitted: (emoji) => onSubmitted(emoji, popoverController),
|
|
||||||
onExit: () {},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
width: 30.0,
|
|
||||||
height: 30.0,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: showBorder
|
|
||||||
? Border.all(
|
|
||||||
color: Theme.of(context).dividerColor,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
child: FlowyButton(
|
|
||||||
margin: emoji.isEmpty && defaultIcon != null
|
|
||||||
? EdgeInsets.zero
|
|
||||||
: const EdgeInsets.only(left: 2.0),
|
|
||||||
expandText: false,
|
|
||||||
text: emoji.isEmpty && defaultIcon != null
|
|
||||||
? defaultIcon!
|
|
||||||
: FlowyText.emoji(emoji, fontSize: emojiSize),
|
|
||||||
onTap: enable ? popoverController.show : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
controller: popoverController,
|
||||||
|
constraints: BoxConstraints.expand(
|
||||||
|
width: emojiPickerSize.width,
|
||||||
|
height: emojiPickerSize.height,
|
||||||
|
),
|
||||||
|
offset: offset,
|
||||||
|
margin: EdgeInsets.zero,
|
||||||
|
direction: direction ?? PopoverDirection.rightWithTopAligned,
|
||||||
|
popupBuilder: (_) => Container(
|
||||||
|
width: emojiPickerSize.width,
|
||||||
|
height: emojiPickerSize.height,
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: EmojiSelectionMenu(
|
||||||
|
onSubmitted: (emoji) => onSubmitted(emoji, popoverController),
|
||||||
|
onExit: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
width: buttonSize?.width ?? 30.0,
|
||||||
|
height: buttonSize?.height ?? 30.0,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: showBorder
|
||||||
|
? Border.all(
|
||||||
|
color: Theme.of(context).dividerColor,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
child: FlowyButton(
|
||||||
|
margin: emoji.isEmpty && defaultIcon != null
|
||||||
|
? EdgeInsets.zero
|
||||||
|
: const EdgeInsets.only(left: 2.0),
|
||||||
|
expandText: false,
|
||||||
|
text: emoji.isEmpty && defaultIcon != null
|
||||||
|
? defaultIcon!
|
||||||
|
: FlowyText.emoji(emoji, fontSize: emojiSize),
|
||||||
|
onTap: enable ? popoverController.show : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user