Skip to content

Commit f872391

Browse files
[SuperEditor][SuperReader][SuperTextField] Update Android toolbar. (Resolves #2791) (#2799)
1 parent d9b7785 commit f872391

File tree

21 files changed

+896
-189
lines changed

21 files changed

+896
-189
lines changed

super_clones/google_docs/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ dependencies:
1212
sdk: flutter
1313

1414
cupertino_icons: ^1.0.6
15-
follow_the_leader: ^0.0.4+7
15+
follow_the_leader: ^0.5.1
1616
super_editor:
1717
path: ../../super_editor
1818
super_text_layout:
1919
path: ../../super_text_layout
2020
google_fonts: ^6.2.1
21-
overlord: ^0.0.3+5
21+
overlord: ^0.4.2
2222

2323
dependency_overrides:
2424
# Override to local mono-repo path so devs can test this repo

super_clones/quill/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ dependencies:
1717
super_editor_markdown: any
1818
super_text_layout: any
1919
collection: ^1.18.0
20-
overlord: ^0.0.3+5
20+
overlord: ^0.4.2
2121
material_symbols_icons: ^4.2762.0
2222
dart_quill_delta: ^9.4.6
23-
follow_the_leader: ^0.0.4+8
23+
follow_the_leader: ^0.5.1
2424

2525
dependency_overrides:
2626
super_editor:

super_clones/slack/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ dependencies:
1919
git:
2020
url: https://github.com/superlistapp/super_editor.git
2121
path: super_editor_markdown
22-
follow_the_leader: ^0.0.4+2
23-
overlord: ^0.0.3+2
22+
follow_the_leader: ^0.5.1
23+
overlord: ^0.4.2
2424
markdown: ^7.2.1
2525

2626
# The following adds the Cupertino Icons font to your application.

super_editor/example/lib/demos/example_editor/_toolbar.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class _EditorToolbarState extends State<EditorToolbar> {
7575
void initState() {
7676
super.initState();
7777

78-
_toolbarAligner = CupertinoPopoverToolbarAligner(widget.editorViewportKey);
78+
_toolbarAligner = CupertinoPopoverToolbarAligner();
7979

8080
_popoverFocusNode = FocusNode();
8181

@@ -92,7 +92,6 @@ class _EditorToolbarState extends State<EditorToolbar> {
9292

9393
_screenBoundary = WidgetFollowerBoundary(
9494
boundaryKey: widget.editorViewportKey,
95-
devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
9695
);
9796
}
9897

super_editor/example/lib/demos/example_editor/example_editor.dart

Lines changed: 47 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class _ExampleEditorState extends State<ExampleEditor> {
4949
..screenPadding = const EdgeInsets.all(20.0);
5050

5151
late final SuperEditorIosControlsController _iosControlsController;
52+
late final SuperEditorAndroidControlsController _androidControlsController;
5253

5354
@override
5455
void initState() {
@@ -67,11 +68,13 @@ class _ExampleEditorState extends State<ExampleEditor> {
6768
_scrollController = ScrollController()..addListener(_hideOrShowToolbar);
6869

6970
_iosControlsController = SuperEditorIosControlsController();
71+
_androidControlsController = SuperEditorAndroidControlsController();
7072
}
7173

7274
@override
7375
void dispose() {
7476
_iosControlsController.dispose();
77+
_androidControlsController.dispose();
7578
_scrollController.dispose();
7679
_editorFocusNode.dispose();
7780
_composer.dispose();
@@ -210,29 +213,6 @@ class _ExampleEditorState extends State<ExampleEditor> {
210213
}
211214
}
212215

213-
void _cut() {
214-
_docOps.cut();
215-
// TODO: get rid of overlay controller once Android is refactored to use a control scope (as follow up to: https://github.com/superlistapp/super_editor/pull/1470)
216-
_overlayController.hideToolbar();
217-
_iosControlsController.hideToolbar();
218-
}
219-
220-
void _copy() {
221-
_docOps.copy();
222-
// TODO: get rid of overlay controller once Android is refactored to use a control scope (as follow up to: https://github.com/superlistapp/super_editor/pull/1470)
223-
_overlayController.hideToolbar();
224-
_iosControlsController.hideToolbar();
225-
}
226-
227-
void _paste() {
228-
_docOps.paste();
229-
// TODO: get rid of overlay controller once Android is refactored to use a control scope (as follow up to: https://github.com/superlistapp/super_editor/pull/1470)
230-
_overlayController.hideToolbar();
231-
_iosControlsController.hideToolbar();
232-
}
233-
234-
void _selectAll() => _docOps.selectAll();
235-
236216
void _showImageToolbar() {
237217
// Schedule a callback after this frame to locate the selection
238218
// bounds on the screen and display the toolbar near the selected
@@ -388,74 +368,60 @@ class _ExampleEditorState extends State<ExampleEditor> {
388368
config: _debugConfig ?? const SuperEditorDebugVisualsConfig(),
389369
child: KeyedSubtree(
390370
key: _viewportKey,
391-
child: SuperEditorIosControlsScope(
392-
controller: _iosControlsController,
393-
child: SuperEditor(
394-
editor: _docEditor,
395-
focusNode: _editorFocusNode,
396-
scrollController: _scrollController,
397-
documentLayoutKey: _docLayoutKey,
398-
documentOverlayBuilders: [
399-
DefaultCaretOverlayBuilder(
400-
caretStyle: const CaretStyle().copyWith(color: isLight ? Colors.black : Colors.redAccent),
401-
),
402-
if (defaultTargetPlatform == TargetPlatform.iOS) ...[
403-
SuperEditorIosHandlesDocumentLayerBuilder(),
404-
SuperEditorIosToolbarFocalPointDocumentLayerBuilder(),
405-
],
406-
if (defaultTargetPlatform == TargetPlatform.android) ...[
407-
SuperEditorAndroidToolbarFocalPointDocumentLayerBuilder(),
408-
SuperEditorAndroidHandlesDocumentLayerBuilder(),
371+
child: SuperEditorAndroidControlsScope(
372+
controller: _androidControlsController,
373+
child: SuperEditorIosControlsScope(
374+
controller: _iosControlsController,
375+
child: SuperEditor(
376+
editor: _docEditor,
377+
focusNode: _editorFocusNode,
378+
scrollController: _scrollController,
379+
documentLayoutKey: _docLayoutKey,
380+
documentOverlayBuilders: [
381+
DefaultCaretOverlayBuilder(
382+
caretStyle: const CaretStyle().copyWith(color: isLight ? Colors.black : Colors.redAccent),
383+
),
384+
if (defaultTargetPlatform == TargetPlatform.iOS) ...[
385+
SuperEditorIosHandlesDocumentLayerBuilder(),
386+
SuperEditorIosToolbarFocalPointDocumentLayerBuilder(),
387+
],
388+
if (defaultTargetPlatform == TargetPlatform.android) ...[
389+
SuperEditorAndroidToolbarFocalPointDocumentLayerBuilder(),
390+
SuperEditorAndroidHandlesDocumentLayerBuilder(),
391+
],
409392
],
410-
],
411-
selectionLayerLinks: _selectionLayerLinks,
412-
selectionStyle: isLight
413-
? defaultSelectionStyle
414-
: SelectionStyles(
415-
selectionColor: Colors.red.withValues(alpha: 0.3),
416-
),
417-
stylesheet: defaultStylesheet.copyWith(
418-
addRulesAfter: [
419-
if (!isLight) ..._darkModeStyles,
420-
taskStyles,
393+
selectionLayerLinks: _selectionLayerLinks,
394+
selectionStyle: isLight
395+
? defaultSelectionStyle
396+
: SelectionStyles(
397+
selectionColor: Colors.red.withValues(alpha: 0.3),
398+
),
399+
stylesheet: defaultStylesheet.copyWith(
400+
addRulesAfter: [
401+
if (!isLight) ..._darkModeStyles,
402+
taskStyles,
403+
],
404+
),
405+
componentBuilders: [
406+
TaskComponentBuilder(_docEditor),
407+
...defaultComponentBuilders,
421408
],
409+
gestureMode: _gestureMode,
410+
inputSource: _inputSource,
411+
keyboardActions:
412+
_inputSource == TextInputSource.ime ? defaultImeKeyboardActions : defaultKeyboardActions,
413+
overlayController: _overlayController,
414+
plugins: {
415+
MarkdownInlineUpstreamSyntaxPlugin(),
416+
},
422417
),
423-
componentBuilders: [
424-
TaskComponentBuilder(_docEditor),
425-
...defaultComponentBuilders,
426-
],
427-
gestureMode: _gestureMode,
428-
inputSource: _inputSource,
429-
keyboardActions: _inputSource == TextInputSource.ime ? defaultImeKeyboardActions : defaultKeyboardActions,
430-
androidToolbarBuilder: (_) => _buildAndroidFloatingToolbar(),
431-
overlayController: _overlayController,
432-
plugins: {
433-
MarkdownInlineUpstreamSyntaxPlugin(),
434-
},
435418
),
436419
),
437420
),
438421
),
439422
);
440423
}
441424

442-
Widget _buildAndroidFloatingToolbar() {
443-
return ListenableBuilder(
444-
listenable: _brightness,
445-
builder: (context, _) {
446-
return Theme(
447-
data: ThemeData(brightness: _brightness.value),
448-
child: AndroidTextEditingFloatingToolbar(
449-
onCutPressed: _cut,
450-
onCopyPressed: _copy,
451-
onPastePressed: _paste,
452-
onSelectAllPressed: _selectAll,
453-
),
454-
);
455-
},
456-
);
457-
}
458-
459425
Widget _buildMountedToolbar() {
460426
return MultiListenableBuilder(
461427
listenables: <Listenable>{

super_editor/example/lib/demos/in_the_lab/selected_text_colors_demo.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ class ColorPickerPopoverModal extends StatelessWidget {
229229
followerAnchor: Alignment.centerRight,
230230
offset: Offset(-24, 0),
231231
),
232-
boundary: ScreenFollowerBoundary(
233-
screenSize: MediaQuery.sizeOf(context),
234-
devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
235-
),
232+
boundary: const ScreenFollowerBoundary(),
236233
child: CupertinoPopoverMenu(
237234
focalPoint: LeaderMenuFocalPoint(link: leaderLink),
238235
backgroundColor: const Color(0xFF111111),

super_editor/example/lib/demos/interaction_spot_checks/toolbar_following_content_in_layer.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ class _ToolbarFollowingContentInLayerState extends State<ToolbarFollowingContent
9797
link: _leaderLink,
9898
boundary: WidgetFollowerBoundary(
9999
boundaryKey: _viewportKey,
100-
devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
101100
),
102101
child: Follower.withAligner(
103102
link: _leaderLink,
104-
aligner: CupertinoPopoverToolbarAligner(_viewportKey),
103+
aligner: CupertinoPopoverToolbarAligner(),
105104
child: CupertinoPopoverToolbar(
106105
focalPoint: LeaderMenuFocalPoint(link: _leaderLink),
107106
children: [

super_editor/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ dependencies:
5454
url: https://github.com/superlistapp/super_editor.git
5555
path: super_text_layout
5656
super_keyboard: ^0.2.0
57-
follow_the_leader: 0.0.4+8
58-
overlord: 0.0.3+5
57+
follow_the_leader: 0.5.1
58+
overlord: 0.4.2
5959

6060
dependency_overrides:
6161
# Override to local mono-repo path so devs can test this repo

super_editor/lib/src/default_editor/document_gestures_touch_android.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ class SuperEditorAndroidControlsOverlayManager extends StatefulWidget {
13761376

13771377
@visibleForTesting
13781378
class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAndroidControlsOverlayManager> {
1379+
final _boundsKey = GlobalKey();
13791380
final _overlayController = OverlayPortalController();
13801381

13811382
SuperEditorAndroidControlsController? _controlsController;
@@ -1435,8 +1436,11 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
14351436
super.didChangeDependencies();
14361437

14371438
_controlsController = SuperEditorAndroidControlsScope.rootOf(context);
1438-
// TODO: Replace Cupertino aligner with a generic aligner because this code runs on Android.
1439-
_toolbarAligner = CupertinoPopoverToolbarAligner();
1439+
// TODO: Replace CupertinoPopoverToolbarAligner aligner with a generic aligner because this code runs on Android.
1440+
_toolbarAligner = CupertinoPopoverToolbarAligner(
1441+
toolbarVerticalOffsetAbove: 20,
1442+
toolbarVerticalOffsetBelow: 90,
1443+
);
14401444
widget.selection.addListener(_onSelectionChange);
14411445
}
14421446

@@ -1736,6 +1740,7 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
17361740
return TapRegion(
17371741
groupId: widget.tapRegionGroupId,
17381742
child: Stack(
1743+
key: _boundsKey,
17391744
children: [
17401745
_buildMagnifierFocalPoint(),
17411746
if (widget.showDebugPaint) //
@@ -1912,10 +1917,7 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
19121917
child: Follower.withAligner(
19131918
link: _controlsController!.toolbarFocalPoint,
19141919
aligner: _toolbarAligner,
1915-
boundary: ScreenFollowerBoundary(
1916-
screenSize: MediaQuery.sizeOf(context),
1917-
devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
1918-
),
1920+
boundary: const ScreenFollowerBoundary(),
19191921
child: _toolbarBuilder(context, DocumentKeys.mobileToolbar, _controlsController!.toolbarFocalPoint),
19201922
),
19211923
);
@@ -1980,10 +1982,7 @@ class SuperEditorAndroidControlsOverlayManagerState extends State<SuperEditorAnd
19801982
offset: Offset(0, -54 * devicePixelRatio),
19811983
leaderAnchor: Alignment.center,
19821984
followerAnchor: Alignment.center,
1983-
boundary: ScreenFollowerBoundary(
1984-
screenSize: MediaQuery.sizeOf(context),
1985-
devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
1986-
),
1985+
boundary: const ScreenFollowerBoundary(),
19871986
child: AndroidMagnifyingGlass(
19881987
key: magnifierKey,
19891988
magnificationScale: 1.5,

super_editor/lib/src/default_editor/super_editor.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ class SuperEditorState extends State<SuperEditor> {
866866
editContext.commonOps,
867867
SuperEditorAndroidControlsScope.rootOf(context),
868868
editContext.composer.selectionNotifier,
869+
focalPoint,
869870
),
870871
child: child,
871872
);
@@ -1042,9 +1043,11 @@ Widget defaultAndroidEditorToolbarBuilder(
10421043
CommonEditorOperations editorOps,
10431044
SuperEditorAndroidControlsController editorControlsController,
10441045
ValueListenable<DocumentSelection?> selectionNotifier,
1046+
LeaderLink focalPoint,
10451047
) {
10461048
return DefaultAndroidEditorToolbar(
10471049
floatingToolbarKey: floatingToolbarKey,
1050+
focalPoint: focalPoint,
10481051
editorOps: editorOps,
10491052
editorControlsController: editorControlsController,
10501053
selectionNotifier: selectionNotifier,
@@ -1059,9 +1062,11 @@ class DefaultAndroidEditorToolbar extends StatelessWidget {
10591062
required this.editorOps,
10601063
required this.editorControlsController,
10611064
required this.selectionNotifier,
1065+
required this.focalPoint,
10621066
});
10631067

10641068
final Key? floatingToolbarKey;
1069+
final LeaderLink focalPoint;
10651070
final CommonEditorOperations editorOps;
10661071
final SuperEditorAndroidControlsController editorControlsController;
10671072
final ValueListenable<DocumentSelection?> selectionNotifier;
@@ -1073,6 +1078,7 @@ class DefaultAndroidEditorToolbar extends StatelessWidget {
10731078
builder: (context, selection, child) {
10741079
return AndroidTextEditingFloatingToolbar(
10751080
floatingToolbarKey: floatingToolbarKey,
1081+
focalPoint: focalPoint,
10761082
onCopyPressed: selection == null || !selection.isCollapsed //
10771083
? _copy
10781084
: null,

0 commit comments

Comments
 (0)