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 2e3ead4ee0..c9d7347319 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 @@ -9,7 +9,18 @@ class MultiBoardListExample extends StatefulWidget { } class _MultiBoardListExampleState extends State { - final BoardDataController boardDataController = BoardDataController(); + final BoardDataController boardDataController = BoardDataController( + onMoveColumn: (fromIndex, toIndex) { + debugPrint('Move column from $fromIndex to $toIndex'); + }, + onMoveColumnItem: (columnId, fromIndex, toIndex) { + debugPrint('Column:$columnId move item from $fromIndex to $toIndex'); + }, + onMoveColumnItemToColumn: (fromColumnId, fromIndex, toColumnId, toIndex) { + debugPrint( + 'Column:$fromColumnId move item at $fromIndex to column:$toColumnId $toIndex'); + }, + ); @override void initState() { @@ -34,9 +45,9 @@ class _MultiBoardListExampleState extends State { TextItem("D"), ]); - boardDataController.setColumnData(column1); - boardDataController.setColumnData(column2); - boardDataController.setColumnData(column3); + boardDataController.addColumn(column1); + boardDataController.addColumn(column2); + boardDataController.addColumn(column3); super.initState(); } 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 e8bfedb344..64c4871e52 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 @@ -20,7 +20,7 @@ class _SingleBoardListExampleState extends State { TextItem("d"), ]); - boardData.setColumnData(column); + boardData.addColumn(column); super.initState(); } diff --git a/frontend/app_flowy/packages/flowy_board/lib/flowy_board.dart b/frontend/app_flowy/packages/flowy_board/lib/flowy_board.dart index 16d2c612d3..c145be5440 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/flowy_board.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/flowy_board.dart @@ -1,6 +1,5 @@ library flowy_board; -export 'src/widgets/board_column/board_column.dart'; -export 'src/widgets/board_column/data_controller.dart'; -export 'src/widgets/board.dart'; +export 'src/widgets/board_column/board_column_data.dart'; export 'src/widgets/board_data.dart'; +export 'src/widgets/board.dart'; diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/utils/log.dart b/frontend/app_flowy/packages/flowy_board/lib/src/utils/log.dart index 5d39219f2e..6f923ddf16 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/utils/log.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/utils/log.dart @@ -6,7 +6,7 @@ const DART_LOG = "Dart_LOG"; class Log { // static const enableLog = bool.hasEnvironment(DART_LOG); // static final shared = Log(); - static const enableLog = true; + static const enableLog = false; static void info(String? message) { if (enableLog) { @@ -22,7 +22,7 @@ class Log { static void trace(String? message) { if (enableLog) { - debugPrint('❗️[Trace]=> $message'); + // debugPrint('❗️[Trace]=> $message'); } } } diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart index 3cce2b8b99..bef98842c0 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'board_column/board_column.dart'; +import 'board_column/board_column_data.dart'; +import 'board_data.dart'; import 'flex/drag_target_inteceptor.dart'; import 'flex/reorder_flex.dart'; import 'phantom/phantom_controller.dart'; -import '../../flowy_board.dart'; import '../rendering/board_overlay.dart'; class Board extends StatelessWidget { @@ -122,7 +124,8 @@ class BoardContent extends StatefulWidget { } class _BoardContentState extends State { - final GlobalKey _columnContainerOverlayKey = GlobalKey(debugLabel: '$BoardContent overlay key'); + final GlobalKey _columnContainerOverlayKey = + GlobalKey(debugLabel: '$BoardContent overlay key'); late BoardOverlayEntry _overlayEntry; @override @@ -215,7 +218,8 @@ class _BoardColumnDataSourceImpl extends BoardColumnDataDataSource { }); @override - BoardColumnData get columnData => dataController.columnController(columnId).columnData; + BoardColumnData get columnData => + dataController.columnController(columnId).columnData; @override List get acceptedColumnIds => dataController.columnIds; diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column.dart index 78cb78950c..f95f4dae5c 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column.dart @@ -6,7 +6,7 @@ import '../../utils/log.dart'; import '../phantom/phantom_controller.dart'; import '../flex/reorder_flex.dart'; import '../flex/drag_target_inteceptor.dart'; -import 'data_controller.dart'; +import 'board_column_data.dart'; typedef OnColumnDragStarted = void Function(int index); diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/data_controller.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column_data.dart similarity index 100% rename from frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/data_controller.dart rename to frontend/app_flowy/packages/flowy_board/lib/src/widgets/board_column/board_column_data.dart 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 0e095b1a09..a5033623fb 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 @@ -2,16 +2,33 @@ import 'dart:collection'; import 'package:equatable/equatable.dart'; -import '../../flowy_board.dart'; import '../utils/log.dart'; +import 'board_column/board_column_data.dart'; import 'flex/reorder_flex.dart'; import 'package:flutter/material.dart'; import 'phantom/phantom_controller.dart'; -@protected +typedef OnMoveColumn = void Function(int fromIndex, int toIndex); + +typedef OnMoveColumnItem = void Function( + String columnId, + int fromIndex, + int toIndex, +); + +typedef OnMoveColumnItemToColumn = void Function( + String fromColumnId, + int fromIndex, + String toColumnId, + int toIndex, +); + class BoardDataController extends ChangeNotifier with EquatableMixin, BoardPhantomControllerDelegate, ReoderFlextDataSource { final List _columnDatas = []; + final OnMoveColumn? onMoveColumn; + final OnMoveColumnItem? onMoveColumnItem; + final OnMoveColumnItemToColumn? onMoveColumnItemToColumn; List get columnDatas => _columnDatas; @@ -21,9 +38,13 @@ class BoardDataController extends ChangeNotifier final LinkedHashMap _columnControllers = LinkedHashMap(); - BoardDataController(); + BoardDataController({ + this.onMoveColumn, + this.onMoveColumnItem, + this.onMoveColumnItemToColumn, + }); - void setColumnData(BoardColumnData columnData) { + void addColumn(BoardColumnData columnData) { final controller = BoardColumnDataController(columnData: columnData); _columnDatas.add(columnData); _columnControllers[columnData.id] = controller; @@ -36,6 +57,7 @@ class BoardDataController extends ChangeNotifier void moveColumn(int fromIndex, int toIndex) { final columnData = _columnDatas.removeAt(fromIndex); _columnDatas.insert(toIndex, columnData); + onMoveColumn?.call(fromIndex, toIndex); notifyListeners(); } @@ -44,10 +66,12 @@ class BoardDataController extends ChangeNotifier assert(columnController != null); if (columnController != null) { columnController.move(fromIndex, toIndex); + onMoveColumnItem?.call(columnId, fromIndex, toIndex); } } @override + @protected void swapColumnItem( String fromColumnId, int fromColumnIndex, @@ -55,11 +79,17 @@ class BoardDataController extends ChangeNotifier int toColumnIndex, ) { final item = columnController(fromColumnId).removeAt(fromColumnIndex); - assert( columnController(toColumnId).items[toColumnIndex] is PhantomColumnItem); columnController(toColumnId).replace(toColumnIndex, item); + + onMoveColumnItemToColumn?.call( + fromColumnId, + fromColumnIndex, + toColumnId, + toColumnIndex, + ); } @override @@ -80,6 +110,7 @@ class BoardDataController extends ChangeNotifier UnmodifiableListView(_columnDatas); @override + @protected bool removePhantom(String columnId) { final columnController = this.columnController(columnId); final index = columnController.items.indexWhere((item) => item.isPhantom); @@ -95,6 +126,7 @@ class BoardDataController extends ChangeNotifier } @override + @protected void updatePhantom(String columnId, int newIndex) { final columnDataController = columnController(columnId); final index = @@ -111,6 +143,7 @@ class BoardDataController extends ChangeNotifier } @override + @protected void insertPhantom(String columnId, int index, PhantomColumnItem item) { columnController(columnId).insert(index, item); } 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 4ba0f01d18..c3b962408d 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 @@ -327,29 +327,16 @@ class _FakeDragTargetState @override void initState() { widget.insertAnimationController.addStatusListener( - (status) { - if (status != AnimationStatus.completed) return; - if (!mounted) return; - WidgetsBinding.instance.addPostFrameCallback((_) { - setState(() { - simulateDragging = true; - widget.deleteAnimationController.reverse(from: 1.0); - widget.onWillAccept(widget.eventData.dragTargetData as T); - widget.onDragStarted( - widget.child, - widget.eventData.index, - widget.eventData.feedbackSize, - ); - }); - }); - }, + _onInsertedAnimationStatusChanged, ); + /// Start insert animation widget.insertAnimationController.forward(from: 0.0); + widget.eventTrigger.fakeOnDragEnded(() { - if (mounted) { + WidgetsBinding.instance.addPostFrameCallback((_) { widget.onDragEnded(widget.eventData.dragTargetData as T); - } + }); }); super.initState(); @@ -357,17 +344,40 @@ class _FakeDragTargetState @override Widget build(BuildContext context) { - final child = IgnorePointerWidget( - useIntrinsicSize: !simulateDragging, child: widget.child); + if (simulateDragging) { + return SizeTransitionWithIntrinsicSize( + sizeFactor: widget.deleteAnimationController, + axis: Axis.vertical, + child: IgnorePointerWidget( + child: widget.child, + ), + ); + } else { + return SizeTransitionWithIntrinsicSize( + sizeFactor: widget.insertAnimationController, + axis: Axis.vertical, + child: IgnorePointerWidget( + useIntrinsicSize: true, + child: widget.child, + ), + ); + } + } - final animationController = simulateDragging - ? widget.deleteAnimationController - : widget.insertAnimationController; - - return SizeTransitionWithIntrinsicSize( - sizeFactor: animationController, - axis: Axis.vertical, - child: child, - ); + void _onInsertedAnimationStatusChanged(AnimationStatus status) { + if (status != AnimationStatus.completed) return; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + setState(() { + simulateDragging = true; + widget.deleteAnimationController.reverse(from: 1.0); + widget.onWillAccept(widget.eventData.dragTargetData as T); + widget.onDragStarted( + widget.child, + widget.eventData.index, + widget.eventData.feedbackSize, + ); + }); + }); } } diff --git a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_mixin.dart b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_mixin.dart index 1d9e764ade..a90ee6a83a 100644 --- a/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_mixin.dart +++ b/frontend/app_flowy/packages/flowy_board/lib/src/widgets/flex/reorder_mixin.dart @@ -27,8 +27,10 @@ mixin ReorderFlexMinxi { child: FadeTransition(opacity: animationController, child: child), ); - BoxConstraints contentSizeConstraints = BoxConstraints.loose(draggingFeedbackSize); - return ConstrainedBox(constraints: contentSizeConstraints, child: transition); + BoxConstraints contentSizeConstraints = + BoxConstraints.loose(draggingFeedbackSize); + return ConstrainedBox( + constraints: contentSizeConstraints, child: transition); } } @@ -56,13 +58,16 @@ mixin ReorderFlexMinxi { child: FadeTransition(opacity: animationController, child: child), ); - BoxConstraints contentSizeConstraints = BoxConstraints.loose(draggingFeedbackSize); - return ConstrainedBox(constraints: contentSizeConstraints, child: transition); + BoxConstraints contentSizeConstraints = + BoxConstraints.loose(draggingFeedbackSize); + return ConstrainedBox( + constraints: contentSizeConstraints, child: transition); } } } -Animation withCurve(AnimationController animationController, Cubic curve) { +Animation withCurve( + AnimationController animationController, Cubic curve) { return CurvedAnimation( parent: animationController, curve: curve, 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 6a5b91bdd1..9faece14f2 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 @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -import '../../../flowy_board.dart'; import '../../utils/log.dart'; +import '../board_column/board_column_data.dart'; import '../flex/drag_state.dart'; import '../flex/drag_target.dart'; import '../flex/drag_target_inteceptor.dart'; import 'phantom_state.dart'; -@protected abstract class BoardPhantomControllerDelegate { BoardColumnDataController? controller(String columnId); @@ -35,7 +34,6 @@ abstract class BoardPhantomControllerDelegate { ); } -@protected class BoardPhantomController extends OverlapDragTargetDelegate with CrossReorderFlexDragTargetDelegate { PhantomRecord? phantomRecord; @@ -95,8 +93,6 @@ class BoardPhantomController extends OverlapDragTargetDelegate /// Remove the phantom in the column if it contains phantom void _removePhantom(String columnId) { - // columnsState.notifyDidRemovePhantom(columnId); - // columnsState.removeColumnListener(columnId); if (delegate.removePhantom(columnId)) { columnsState.notifyDidRemovePhantom(columnId); columnsState.removeColumnListener(columnId); @@ -217,7 +213,6 @@ class BoardPhantomController extends OverlapDragTargetDelegate /// [toColumnId] the column that the phantom moves into /// [toColumnIndex] the index of the phantom moves into the column /// -@protected class PhantomRecord { final String fromColumnId; int fromColumnIndex; @@ -313,7 +308,6 @@ class PassthroughPhantomContext extends FakeDragTargetEventTrigger } } -@protected class PassthroughPhantomWidget extends PhantomWidget { final PassthroughPhantomContext passthroughPhantomContext; @@ -328,7 +322,6 @@ class PassthroughPhantomWidget extends PhantomWidget { ); } -@protected class PhantomDraggableBuilder extends ReorderFlexDraggableTargetBuilder { PhantomDraggableBuilder(); @override