mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add documentation
This commit is contained in:
parent
a0d7f114c0
commit
3977925e8a
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../rendering/board_overlay.dart';
|
import '../../rendering/board_overlay.dart';
|
||||||
import '../../utils/log.dart';
|
|
||||||
import '../phantom/phantom_controller.dart';
|
import '../phantom/phantom_controller.dart';
|
||||||
import '../flex/reorder_flex.dart';
|
import '../flex/reorder_flex.dart';
|
||||||
import '../flex/drag_target_inteceptor.dart';
|
import '../flex/drag_target_inteceptor.dart';
|
||||||
@ -110,7 +109,7 @@ class _BoardColumnWidgetState extends State<BoardColumnWidget> {
|
|||||||
onDragEnded: () {
|
onDragEnded: () {
|
||||||
widget.phantomController.columnEndDragging(widget.columnId);
|
widget.phantomController.columnEndDragging(widget.columnId);
|
||||||
widget.onDragEnded?.call(widget.columnId);
|
widget.onDragEnded?.call(widget.columnId);
|
||||||
_printItems(widget.dataController);
|
widget.dataController.debugPrintItems();
|
||||||
},
|
},
|
||||||
dataSource: widget.dataController,
|
dataSource: widget.dataController,
|
||||||
interceptor: interceptor,
|
interceptor: interceptor,
|
||||||
@ -151,12 +150,3 @@ class _BoardColumnWidgetState extends State<BoardColumnWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _printItems(BoardColumnDataController dataController) {
|
|
||||||
String msg = 'Column${dataController.columnData} data: ';
|
|
||||||
for (var element in dataController.items) {
|
|
||||||
msg = '$msg$element,';
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.debug(msg);
|
|
||||||
}
|
|
||||||
|
@ -37,7 +37,8 @@ class BoardColumnData extends ReoderFlexItem with EquatableMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BoardColumnDataController extends ChangeNotifier with EquatableMixin, ReoderFlextDataSource {
|
class BoardColumnDataController extends ChangeNotifier
|
||||||
|
with EquatableMixin, ReoderFlextDataSource {
|
||||||
final BoardColumnData columnData;
|
final BoardColumnData columnData;
|
||||||
|
|
||||||
BoardColumnDataController({
|
BoardColumnDataController({
|
||||||
@ -60,14 +61,16 @@ class BoardColumnDataController extends ChangeNotifier with EquatableMixin, Reod
|
|||||||
if (fromIndex == toIndex) {
|
if (fromIndex == toIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.debug('[$BoardColumnDataController] $columnData move item from $fromIndex to $toIndex');
|
Log.debug(
|
||||||
|
'[$BoardColumnDataController] $columnData move item from $fromIndex to $toIndex');
|
||||||
final item = columnData._items.removeAt(fromIndex);
|
final item = columnData._items.removeAt(fromIndex);
|
||||||
columnData._items.insert(toIndex, item);
|
columnData._items.insert(toIndex, item);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(int index, ColumnItem item, {bool notify = true}) {
|
void insert(int index, ColumnItem item, {bool notify = true}) {
|
||||||
Log.debug('[$BoardColumnDataController] $columnData insert $item at $index');
|
Log.debug(
|
||||||
|
'[$BoardColumnDataController] $columnData insert $item at $index');
|
||||||
columnData._items.insert(index, item);
|
columnData._items.insert(index, item);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -77,10 +80,20 @@ class BoardColumnDataController extends ChangeNotifier with EquatableMixin, Reod
|
|||||||
void replace(int index, ColumnItem item) {
|
void replace(int index, ColumnItem item) {
|
||||||
final removedItem = columnData._items.removeAt(index);
|
final removedItem = columnData._items.removeAt(index);
|
||||||
columnData._items.insert(index, item);
|
columnData._items.insert(index, item);
|
||||||
Log.debug('[$BoardColumnDataController] $columnData replace $removedItem with $item at $index');
|
Log.debug(
|
||||||
|
'[$BoardColumnDataController] $columnData replace $removedItem with $item at $index');
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debugPrintItems() {
|
||||||
|
String msg = '[$BoardColumnDataController] $columnData data: ';
|
||||||
|
for (var element in items) {
|
||||||
|
msg = '$msg$element,';
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.debug(msg);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<ColumnItem> get items => UnmodifiableListView(columnData._items);
|
List<ColumnItem> get items => UnmodifiableListView(columnData._items);
|
||||||
|
|
||||||
|
@ -4,18 +4,23 @@ import '../../utils/log.dart';
|
|||||||
import 'drag_target.dart';
|
import 'drag_target.dart';
|
||||||
import 'reorder_flex.dart';
|
import 'reorder_flex.dart';
|
||||||
|
|
||||||
/// [FlexDragTargetData] is used to store the custom dragging data. It can be used to
|
/// [FlexDragTargetData] is used to store the custom dragging data.
|
||||||
/// locate the index of the dragging widget in the [BoardList].
|
///
|
||||||
|
/// * [draggingIndex] the index of the dragTarget that is being dragged.
|
||||||
|
/// * [draggingWidget] the widget of the dragTarget that is being dragged.
|
||||||
|
/// * [reorderFlexId] the id of the [ReorderFlex]
|
||||||
|
/// * [reorderFlexItem] the item of the [ReorderFlex]
|
||||||
|
///
|
||||||
class FlexDragTargetData extends DragTargetData {
|
class FlexDragTargetData extends DragTargetData {
|
||||||
/// The index of the dragging target in the boardList.
|
/// The index of the dragging target in the boardList.
|
||||||
@override
|
@override
|
||||||
final int draggingIndex;
|
final int draggingIndex;
|
||||||
|
|
||||||
final DraggingState state;
|
final DraggingState _state;
|
||||||
|
|
||||||
Widget? get draggingWidget => state.draggingWidget;
|
Widget? get draggingWidget => _state.draggingWidget;
|
||||||
|
|
||||||
Size? get feedbackSize => state.feedbackSize;
|
Size? get feedbackSize => _state.feedbackSize;
|
||||||
|
|
||||||
final String dragTargetId;
|
final String dragTargetId;
|
||||||
|
|
||||||
@ -28,8 +33,8 @@ class FlexDragTargetData extends DragTargetData {
|
|||||||
required this.draggingIndex,
|
required this.draggingIndex,
|
||||||
required this.reorderFlexId,
|
required this.reorderFlexId,
|
||||||
required this.reorderFlexItem,
|
required this.reorderFlexItem,
|
||||||
required this.state,
|
required DraggingState state,
|
||||||
});
|
}) : _state = state;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -13,9 +13,14 @@ abstract class ReorderFlexDraggableTargetBuilder {
|
|||||||
DragTargetWillAccpet<T> onWillAccept);
|
DragTargetWillAccpet<T> onWillAccept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
typedef DragTargetWillAccpet<T extends DragTargetData> = bool Function(
|
typedef DragTargetWillAccpet<T extends DragTargetData> = bool Function(
|
||||||
T dragTargetData);
|
T dragTargetData);
|
||||||
|
|
||||||
|
///
|
||||||
typedef DragTargetOnStarted = void Function(Widget, int, Size?);
|
typedef DragTargetOnStarted = void Function(Widget, int, Size?);
|
||||||
|
|
||||||
|
///
|
||||||
typedef DragTargetOnEnded<T extends DragTargetData> = void Function(
|
typedef DragTargetOnEnded<T extends DragTargetData> = void Function(
|
||||||
T dragTargetData);
|
T dragTargetData);
|
||||||
|
|
||||||
|
@ -50,7 +50,9 @@ class OverlapReorderFlexDragTargetInteceptor
|
|||||||
required String dragTargetId,
|
required String dragTargetId,
|
||||||
required int dragTargetIndex}) {
|
required int dragTargetIndex}) {
|
||||||
if (dragTargetId == dragTargetData.reorderFlexId) {
|
if (dragTargetId == dragTargetData.reorderFlexId) {
|
||||||
// Log.debug('remove all phantom');
|
Log.debug('remove all phantom');
|
||||||
|
} else {
|
||||||
|
Log.debug('add phantom to $dragTargetId');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -58,6 +60,7 @@ class OverlapReorderFlexDragTargetInteceptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class CrossReorderFlexDragTargetDelegate {
|
abstract class CrossReorderFlexDragTargetDelegate {
|
||||||
|
/// * [reorderFlexId] is the id that the [ReorderFlex] passed in.
|
||||||
bool acceptNewDragTargetData(
|
bool acceptNewDragTargetData(
|
||||||
String reorderFlexId,
|
String reorderFlexId,
|
||||||
FlexDragTargetData dragTargetData,
|
FlexDragTargetData dragTargetData,
|
||||||
@ -66,7 +69,6 @@ abstract class CrossReorderFlexDragTargetDelegate {
|
|||||||
|
|
||||||
void updateDragTargetData(
|
void updateDragTargetData(
|
||||||
String reorderFlexId,
|
String reorderFlexId,
|
||||||
FlexDragTargetData dragTargetData,
|
|
||||||
int dragTargetIndex,
|
int dragTargetIndex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -129,16 +131,8 @@ class CrossReorderFlexDragTargetInterceptor
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isNewDragTarget == false) {
|
if (isNewDragTarget == false) {
|
||||||
delegate.updateDragTargetData(
|
delegate.updateDragTargetData(reorderFlexId, dragTargetIndex);
|
||||||
reorderFlexId,
|
reorderFlexState.handleOnWillAccept(context, dragTargetIndex);
|
||||||
dragTargetData,
|
|
||||||
dragTargetIndex,
|
|
||||||
);
|
|
||||||
|
|
||||||
reorderFlexState.handleOnWillAccept(
|
|
||||||
context,
|
|
||||||
dragTargetIndex,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,7 +20,7 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
|
|
||||||
PhantomRecord? phantomRecord;
|
PhantomRecord? phantomRecord;
|
||||||
|
|
||||||
final columnsState = ColumnPassthroughStateController();
|
final columnsState = ColumnPhantomStateController();
|
||||||
|
|
||||||
BoardPhantomController({required this.delegate});
|
BoardPhantomController({required this.delegate});
|
||||||
|
|
||||||
@ -79,9 +79,11 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
phantomRecord = null;
|
phantomRecord = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the column's phantom index if it exists.
|
||||||
|
/// [toColumnId] the id of the column
|
||||||
|
/// [dragTargetIndex] the index of the dragTarget
|
||||||
void _updatePhantom(
|
void _updatePhantom(
|
||||||
String toColumnId,
|
String toColumnId,
|
||||||
FlexDragTargetData dragTargetData,
|
|
||||||
int dragTargetIndex,
|
int dragTargetIndex,
|
||||||
) {
|
) {
|
||||||
final columnDataController = delegate.controller(toColumnId);
|
final columnDataController = delegate.controller(toColumnId);
|
||||||
@ -99,6 +101,7 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove the phantom in the column if it contains phantom
|
||||||
void _removePhantom(String columnId) {
|
void _removePhantom(String columnId) {
|
||||||
final index = delegate
|
final index = delegate
|
||||||
.controller(columnId)
|
.controller(columnId)
|
||||||
@ -118,45 +121,51 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Insert the phantom into column
|
||||||
|
///
|
||||||
|
/// * [toColumnId] id of the column
|
||||||
|
/// * [phantomIndex] the phantom occupies index
|
||||||
void _insertPhantom(
|
void _insertPhantom(
|
||||||
String toColumnId,
|
String toColumnId,
|
||||||
FlexDragTargetData dragTargetData,
|
FlexDragTargetData dragTargetData,
|
||||||
int phantomIndex,
|
int phantomIndex,
|
||||||
) {
|
) {
|
||||||
final items = delegate.controller(toColumnId)?.items;
|
|
||||||
if (items == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final phantomContext = PassthroughPhantomContext(
|
final phantomContext = PassthroughPhantomContext(
|
||||||
index: phantomIndex,
|
index: phantomIndex,
|
||||||
dragTargetData: dragTargetData,
|
dragTargetData: dragTargetData,
|
||||||
);
|
);
|
||||||
columnsState.addColumnListener(toColumnId, phantomContext);
|
columnsState.addColumnListener(toColumnId, phantomContext);
|
||||||
Log.debug('$phantomContext');
|
|
||||||
delegate
|
delegate
|
||||||
.controller(toColumnId)
|
.controller(toColumnId)
|
||||||
?.insert(phantomIndex, PhantomColumnItem(phantomContext));
|
?.insert(phantomIndex, PhantomColumnItem(phantomContext));
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
Future.delayed(const Duration(milliseconds: 100), () {
|
Future.delayed(const Duration(milliseconds: 100), () {
|
||||||
|
Log.debug(
|
||||||
|
'[$BoardPhantomController] notify $toColumnId to insert phantom');
|
||||||
columnsState.notifyDidInsertPhantom(toColumnId);
|
columnsState.notifyDidInsertPhantom(toColumnId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updatePhantomRecord(
|
/// Reset or initial the [PhantomRecord]
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// * [columnId] the id of the column
|
||||||
|
/// * [dragTargetData]
|
||||||
|
/// * [dragTargetIndex]
|
||||||
|
///
|
||||||
|
void _resetPhantomRecord(
|
||||||
String columnId,
|
String columnId,
|
||||||
FlexDragTargetData dragTargetData,
|
FlexDragTargetData dragTargetData,
|
||||||
int index,
|
int dragTargetIndex,
|
||||||
) {
|
) {
|
||||||
// Log.debug('[$BoardPhantomController] move Column${dragTargetData.reorderFlexId}:${dragTargetData.draggingIndex} '
|
// Log.debug('[$BoardPhantomController] move Column${dragTargetData.reorderFlexId}:${dragTargetData.draggingIndex} '
|
||||||
// 'to Column$columnId:$index');
|
// 'to Column$columnId:$index');
|
||||||
|
|
||||||
phantomRecord = PhantomRecord(
|
phantomRecord = PhantomRecord(
|
||||||
toColumnId: columnId,
|
toColumnId: columnId,
|
||||||
toColumnIndex: index,
|
toColumnIndex: dragTargetIndex,
|
||||||
item: dragTargetData.reorderFlexItem as ColumnItem,
|
|
||||||
fromColumnId: dragTargetData.reorderFlexId,
|
fromColumnId: dragTargetData.reorderFlexId,
|
||||||
fromColumnIndex: dragTargetData.draggingIndex,
|
fromColumnIndex: dragTargetData.draggingIndex,
|
||||||
);
|
);
|
||||||
@ -170,18 +179,15 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
int dragTargetIndex,
|
int dragTargetIndex,
|
||||||
) {
|
) {
|
||||||
if (phantomRecord == null) {
|
if (phantomRecord == null) {
|
||||||
_updatePhantomRecord(reorderFlexId, dragTargetData, dragTargetIndex);
|
_resetPhantomRecord(reorderFlexId, dragTargetData, dragTargetIndex);
|
||||||
_insertPhantom(reorderFlexId, dragTargetData, dragTargetIndex);
|
_insertPhantom(reorderFlexId, dragTargetData, dragTargetIndex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final isNewDragTarget = phantomRecord!.toColumnId != reorderFlexId;
|
final isNewDragTarget = phantomRecord!.toColumnId != reorderFlexId;
|
||||||
if (isNewDragTarget) {
|
if (isNewDragTarget) {
|
||||||
/// Remove the phantom in the previous column.
|
|
||||||
_removePhantom(phantomRecord!.toColumnId);
|
_removePhantom(phantomRecord!.toColumnId);
|
||||||
|
_resetPhantomRecord(reorderFlexId, dragTargetData, dragTargetIndex);
|
||||||
/// Update the record and insert the phantom to new column.
|
|
||||||
_updatePhantomRecord(reorderFlexId, dragTargetData, dragTargetIndex);
|
|
||||||
_insertPhantom(reorderFlexId, dragTargetData, dragTargetIndex);
|
_insertPhantom(reorderFlexId, dragTargetData, dragTargetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +197,6 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
@override
|
@override
|
||||||
void updateDragTargetData(
|
void updateDragTargetData(
|
||||||
String reorderFlexId,
|
String reorderFlexId,
|
||||||
FlexDragTargetData dragTargetData,
|
|
||||||
int dragTargetIndex,
|
int dragTargetIndex,
|
||||||
) {
|
) {
|
||||||
phantomRecord?.updateInsertedIndex(dragTargetIndex);
|
phantomRecord?.updateInsertedIndex(dragTargetIndex);
|
||||||
@ -199,14 +204,20 @@ class BoardPhantomController extends OverlapReorderFlexDragTargetDelegate
|
|||||||
assert(phantomRecord != null);
|
assert(phantomRecord != null);
|
||||||
if (phantomRecord!.toColumnId == reorderFlexId) {
|
if (phantomRecord!.toColumnId == reorderFlexId) {
|
||||||
/// Update the existing phantom index
|
/// Update the existing phantom index
|
||||||
_updatePhantom(
|
_updatePhantom(phantomRecord!.toColumnId, dragTargetIndex);
|
||||||
phantomRecord!.toColumnId, dragTargetData, dragTargetIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use [PhantomRecord] to record where to remove the column item and where to
|
||||||
|
/// insert the column item.
|
||||||
|
///
|
||||||
|
/// [fromColumnId] the column that phantom comes from
|
||||||
|
/// [fromColumnIndex] the index of the phantom from the original column
|
||||||
|
/// [toColumnId] the column that the phantom moves into
|
||||||
|
/// [toColumnIndex] the index of the phantom moves into the column
|
||||||
|
///
|
||||||
class PhantomRecord {
|
class PhantomRecord {
|
||||||
final ColumnItem item;
|
|
||||||
final String fromColumnId;
|
final String fromColumnId;
|
||||||
int fromColumnIndex;
|
int fromColumnIndex;
|
||||||
|
|
||||||
@ -214,7 +225,6 @@ class PhantomRecord {
|
|||||||
int toColumnIndex;
|
int toColumnIndex;
|
||||||
|
|
||||||
PhantomRecord({
|
PhantomRecord({
|
||||||
required this.item,
|
|
||||||
required this.toColumnId,
|
required this.toColumnId,
|
||||||
required this.toColumnIndex,
|
required this.toColumnIndex,
|
||||||
required this.fromColumnId,
|
required this.fromColumnId,
|
||||||
@ -274,7 +284,7 @@ class PassthroughPhantomContext extends FakeDragTargetEventTrigger
|
|||||||
final FlexDragTargetData dragTargetData;
|
final FlexDragTargetData dragTargetData;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Size? get feedbackSize => dragTargetData.state.feedbackSize;
|
Size? get feedbackSize => dragTargetData.feedbackSize;
|
||||||
|
|
||||||
Widget? get draggingWidget => dragTargetData.draggingWidget;
|
Widget? get draggingWidget => dragTargetData.draggingWidget;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'phantom_controller.dart';
|
import 'phantom_controller.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ColumnPassthroughStateController {
|
class ColumnPhantomStateController {
|
||||||
final _states = <String, ColumnPassthrougPhantomhState>{};
|
final _states = <String, ColumnState>{};
|
||||||
|
|
||||||
void setColumnIsDragging(String columnId, bool isDragging) {
|
void setColumnIsDragging(String columnId, bool isDragging) {
|
||||||
_stateWithId(columnId).isDragging = isDragging;
|
_stateWithId(columnId).isDragging = isDragging;
|
||||||
@ -32,17 +32,17 @@ class ColumnPassthroughStateController {
|
|||||||
_stateWithId(columnId).notifier.remove();
|
_stateWithId(columnId).notifier.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnPassthrougPhantomhState _stateWithId(String columnId) {
|
ColumnState _stateWithId(String columnId) {
|
||||||
var state = _states[columnId];
|
var state = _states[columnId];
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
state = ColumnPassthrougPhantomhState();
|
state = ColumnState();
|
||||||
_states[columnId] = state;
|
_states[columnId] = state;
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ColumnPassthrougPhantomhState {
|
class ColumnState {
|
||||||
bool isDragging = false;
|
bool isDragging = false;
|
||||||
final notifier = PassthroughPhantomNotifier();
|
final notifier = PassthroughPhantomNotifier();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user