From e592a09ec305ee6581b22f2f0c68d87e540baac8 Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 5 Aug 2022 12:09:27 +0800 Subject: [PATCH] chore: remove phantom where dragTarget disappear --- .../lib/src/widgets/flex/drag_target_inteceptor.dart | 6 ++++-- .../flowy_board/lib/src/widgets/flex/reorder_flex.dart | 2 +- .../lib/src/widgets/phantom/phantom_controller.dart | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart index 64addf7dbe..fc2fc8482c 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target_inteceptor.dart @@ -23,7 +23,9 @@ abstract class ReorderFlexDragTargetInterceptor { ReorderFlexDraggableTargetBuilder? get draggableTargetBuilder => null; } -abstract class OverlapReorderFlexDragTargetDelegate {} +abstract class OverlapReorderFlexDragTargetDelegate { + void dragTargetDidDisappear(); +} class OverlapReorderFlexDragTargetInteceptor extends ReorderFlexDragTargetInterceptor { @@ -50,7 +52,7 @@ class OverlapReorderFlexDragTargetInteceptor required String dragTargetId, required int dragTargetIndex}) { if (dragTargetId == dragTargetData.reorderFlexId) { - Log.debug('remove all phantom'); + delegate.dragTargetDidDisappear(); } else { Log.debug('add phantom to $dragTargetId'); } diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart index b451aaf0e6..6ffb310390 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_flex.dart @@ -396,7 +396,7 @@ class ReorderFlexState extends State /// The [willAccept] will be true if the dargTarget is the widget that gets /// dragged and it is dragged on top of the other dragTargets. /// - Log.debug( + Log.trace( '[$ReorderDragTarget] ${widget.dataSource.identifier} on will accept, dragIndex:$dragIndex, dragTargetIndex:$dragTargetIndex, count: ${widget.dataSource.items.length}'); bool willAccept = diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart index d04c7eca6e..92b9f31043 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/phantom/phantom_controller.dart @@ -207,6 +207,16 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate _updatePhantom(phantomRecord!.toColumnId, dragTargetIndex); } } + + @override + void dragTargetDidDisappear() { + if (phantomRecord == null) { + return; + } + + _removePhantom(phantomRecord!.toColumnId); + phantomRecord = null; + } } /// Use [PhantomRecord] to record where to remove the column item and where to