From 1ba24c00baa1610a536eca5839e57cdd72552523 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sun, 7 Aug 2022 11:17:27 +0800 Subject: [PATCH] chore: fix reset phantom record bug --- .../example/lib/multi_board_list_example.dart | 5 ++-- .../lib/single_board_list_example.dart | 2 +- .../lib/src/widgets/board_data.dart | 2 +- .../lib/src/widgets/flex/drag_target.dart | 6 ++--- .../lib/src/widgets/flex/reorder_flex.dart | 11 +++++---- .../widgets/phantom/phantom_controller.dart | 24 ++++++++----------- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_board/example/lib/multi_board_list_example.dart b/frontend/app_flowy/packages/flowy_board/example/lib/multi_board_list_example.dart index c9d7347319..95b0a64fc6 100644 --- a/frontend/app_flowy/packages/flowy_board/example/lib/multi_board_list_example.dart +++ b/frontend/app_flowy/packages/flowy_board/example/lib/multi_board_list_example.dart @@ -14,11 +14,10 @@ class _MultiBoardListExampleState extends State { debugPrint('Move column from $fromIndex to $toIndex'); }, onMoveColumnItem: (columnId, fromIndex, toIndex) { - debugPrint('Column:$columnId move item from $fromIndex to $toIndex'); + debugPrint('Move $columnId:$fromIndex to $columnId:$toIndex'); }, onMoveColumnItemToColumn: (fromColumnId, fromIndex, toColumnId, toIndex) { - debugPrint( - 'Column:$fromColumnId move item at $fromIndex to column:$toColumnId $toIndex'); + debugPrint('Move $fromColumnId:$fromIndex to $toColumnId:$toIndex'); }, ); diff --git a/frontend/app_flowy/packages/flowy_board/example/lib/single_board_list_example.dart b/frontend/app_flowy/packages/flowy_board/example/lib/single_board_list_example.dart index 64c4871e52..e508896f9f 100644 --- a/frontend/app_flowy/packages/flowy_board/example/lib/single_board_list_example.dart +++ b/frontend/app_flowy/packages/flowy_board/example/lib/single_board_list_example.dart @@ -56,5 +56,5 @@ class TextItem extends ColumnItem { TextItem(this.s); @override - String get id => throw UnimplementedError(); + String get id => s; } diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_data.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_data.dart index a5033623fb..fe2fca2c92 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_data.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_data.dart @@ -120,7 +120,7 @@ class BoardDataController extends ChangeNotifier columnController.removeAt(index); Log.debug( - '[$BoardPhantomController] Column$columnId remove phantom, current count: ${columnController.items.length}'); + '[$BoardDataController] Column$columnId remove phantom, current count: ${columnController.items.length}'); } return isExist; } diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target.dart index c3b962408d..fafdcef774 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/drag_target.dart @@ -174,7 +174,7 @@ class _ReorderDragTargetState transform: Matrix4.rotationZ(0), alignment: FractionalOffset.topLeft, child: Material( - elevation: 2.0, + elevation: 3.0, color: Colors.transparent, borderRadius: BorderRadius.zero, clipBehavior: Clip.hardEdge, @@ -212,10 +212,10 @@ class DragTargetAnimation { value: 0, vsync: vsync, duration: reorderAnimationDuration); insertController = AnimationController( - value: 0.0, vsync: vsync, duration: reorderAnimationDuration); + value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 100)); deleteController = AnimationController( - value: 0.0, vsync: vsync, duration: reorderAnimationDuration); + value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 10)); } void startDargging() { 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 f8c587d08c..9066c987f0 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 @@ -328,10 +328,13 @@ class ReorderFlexState extends State "[DragTarget]: Column${widget.dataSource.identifier} end dragging"); setState(() { - _onReordered( - dragState.dragStartIndex, - dragState.currentIndex, - ); + if (dragTargetData.reorderFlexId == widget.reorderFlexId) { + _onReordered( + dragState.dragStartIndex, + dragState.currentIndex, + ); + } + dragState.endDragging(); widget.onDragEnded?.call(); }); 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 9faece14f2..6b68eefd52 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 @@ -64,26 +64,22 @@ class BoardPhantomController extends OverlapDragTargetDelegate /// Remove the phanton in the column when the column is end dragging. void columnEndDragging(String columnId) { columnsState.setColumnIsDragging(columnId, true); - if (phantomRecord != null) { - if (phantomRecord!.fromColumnId == columnId) { - columnsState.notifyDidRemovePhantom(phantomRecord!.toColumnId); - } - } - _swapColumnData(); - } + if (phantomRecord == null) return; - void _swapColumnData() { - if (phantomRecord == null) { + final fromColumnId = phantomRecord!.fromColumnId; + final toColumnId = phantomRecord!.toColumnId; + if (fromColumnId == columnId) { + columnsState.notifyDidRemovePhantom(toColumnId); + } + + if (columnsState.isDragging(fromColumnId) == false) { return; } - if (columnsState.isDragging(phantomRecord!.fromColumnId) == false) { - return; - } delegate.swapColumnItem( - phantomRecord!.fromColumnId, + fromColumnId, phantomRecord!.fromColumnIndex, - phantomRecord!.toColumnId, + toColumnId, phantomRecord!.toColumnIndex, );