Skip to content

Commit

Permalink
fix: remove flutter overlay (AppFlowy-IO#358)
Browse files Browse the repository at this point in the history
* fix: remove flutter overlay

* fix: hide toolbar if selection is not visible

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
  • Loading branch information
Xazin and LucasXu0 authored Aug 29, 2023
1 parent 7a03439 commit 81fbb40
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 972 deletions.
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
3 changes: 1 addition & 2 deletions lib/src/editor/editor_component/service/editor.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/flutter/overlay.dart';
import 'package:appflowy_editor/src/service/context_menu/built_in_context_menu_item.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

// workaround for the issue:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry, OverlayState;
import 'package:flutter/material.dart';

class EditorService {
// selection service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/flutter/overlay.dart';
import 'package:appflowy_editor/src/render/selection/cursor_widget.dart';
import 'package:appflowy_editor/src/render/selection/selection_widget.dart';
import 'package:appflowy_editor/src/service/selection/selection_gesture.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class DesktopSelectionServiceWidget extends StatefulWidget {
Expand Down Expand Up @@ -362,7 +361,7 @@ class _DesktopSelectionServiceWidgetState
);
_selectionAreas.add(overlay);

Overlay.of(context)?.insertAll(_selectionAreas);
Overlay.of(context).insertAll(_selectionAreas);
}

void _updateSelectionAreas(Selection selection) {
Expand Down Expand Up @@ -479,7 +478,7 @@ class _DesktopSelectionServiceWidgetState
}

final overlay = Overlay.of(context);
overlay?.insertAll(
overlay.insertAll(
_selectionAreas,
);
}
Expand Down Expand Up @@ -514,7 +513,7 @@ class _DesktopSelectionServiceWidgetState

_cursorAreas.add(cursorArea);
selectionRects.add(selectable.transformRectToGlobal(cursorRect));
Overlay.of(context)?.insertAll(_cursorAreas);
Overlay.of(context).insertAll(_cursorAreas);

_forceShowCursor();
}
Expand Down Expand Up @@ -564,7 +563,7 @@ class _DesktopSelectionServiceWidgetState
);

_contextMenuAreas.add(contextMenu);
Overlay.of(context)?.insert(contextMenu);
Overlay.of(context).insert(contextMenu);
}

Node? _getNodeInOffset(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/flutter/overlay.dart';
import 'package:appflowy_editor/src/render/selection/mobile_selection_widget.dart';
import 'package:appflowy_editor/src/service/selection/mobile_selection_gesture.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;

import 'package:appflowy_editor/src/render/selection/cursor_widget.dart';
import 'package:appflowy_editor/src/render/selection/selection_widget.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -368,7 +367,7 @@ class _MobileSelectionServiceWidgetState
);
_selectionAreas.add(overlay);

Overlay.of(context)?.insertAll(_selectionAreas);
Overlay.of(context).insertAll(_selectionAreas);
}

void _updateSelectionAreas(Selection selection) {
Expand Down Expand Up @@ -445,8 +444,7 @@ class _MobileSelectionServiceWidgetState
}
}

final overlay = Overlay.of(context);
overlay?.insertAll(
Overlay.of(context).insertAll(
_selectionAreas,
);
}
Expand Down Expand Up @@ -481,7 +479,7 @@ class _MobileSelectionServiceWidgetState

_cursorAreas.add(cursorArea);
selectionRects.add(selectable.transformRectToGlobal(cursorRect));
Overlay.of(context)?.insertAll(_cursorAreas);
Overlay.of(context).insertAll(_cursorAreas);

_forceShowCursor();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/material.dart';

import 'package:appflowy_editor/src/core/document/node.dart';
import 'package:appflowy_editor/src/core/location/position.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/desktop_selection_service.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
import 'package:flutter/material.dart';

class SelectionServiceWidget extends StatefulWidget {
const SelectionServiceWidget({
Expand Down
16 changes: 16 additions & 0 deletions lib/src/editor/editor_component/service/toolbar_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

abstract class AppFlowyToolbarService {
/// Show the toolbar widget beside the offset.
void showInOffset(
Offset offset,
Alignment alignment,
LayerLink layerLink,
);

/// Hide the toolbar widget.
void hide();

/// Trigger the specified handler.
bool triggerHandler(String id);
}
4 changes: 4 additions & 0 deletions lib/src/editor/toolbar/desktop/floating_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class _FloatingToolbarState extends State<FloatingToolbar>

final rect = _findSuitableRect(rects);
final (left, top, right) = calculateToolbarOffset(rect);
// if the selection is not visible, then don't show the toolbar.
if (top <= floatingToolbarHeight || (left == 0 && right == 0)) {
return;
}
_toolbarContainer = OverlayEntry(
builder: (context) {
return Positioned(
Expand Down
Loading

0 comments on commit 81fbb40

Please sign in to comment.