Skip to content

Commit 30a28b1

Browse files
authored
feat: add image block on mobile (#4230)
1 parent 0b3c904 commit 30a28b1

File tree

12 files changed

+73
-5
lines changed

12 files changed

+73
-5
lines changed

frontend/appflowy_flutter/android/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@
4747
</application>
4848
<uses-permission android:name="android.permission.INTERNET" />
4949
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
50+
<queries>
51+
<intent>
52+
<action android:name="android.support.customtabs.action.CustomTabsService" />
53+
</intent>
54+
</queries>
5055
</manifest>

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class MobileBlockActionButtons extends StatelessWidget {
6767
}
6868

6969
void _showBottomSheet(BuildContext context) {
70+
// close the keyboard
71+
editorState.updateSelectionWithReason(null, extraInfo: {});
72+
7073
showMobileBottomSheet(
7174
context,
7275
showHeader: true,

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_placeholder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
104104
} else {
105105
return GestureDetector(
106106
onTap: () {
107+
editorState.updateSelectionWithReason(null, extraInfo: {});
107108
showUploadImageMenu();
108109
},
109110
child: child,

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_selection_menu.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extension InsertImage on EditorState {
5959
offset: 0,
6060
),
6161
);
62+
transaction.selectionExtraInfo = {};
6263

6364
return apply(transaction);
6465
}

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/_indent_items.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import 'package:appflowy/generated/flowy_svgs.g.dart';
22
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/_toolbar_theme.dart';
3-
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart';
3+
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
44
import 'package:appflowy_editor/appflowy_editor.dart';
55
import 'package:flutter/material.dart';
66

77
class IndentAndOutdentItems extends StatelessWidget {
88
const IndentAndOutdentItems({
99
super.key,
10+
required this.service,
1011
required this.editorState,
1112
});
1213

1314
final EditorState editorState;
15+
final AppFlowyMobileToolbarWidgetService service;
1416

1517
@override
1618
Widget build(BuildContext context) {
@@ -28,6 +30,7 @@ class IndentAndOutdentItems extends StatelessWidget {
2830
iconPadding: const EdgeInsets.symmetric(vertical: 14.0),
2931
backgroundColor: theme.toolbarMenuItemBackgroundColor,
3032
onTap: () {
33+
service.closeItemMenu();
3134
outdentCommand.execute(editorState);
3235
},
3336
),
@@ -42,6 +45,7 @@ class IndentAndOutdentItems extends StatelessWidget {
4245
iconPadding: const EdgeInsets.symmetric(vertical: 14.0),
4346
backgroundColor: theme.toolbarMenuItemBackgroundColor,
4447
onTap: () {
48+
service.closeItemMenu();
4549
indentCommand.execute(editorState);
4650
},
4751
),

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_toolbar_item.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class _TextDecorationMenuState extends State<_TextDecorationMenu> {
106106
),
107107
const Spacer(),
108108
IndentAndOutdentItems(
109+
service: widget.service,
109110
editorState: editorState,
110111
),
111112
],

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:appflowy/generated/flowy_svgs.g.dart';
22
import 'package:appflowy/generated/locale_keys.g.dart';
33
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
4+
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
45
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_item/mobile_add_block_toolbar_item.dart';
56
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/_toolbar_theme.dart';
67
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
@@ -184,7 +185,7 @@ class _AddBlockMenu extends StatelessWidget {
184185
onTap: () => _insertBlock(quoteNode()),
185186
),
186187

187-
// divider,
188+
// divider
188189
_AddBlockMenuItemData(
189190
blockType: DividerBlockKeys.type,
190191
backgroundColor: const Color(0xFF98F4CD),
@@ -197,6 +198,25 @@ class _AddBlockMenu extends StatelessWidget {
197198
});
198199
},
199200
),
201+
202+
// image
203+
_AddBlockMenuItemData(
204+
blockType: DividerBlockKeys.type,
205+
backgroundColor: const Color(0xFF98F4CD),
206+
text: LocaleKeys.editor_image.tr(),
207+
icon: FlowySvgs.m_toolbar_imae_lg,
208+
onTap: () async {
209+
AppGlobals.rootNavKey.currentContext?.pop(true);
210+
Future.delayed(const Duration(milliseconds: 400), () async {
211+
final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
212+
await editorState.insertEmptyImageBlock(imagePlaceholderKey);
213+
214+
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
215+
imagePlaceholderKey.currentState?.controller.show();
216+
});
217+
});
218+
},
219+
),
200220
];
201221

202222
@override
@@ -257,7 +277,7 @@ class _AddBlockMenuItem extends StatelessWidget {
257277
borderRadius: BorderRadius.circular(20),
258278
),
259279
),
260-
padding: const EdgeInsets.all(24),
280+
padding: EdgeInsets.all(20 * context.scale),
261281
child: FlowySvg(
262282
data.icon,
263283
color: Colors.black,
@@ -266,7 +286,7 @@ class _AddBlockMenuItem extends StatelessWidget {
266286
const VSpace(4),
267287
FlowyText(
268288
data.text,
269-
fontSize: 13.0,
289+
fontSize: 12.0,
270290
),
271291
],
272292
),

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ class _ToolbarItemListViewState extends State<_ToolbarItemListView> {
540540
}
541541

542542
final toolbarItems = widget.toolbarItems;
543-
final alignment = selection.isCollapsed ? 0.0 : -1.0;
543+
// use -0.4 to make sure the pilot is in the front of the toolbar item
544+
final alignment = selection.isCollapsed ? 0.0 : -0.4;
544545
final index = toolbarItems.indexWhere(
545546
(element) => selection.isCollapsed
546547
? element.pilotAtCollapsedSelection

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/keyboard_height_observer.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:appflowy/startup/tasks/prelude.dart';
12
import 'package:keyboard_height_plugin/keyboard_height_plugin.dart';
23

34
typedef KeyboardHeightCallback = void Function(double height);
@@ -32,6 +33,12 @@ class KeyboardHeightObserver {
3233
}
3334

3435
void notify(double height) {
36+
// the keyboard height will notify twice with the same value on Android 14
37+
if (DeviceInfoTask.androidSDKVersion == 34) {
38+
if (height == 0 && currentKeyboardHeight == 0) {
39+
return;
40+
}
41+
}
3542
for (final listener in _listeners) {
3643
listener(height);
3744
}

frontend/appflowy_flutter/lib/startup/startup.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class FlowyRunner {
103103
// there's a flag named _enable in memory_leak_detector.dart. If it's false, the task will be ignored.
104104
MemoryLeakDetectorTask(),
105105
const DebugTask(),
106+
const DeviceInfoTask(),
106107
// localization
107108
const InitLocalizationTask(),
108109
// init the app window

0 commit comments

Comments
 (0)