feat: update emoji picker UI

This commit is contained in:
Lucas.Xu
2022-12-12 15:10:38 +08:00
parent 98d408af87
commit 3932d0661d
3 changed files with 46 additions and 59 deletions

View File

@ -1,6 +1,3 @@
import 'package:app_flowy/plugins/document/editor_styles.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/plugins/document/presentation/banner.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart'; import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flowy_infra_ui/widget/error_page.dart'; import 'package:flowy_infra_ui/widget/error_page.dart';
@ -8,7 +5,11 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../../startup/startup.dart';
import 'application/doc_bloc.dart'; import 'application/doc_bloc.dart';
import 'editor_styles.dart';
import 'presentation/banner.dart';
class DocumentPage extends StatefulWidget { class DocumentPage extends StatefulWidget {
final VoidCallback onDeleted; final VoidCallback onDeleted;
@ -123,6 +124,8 @@ class _DocumentPageState extends State<DocumentPage> {
mathEquationMenuItem, mathEquationMenuItem,
// Code Block // Code Block
codeBlockMenuItem, codeBlockMenuItem,
// Emoji
emojiMenuItem,
], ],
themeData: theme.copyWith(extensions: [ themeData: theme.copyWith(extensions: [
...theme.extensions.values, ...theme.extensions.values,

View File

@ -80,16 +80,16 @@ class SelectionMenu implements SelectionMenuService {
// show above // show above
offset = topRight - menuOffset; offset = topRight - menuOffset;
showBelow = false; showBelow = false;
_alignment = Alignment.topRight; _alignment = Alignment.topLeft;
} }
_topLeft = offset; _topLeft = offset;
_offset = Offset(offset.dx, showBelow ? offset.dy : MediaQuery.of(context).size.height - offset.dy); _offset = Offset(offset.dx,
showBelow ? offset.dy : MediaQuery.of(context).size.height - offset.dy);
_selectionMenuEntry = OverlayEntry(builder: (context) { _selectionMenuEntry = OverlayEntry(builder: (context) {
return Positioned( return Positioned(
top: showBelow ? _offset.dy : null, top: showBelow ? _offset.dy : null,
bottom: bottom: showBelow ? null : _offset.dy,
showBelow ? null : _offset.dy,
left: offset.dx, left: offset.dx,
child: SelectionMenuWidget( child: SelectionMenuWidget(
items: [ items: [

View File

@ -1,12 +1,10 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'emoji_picker.dart'; import 'emoji_picker.dart';
SelectionMenuItem emojiMenuItem = SelectionMenuItem emojiMenuItem = SelectionMenuItem(
SelectionMenuItem(
name: () => 'emoji', name: () => 'emoji',
icon: (editorState, onSelected) => Icon( icon: (editorState, onSelected) => Icon(
Icons.emoji_emotions_outlined, Icons.emoji_emotions_outlined,
@ -17,7 +15,7 @@ SelectionMenuItem emojiMenuItem =
), ),
keywords: ['emoji'], keywords: ['emoji'],
handler: _showEmojiSelectionMenu, handler: _showEmojiSelectionMenu,
); );
OverlayEntry? _emojiSelectionMenu; OverlayEntry? _emojiSelectionMenu;
EditorState? _editorState; EditorState? _editorState;
@ -33,9 +31,8 @@ void _showEmojiSelectionMenu(
_emojiSelectionMenu?.remove(); _emojiSelectionMenu?.remove();
_emojiSelectionMenu = OverlayEntry(builder: (context) { _emojiSelectionMenu = OverlayEntry(builder: (context) {
return Positioned( return Positioned(
top: aligment == Alignment.bottomRight ? offset.dy : null, top: aligment == Alignment.bottomLeft ? offset.dy : null,
bottom: bottom: aligment == Alignment.topLeft ? offset.dy : null,
aligment == Alignment.topRight ? offset.dy : null,
left: offset.dx, left: offset.dx,
child: Material( child: Material(
child: EmojiSelectionMenu( child: EmojiSelectionMenu(
@ -73,19 +70,19 @@ class EmojiSelectionMenu extends StatefulWidget {
Key? key, Key? key,
required this.onSubmitted, required this.onSubmitted,
required this.onExit, required this.onExit,
this.editorState, required this.editorState,
}) : super(key: key); }) : super(key: key);
final void Function(Emoji emoji) onSubmitted; final void Function(Emoji emoji) onSubmitted;
final void Function() onExit; final void Function() onExit;
final EditorState? editorState; final EditorState editorState;
@override @override
State<EmojiSelectionMenu> createState() => _EmojiSelectionMenuState(); State<EmojiSelectionMenu> createState() => _EmojiSelectionMenuState();
} }
class _EmojiSelectionMenuState extends State<EmojiSelectionMenu> { class _EmojiSelectionMenuState extends State<EmojiSelectionMenu> {
EditorStyle? get style => widget.editorState?.editorStyle; EditorStyle get style => widget.editorState.editorStyle;
@override @override
void initState() { void initState() {
@ -119,9 +116,9 @@ class _EmojiSelectionMenuState extends State<EmojiSelectionMenu> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
width: 300, width: 300,
padding: const EdgeInsets.all(24.0), padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: style?.selectionMenuBackgroundColor ?? Colors.white, color: style.selectionMenuBackgroundColor,
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
blurRadius: 5, blurRadius: 5,
@ -129,45 +126,26 @@ class _EmojiSelectionMenuState extends State<EmojiSelectionMenu> {
color: Colors.black.withOpacity(0.1), color: Colors.black.withOpacity(0.1),
), ),
], ],
// borderRadius: BorderRadius.circular(6.0), borderRadius: BorderRadius.circular(6.0),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(context),
// FlowyEmojiStyleButton(normalIcon: '', tooltipText: ''),
const SizedBox(height: 10.0),
_buildEmojiBox(context),
],
),
);
}
Widget _buildHeader(BuildContext context) {
return Text(
'Pick Emoji',
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14.0,
color: style?.selectionMenuItemTextColor ?? Colors.black,
fontWeight: FontWeight.w500,
), ),
child: _buildEmojiBox(context),
); );
} }
Widget _buildEmojiBox(BuildContext context) { Widget _buildEmojiBox(BuildContext context) {
return SizedBox( return SizedBox(
height: 300, height: 200,
child: EmojiPicker( child: EmojiPicker(
onEmojiSelected: (category, emoji) => widget.onSubmitted(emoji), onEmojiSelected: (category, emoji) => widget.onSubmitted(emoji),
config: const Config( config: Config(
columns: 8, columns: 8,
emojiSizeMax: 28, emojiSizeMax: 28,
bgColor: Color(0xffF2F2F2), bgColor:
style.selectionMenuBackgroundColor ?? const Color(0xffF2F2F2),
iconColor: Colors.grey, iconColor: Colors.grey,
iconColorSelected: Color(0xff333333), iconColorSelected: const Color(0xff333333),
indicatorColor: Color(0xff333333), indicatorColor: const Color(0xff333333),
progressIndicatorColor: Color(0xff333333), progressIndicatorColor: const Color(0xff333333),
buttonMode: ButtonMode.CUPERTINO, buttonMode: ButtonMode.CUPERTINO,
initCategory: Category.RECENT, initCategory: Category.RECENT,
), ),
@ -181,12 +159,18 @@ extension on EditorState {
final selectionService = service.selectionService; final selectionService = service.selectionService;
final currentSelection = selectionService.currentSelection.value; final currentSelection = selectionService.currentSelection.value;
final nodes = selectionService.currentSelectedNodes; final nodes = selectionService.currentSelectedNodes;
if (currentSelection == null || !currentSelection.isCollapsed || nodes.first is! TextNode) { if (currentSelection == null ||
!currentSelection.isCollapsed ||
nodes.first is! TextNode) {
return; return;
} }
final textNode = nodes.first as TextNode; final textNode = nodes.first as TextNode;
final tr = transaction; final tr = transaction;
tr.insertText(textNode, currentSelection.endIndex, emoji.emoji,); tr.insertText(
textNode,
currentSelection.endIndex,
emoji.emoji,
);
apply(tr); apply(tr);
} }
} }