mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: support moving group
This commit is contained in:
@ -69,7 +69,6 @@ class BoardContent extends StatefulWidget {
|
|||||||
|
|
||||||
class _BoardContentState extends State<BoardContent> {
|
class _BoardContentState extends State<BoardContent> {
|
||||||
late AppFlowyBoardScrollController scrollManager;
|
late AppFlowyBoardScrollController scrollManager;
|
||||||
final Map<String, ValueKey> cardKeysCache = {};
|
|
||||||
|
|
||||||
final config = AppFlowyBoardConfig(
|
final config = AppFlowyBoardConfig(
|
||||||
groupBackgroundColor: HexColor.fromHex('#F7F8FC'),
|
groupBackgroundColor: HexColor.fromHex('#F7F8FC'),
|
||||||
@ -139,7 +138,7 @@ class _BoardContentState extends State<BoardContent> {
|
|||||||
.read<BoardBloc>()
|
.read<BoardBloc>()
|
||||||
.add(BoardEvent.endEditRow(editingRow.row.id));
|
.add(BoardEvent.endEditRow(editingRow.row.id));
|
||||||
} else {
|
} else {
|
||||||
scrollManager.scrollToBottom(editingRow.columnId, () {
|
scrollManager.scrollToBottom(editingRow.columnId, (boardContext) {
|
||||||
context
|
context
|
||||||
.read<BoardBloc>()
|
.read<BoardBloc>()
|
||||||
.add(BoardEvent.endEditRow(editingRow.row.id));
|
.add(BoardEvent.endEditRow(editingRow.row.id));
|
||||||
@ -247,15 +246,8 @@ class _BoardContentState extends State<BoardContent> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final groupItemId = columnItem.id + group.id;
|
final groupItemId = columnItem.id + group.id;
|
||||||
ValueKey? key = cardKeysCache[groupItemId];
|
|
||||||
if (key == null) {
|
|
||||||
final newKey = ValueKey(groupItemId);
|
|
||||||
cardKeysCache[groupItemId] = newKey;
|
|
||||||
key = newKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AppFlowyGroupCard(
|
return AppFlowyGroupCard(
|
||||||
key: key,
|
key: ValueKey(groupItemId),
|
||||||
margin: config.cardPadding,
|
margin: config.cardPadding,
|
||||||
decoration: _makeBoxDecoration(context),
|
decoration: _makeBoxDecoration(context),
|
||||||
child: BoardCard(
|
child: BoardCard(
|
||||||
|
@ -34,7 +34,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('AppFlowy Board'),
|
title: const Text('AppFlowy Board'),
|
||||||
),
|
),
|
||||||
body: _examples[_currentIndex],
|
body: Container(color: Colors.white, child: _examples[_currentIndex]),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
fixedColor: _bottomNavigationColor,
|
fixedColor: _bottomNavigationColor,
|
||||||
showSelectedLabels: true,
|
showSelectedLabels: true,
|
||||||
|
@ -21,8 +21,11 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
late AppFlowyBoardScrollController boardController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
boardController = AppFlowyBoardScrollController();
|
||||||
final group1 = AppFlowyGroupData(id: "To Do", name: "To Do", items: [
|
final group1 = AppFlowyGroupData(id: "To Do", name: "To Do", items: [
|
||||||
TextItem("Card 1"),
|
TextItem("Card 1"),
|
||||||
TextItem("Card 2"),
|
TextItem("Card 2"),
|
||||||
@ -67,12 +70,16 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
|
|||||||
child: _buildCard(groupItem),
|
child: _buildCard(groupItem),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
boardScrollController: boardController,
|
||||||
footerBuilder: (context, columnData) {
|
footerBuilder: (context, columnData) {
|
||||||
return AppFlowyGroupFooter(
|
return AppFlowyGroupFooter(
|
||||||
icon: const Icon(Icons.add, size: 20),
|
icon: const Icon(Icons.add, size: 20),
|
||||||
title: const Text('New'),
|
title: const Text('New'),
|
||||||
height: 50,
|
height: 50,
|
||||||
margin: config.groupItemPadding,
|
margin: config.groupItemPadding,
|
||||||
|
onAddButtonClick: () {
|
||||||
|
boardController.scrollToBottom(columnData.id, (p0) {});
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
headerBuilder: (context, columnData) {
|
headerBuilder: (context, columnData) {
|
||||||
|
@ -13,10 +13,8 @@ import '../rendering/board_overlay.dart';
|
|||||||
class AppFlowyBoardScrollController {
|
class AppFlowyBoardScrollController {
|
||||||
AppFlowyBoardState? _groupState;
|
AppFlowyBoardState? _groupState;
|
||||||
|
|
||||||
void scrollToBottom(String groupId, VoidCallback? completed) {
|
void scrollToBottom(String groupId, void Function(BuildContext)? completed) {
|
||||||
_groupState
|
_groupState?.reorderFlexActionMap[groupId]?.scrollToBottom(completed);
|
||||||
?.getReorderFlexState(groupId: groupId)
|
|
||||||
?.scrollToBottom(completed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +131,7 @@ class AppFlowyBoard extends StatelessWidget {
|
|||||||
dataController: controller,
|
dataController: controller,
|
||||||
scrollController: scrollController,
|
scrollController: scrollController,
|
||||||
scrollManager: boardScrollController,
|
scrollManager: boardScrollController,
|
||||||
columnsState: _groupState,
|
groupState: _groupState,
|
||||||
background: background,
|
background: background,
|
||||||
delegate: _phantomController,
|
delegate: _phantomController,
|
||||||
groupConstraints: groupConstraints,
|
groupConstraints: groupConstraints,
|
||||||
@ -158,7 +156,7 @@ class _AppFlowyBoardContent extends StatefulWidget {
|
|||||||
final ReorderFlexConfig reorderFlexConfig;
|
final ReorderFlexConfig reorderFlexConfig;
|
||||||
final BoxConstraints groupConstraints;
|
final BoxConstraints groupConstraints;
|
||||||
final AppFlowyBoardScrollController? scrollManager;
|
final AppFlowyBoardScrollController? scrollManager;
|
||||||
final AppFlowyBoardState columnsState;
|
final AppFlowyBoardState groupState;
|
||||||
final AppFlowyBoardCardBuilder cardBuilder;
|
final AppFlowyBoardCardBuilder cardBuilder;
|
||||||
final AppFlowyBoardHeaderBuilder? headerBuilder;
|
final AppFlowyBoardHeaderBuilder? headerBuilder;
|
||||||
final AppFlowyBoardFooterBuilder? footerBuilder;
|
final AppFlowyBoardFooterBuilder? footerBuilder;
|
||||||
@ -171,7 +169,7 @@ class _AppFlowyBoardContent extends StatefulWidget {
|
|||||||
required this.delegate,
|
required this.delegate,
|
||||||
required this.dataController,
|
required this.dataController,
|
||||||
required this.scrollManager,
|
required this.scrollManager,
|
||||||
required this.columnsState,
|
required this.groupState,
|
||||||
this.scrollController,
|
this.scrollController,
|
||||||
this.background,
|
this.background,
|
||||||
required this.groupConstraints,
|
required this.groupConstraints,
|
||||||
@ -192,8 +190,6 @@ class _AppFlowyBoardContentState extends State<_AppFlowyBoardContent> {
|
|||||||
GlobalKey(debugLabel: '$_AppFlowyBoardContent overlay key');
|
GlobalKey(debugLabel: '$_AppFlowyBoardContent overlay key');
|
||||||
late BoardOverlayEntry _overlayEntry;
|
late BoardOverlayEntry _overlayEntry;
|
||||||
|
|
||||||
final Map<String, GlobalObjectKey> _reorderFlexKeys = {};
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_overlayEntry = BoardOverlayEntry(
|
_overlayEntry = BoardOverlayEntry(
|
||||||
@ -202,7 +198,7 @@ class _AppFlowyBoardContentState extends State<_AppFlowyBoardContent> {
|
|||||||
reorderFlexId: widget.dataController.identifier,
|
reorderFlexId: widget.dataController.identifier,
|
||||||
acceptedReorderFlexId: widget.dataController.groupIds,
|
acceptedReorderFlexId: widget.dataController.groupIds,
|
||||||
delegate: widget.delegate,
|
delegate: widget.delegate,
|
||||||
columnsState: widget.columnsState,
|
columnsState: widget.groupState,
|
||||||
);
|
);
|
||||||
|
|
||||||
final reorderFlex = ReorderFlex(
|
final reorderFlex = ReorderFlex(
|
||||||
@ -212,7 +208,7 @@ class _AppFlowyBoardContentState extends State<_AppFlowyBoardContent> {
|
|||||||
dataSource: widget.dataController,
|
dataSource: widget.dataController,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
interceptor: interceptor,
|
interceptor: interceptor,
|
||||||
reorderable: false,
|
reorderable: true,
|
||||||
children: _buildColumns(),
|
children: _buildColumns(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -257,18 +253,16 @@ class _AppFlowyBoardContentState extends State<_AppFlowyBoardContent> {
|
|||||||
dataController: widget.dataController,
|
dataController: widget.dataController,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (_reorderFlexKeys[columnData.id] == null) {
|
final reorderFlexAction = ReorderFlexActionImpl();
|
||||||
_reorderFlexKeys[columnData.id] = GlobalObjectKey(columnData.id);
|
widget.groupState.reorderFlexActionMap[columnData.id] =
|
||||||
}
|
reorderFlexAction;
|
||||||
|
|
||||||
GlobalObjectKey reorderFlexKey = _reorderFlexKeys[columnData.id]!;
|
|
||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
key: ValueKey(columnData.id),
|
key: ValueKey(columnData.id),
|
||||||
value: widget.dataController.getGroupController(columnData.id),
|
value: widget.dataController.getGroupController(columnData.id),
|
||||||
child: Consumer<AppFlowyGroupController>(
|
child: Consumer<AppFlowyGroupController>(
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
final boardColumn = AppFlowyBoardGroup(
|
final boardColumn = AppFlowyBoardGroup(
|
||||||
reorderFlexKey: reorderFlexKey,
|
|
||||||
// key: PageStorageKey<String>(columnData.id),
|
// key: PageStorageKey<String>(columnData.id),
|
||||||
margin: _marginFromIndex(columnIndex),
|
margin: _marginFromIndex(columnIndex),
|
||||||
itemMargin: widget.config.groupItemPadding,
|
itemMargin: widget.config.groupItemPadding,
|
||||||
@ -281,11 +275,11 @@ class _AppFlowyBoardContentState extends State<_AppFlowyBoardContent> {
|
|||||||
onReorder: widget.dataController.moveGroupItem,
|
onReorder: widget.dataController.moveGroupItem,
|
||||||
cornerRadius: widget.config.cornerRadius,
|
cornerRadius: widget.config.cornerRadius,
|
||||||
backgroundColor: widget.config.groupBackgroundColor,
|
backgroundColor: widget.config.groupBackgroundColor,
|
||||||
dragStateStorage: widget.columnsState,
|
dragStateStorage: widget.groupState,
|
||||||
dragTargetIndexKeyStorage: widget.columnsState,
|
dragTargetKeys: widget.groupState,
|
||||||
|
reorderFlexAction: reorderFlexAction,
|
||||||
);
|
);
|
||||||
|
|
||||||
widget.columnsState.addGroup(columnData.id, boardColumn);
|
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: widget.groupConstraints,
|
constraints: widget.groupConstraints,
|
||||||
child: boardColumn,
|
child: boardColumn,
|
||||||
@ -356,71 +350,61 @@ class AppFlowyGroupContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AppFlowyBoardState extends DraggingStateStorage
|
class AppFlowyBoardState extends DraggingStateStorage
|
||||||
with ReorderDragTargetIndexKeyStorage {
|
with ReorderDragTargeKeys {
|
||||||
|
final Map<String, DraggingState> groupDragStates = {};
|
||||||
|
final Map<String, Map<String, GlobalObjectKey>> groupDragTargetKeys = {};
|
||||||
|
|
||||||
/// Quick access to the [AppFlowyBoardGroup], the [GlobalKey] is bind to the
|
/// Quick access to the [AppFlowyBoardGroup], the [GlobalKey] is bind to the
|
||||||
/// AppFlowyBoardGroup's [ReorderFlex] widget.
|
/// AppFlowyBoardGroup's [ReorderFlex] widget.
|
||||||
final Map<String, GlobalKey> groupReorderFlexKeys = {};
|
final Map<String, ReorderFlexActionImpl> reorderFlexActionMap = {};
|
||||||
final Map<String, DraggingState> groupDragStates = {};
|
|
||||||
final Map<String, Map<String, GlobalObjectKey>> groupDragDragTargets = {};
|
|
||||||
|
|
||||||
void addGroup(String groupId, AppFlowyBoardGroup groupWidget) {
|
|
||||||
groupReorderFlexKeys[groupId] = groupWidget.reorderFlexKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReorderFlexState? getReorderFlexState({required String groupId}) {
|
|
||||||
final flexGlobalKey = groupReorderFlexKeys[groupId];
|
|
||||||
if (flexGlobalKey == null) return null;
|
|
||||||
if (flexGlobalKey.currentState is! ReorderFlexState) return null;
|
|
||||||
final state = flexGlobalKey.currentState as ReorderFlexState;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReorderFlex? getReorderFlex({required String groupId}) {
|
|
||||||
final flexGlobalKey = groupReorderFlexKeys[groupId];
|
|
||||||
if (flexGlobalKey == null) return null;
|
|
||||||
if (flexGlobalKey.currentWidget is! ReorderFlex) return null;
|
|
||||||
final widget = flexGlobalKey.currentWidget as ReorderFlex;
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
DraggingState? read(String reorderFlexId) {
|
DraggingState? readState(String reorderFlexId) {
|
||||||
return groupDragStates[reorderFlexId];
|
return groupDragStates[reorderFlexId];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void write(String reorderFlexId, DraggingState state) {
|
void insertState(String reorderFlexId, DraggingState state) {
|
||||||
Log.trace('$reorderFlexId Write dragging state: $state');
|
Log.trace('$reorderFlexId Write dragging state: $state');
|
||||||
groupDragStates[reorderFlexId] = state;
|
groupDragStates[reorderFlexId] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void remove(String reorderFlexId) {
|
void removeState(String reorderFlexId) {
|
||||||
groupDragStates.remove(reorderFlexId);
|
groupDragStates.remove(reorderFlexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void addKey(
|
void insertDragTarget(
|
||||||
String reorderFlexId,
|
String reorderFlexId,
|
||||||
String key,
|
String key,
|
||||||
GlobalObjectKey<State<StatefulWidget>> value,
|
GlobalObjectKey<State<StatefulWidget>> value,
|
||||||
) {
|
) {
|
||||||
Map<String, GlobalObjectKey>? group = groupDragDragTargets[reorderFlexId];
|
Map<String, GlobalObjectKey>? group = groupDragTargetKeys[reorderFlexId];
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
group = {};
|
group = {};
|
||||||
groupDragDragTargets[reorderFlexId] = group;
|
groupDragTargetKeys[reorderFlexId] = group;
|
||||||
}
|
}
|
||||||
group[key] = value;
|
group[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
GlobalObjectKey<State<StatefulWidget>>? readKey(
|
GlobalObjectKey<State<StatefulWidget>>? getDragTarget(
|
||||||
String reorderFlexId, String key) {
|
String reorderFlexId,
|
||||||
Map<String, GlobalObjectKey>? group = groupDragDragTargets[reorderFlexId];
|
String key,
|
||||||
|
) {
|
||||||
|
Map<String, GlobalObjectKey>? group = groupDragTargetKeys[reorderFlexId];
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
return group[key];
|
return group[key];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void removeDragTarget(String reorderFlexId) {
|
||||||
|
groupDragTargetKeys.remove(reorderFlexId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ReorderFlexActionImpl extends ReorderFlexAction {}
|
||||||
|
@ -90,21 +90,21 @@ class AppFlowyBoardGroup extends StatefulWidget {
|
|||||||
|
|
||||||
final DraggingStateStorage? dragStateStorage;
|
final DraggingStateStorage? dragStateStorage;
|
||||||
|
|
||||||
final ReorderDragTargetIndexKeyStorage? dragTargetIndexKeyStorage;
|
final ReorderDragTargeKeys? dragTargetKeys;
|
||||||
|
|
||||||
final GlobalObjectKey reorderFlexKey;
|
final ReorderFlexAction? reorderFlexAction;
|
||||||
|
|
||||||
const AppFlowyBoardGroup({
|
const AppFlowyBoardGroup({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.reorderFlexKey,
|
|
||||||
this.headerBuilder,
|
this.headerBuilder,
|
||||||
this.footerBuilder,
|
this.footerBuilder,
|
||||||
required this.cardBuilder,
|
required this.cardBuilder,
|
||||||
required this.onReorder,
|
required this.onReorder,
|
||||||
required this.dataSource,
|
required this.dataSource,
|
||||||
required this.phantomController,
|
required this.phantomController,
|
||||||
|
this.reorderFlexAction,
|
||||||
this.dragStateStorage,
|
this.dragStateStorage,
|
||||||
this.dragTargetIndexKeyStorage,
|
this.dragTargetKeys,
|
||||||
this.scrollController,
|
this.scrollController,
|
||||||
this.onDragStarted,
|
this.onDragStarted,
|
||||||
this.onDragEnded,
|
this.onDragEnded,
|
||||||
@ -146,9 +146,9 @@ class _AppFlowyBoardGroupState extends State<AppFlowyBoardGroup> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Widget reorderFlex = ReorderFlex(
|
Widget reorderFlex = ReorderFlex(
|
||||||
key: widget.reorderFlexKey,
|
key: ValueKey(widget.groupId),
|
||||||
dragStateStorage: widget.dragStateStorage,
|
dragStateStorage: widget.dragStateStorage,
|
||||||
dragTargetIndexKeyStorage: widget.dragTargetIndexKeyStorage,
|
dragTargetKeys: widget.dragTargetKeys,
|
||||||
scrollController: widget.scrollController,
|
scrollController: widget.scrollController,
|
||||||
config: widget.config,
|
config: widget.config,
|
||||||
onDragStarted: (index) {
|
onDragStarted: (index) {
|
||||||
@ -168,6 +168,7 @@ class _AppFlowyBoardGroupState extends State<AppFlowyBoardGroup> {
|
|||||||
},
|
},
|
||||||
dataSource: widget.dataSource,
|
dataSource: widget.dataSource,
|
||||||
interceptor: interceptor,
|
interceptor: interceptor,
|
||||||
|
reorderFlexAction: widget.reorderFlexAction,
|
||||||
children: children,
|
children: children,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
void updateGroupName(String newName) {
|
void updateGroupName(String newName) {
|
||||||
if (groupData.headerData.groupName != newName) {
|
if (groupData.headerData.groupName != newName) {
|
||||||
groupData.headerData.groupName = newName;
|
groupData.headerData.groupName = newName;
|
||||||
notifyListeners();
|
_notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
Log.debug('[$AppFlowyGroupController] $groupData remove item at $index');
|
Log.debug('[$AppFlowyGroupController] $groupData remove item at $index');
|
||||||
final item = groupData._items.removeAt(index);
|
final item = groupData._items.removeAt(index);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyListeners();
|
_notify();
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
'[$AppFlowyGroupController] $groupData move item from $fromIndex to $toIndex');
|
'[$AppFlowyGroupController] $groupData move item from $fromIndex to $toIndex');
|
||||||
final item = groupData._items.removeAt(fromIndex);
|
final item = groupData._items.removeAt(fromIndex);
|
||||||
groupData._items.insert(toIndex, item);
|
groupData._items.insert(toIndex, item);
|
||||||
notifyListeners();
|
_notify();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
groupData._items.add(item);
|
groupData._items.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notify) notifyListeners();
|
if (notify) _notify();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
groupData._items.add(item);
|
groupData._items.add(item);
|
||||||
if (notify) notifyListeners();
|
if (notify) _notify();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
'[$AppFlowyGroupController] $groupData replace $removedItem with $newItem at $index');
|
'[$AppFlowyGroupController] $groupData replace $removedItem with $newItem at $index');
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
_notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceOrInsertItem(AppFlowyGroupItem newItem) {
|
void replaceOrInsertItem(AppFlowyGroupItem newItem) {
|
||||||
@ -143,10 +143,10 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
groupData._items.removeAt(index);
|
groupData._items.removeAt(index);
|
||||||
groupData._items.insert(index, newItem);
|
groupData._items.insert(index, newItem);
|
||||||
notifyListeners();
|
_notify();
|
||||||
} else {
|
} else {
|
||||||
groupData._items.add(newItem);
|
groupData._items.add(newItem);
|
||||||
notifyListeners();
|
_notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +154,10 @@ class AppFlowyGroupController extends ChangeNotifier with EquatableMixin {
|
|||||||
return groupData._items.indexWhere((element) => element.id == item.id) !=
|
return groupData._items.indexWhere((element) => element.id == item.id) !=
|
||||||
-1;
|
-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _notify() {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [AppFlowyGroupData] represents the data of each group of the Board.
|
/// [AppFlowyGroupData] represents the data of each group of the Board.
|
||||||
|
@ -69,9 +69,9 @@ class FlexDragTargetData extends DragTargetData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class DraggingStateStorage {
|
abstract class DraggingStateStorage {
|
||||||
void write(String reorderFlexId, DraggingState state);
|
void insertState(String reorderFlexId, DraggingState state);
|
||||||
void remove(String reorderFlexId);
|
void removeState(String reorderFlexId);
|
||||||
DraggingState? read(String reorderFlexId);
|
DraggingState? readState(String reorderFlexId);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DraggingState {
|
class DraggingState {
|
||||||
|
@ -73,11 +73,15 @@ class ReorderDragTarget<T extends DragTargetData> extends StatefulWidget {
|
|||||||
final ReorderFlexDraggableTargetBuilder? draggableTargetBuilder;
|
final ReorderFlexDraggableTargetBuilder? draggableTargetBuilder;
|
||||||
|
|
||||||
final AnimationController insertAnimationController;
|
final AnimationController insertAnimationController;
|
||||||
|
|
||||||
final AnimationController deleteAnimationController;
|
final AnimationController deleteAnimationController;
|
||||||
|
|
||||||
final bool useMoveAnimation;
|
final bool useMoveAnimation;
|
||||||
|
|
||||||
final bool draggable;
|
final bool draggable;
|
||||||
|
|
||||||
|
final double draggingOpacity;
|
||||||
|
|
||||||
const ReorderDragTarget({
|
const ReorderDragTarget({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.child,
|
required this.child,
|
||||||
@ -94,6 +98,7 @@ class ReorderDragTarget<T extends DragTargetData> extends StatefulWidget {
|
|||||||
this.onAccept,
|
this.onAccept,
|
||||||
this.onLeave,
|
this.onLeave,
|
||||||
this.draggableTargetBuilder,
|
this.draggableTargetBuilder,
|
||||||
|
this.draggingOpacity = 0.3,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -164,6 +169,7 @@ class _ReorderDragTargetState<T extends DragTargetData>
|
|||||||
feedback: feedbackBuilder,
|
feedback: feedbackBuilder,
|
||||||
childWhenDragging: IgnorePointerWidget(
|
childWhenDragging: IgnorePointerWidget(
|
||||||
useIntrinsicSize: !widget.useMoveAnimation,
|
useIntrinsicSize: !widget.useMoveAnimation,
|
||||||
|
opacity: widget.draggingOpacity,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
onDragStarted: () {
|
onDragStarted: () {
|
||||||
@ -195,7 +201,10 @@ class _ReorderDragTargetState<T extends DragTargetData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDraggableFeedback(
|
Widget _buildDraggableFeedback(
|
||||||
BuildContext context, BoxConstraints constraints, Widget child) {
|
BuildContext context,
|
||||||
|
BoxConstraints constraints,
|
||||||
|
Widget child,
|
||||||
|
) {
|
||||||
return Transform(
|
return Transform(
|
||||||
transform: Matrix4.rotationZ(0),
|
transform: Matrix4.rotationZ(0),
|
||||||
alignment: FractionalOffset.topLeft,
|
alignment: FractionalOffset.topLeft,
|
||||||
@ -205,7 +214,7 @@ class _ReorderDragTargetState<T extends DragTargetData>
|
|||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
child: Opacity(opacity: 0.3, child: child),
|
child: Opacity(opacity: widget.draggingOpacity, child: child),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -274,8 +283,11 @@ class DragTargetAnimation {
|
|||||||
class IgnorePointerWidget extends StatelessWidget {
|
class IgnorePointerWidget extends StatelessWidget {
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final bool useIntrinsicSize;
|
final bool useIntrinsicSize;
|
||||||
|
final double opacity;
|
||||||
|
|
||||||
const IgnorePointerWidget({
|
const IgnorePointerWidget({
|
||||||
required this.child,
|
required this.child,
|
||||||
|
required this.opacity,
|
||||||
this.useIntrinsicSize = false,
|
this.useIntrinsicSize = false,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
@ -286,11 +298,10 @@ class IgnorePointerWidget extends StatelessWidget {
|
|||||||
? child
|
? child
|
||||||
: SizedBox(width: 0.0, height: 0.0, child: child);
|
: SizedBox(width: 0.0, height: 0.0, child: child);
|
||||||
|
|
||||||
final opacity = useIntrinsicSize ? 0.3 : 0.0;
|
|
||||||
return IgnorePointer(
|
return IgnorePointer(
|
||||||
ignoring: true,
|
ignoring: true,
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: opacity,
|
opacity: useIntrinsicSize ? opacity : 0.0,
|
||||||
child: sizedChild,
|
child: sizedChild,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -300,8 +311,10 @@ class IgnorePointerWidget extends StatelessWidget {
|
|||||||
class AbsorbPointerWidget extends StatelessWidget {
|
class AbsorbPointerWidget extends StatelessWidget {
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
final bool useIntrinsicSize;
|
final bool useIntrinsicSize;
|
||||||
|
final double opacity;
|
||||||
const AbsorbPointerWidget({
|
const AbsorbPointerWidget({
|
||||||
required this.child,
|
required this.child,
|
||||||
|
required this.opacity,
|
||||||
this.useIntrinsicSize = false,
|
this.useIntrinsicSize = false,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
@ -312,10 +325,9 @@ class AbsorbPointerWidget extends StatelessWidget {
|
|||||||
? child
|
? child
|
||||||
: SizedBox(width: 0.0, height: 0.0, child: child);
|
: SizedBox(width: 0.0, height: 0.0, child: child);
|
||||||
|
|
||||||
final opacity = useIntrinsicSize ? 0.3 : 0.0;
|
|
||||||
return AbsorbPointer(
|
return AbsorbPointer(
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: opacity,
|
opacity: useIntrinsicSize ? opacity : 0.0,
|
||||||
child: sizedChild,
|
child: sizedChild,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -494,6 +506,7 @@ class _FakeDragTargetState<T extends DragTargetData>
|
|||||||
sizeFactor: widget.deleteAnimationController,
|
sizeFactor: widget.deleteAnimationController,
|
||||||
axis: Axis.vertical,
|
axis: Axis.vertical,
|
||||||
child: AbsorbPointerWidget(
|
child: AbsorbPointerWidget(
|
||||||
|
opacity: 0.3,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -503,6 +516,7 @@ class _FakeDragTargetState<T extends DragTargetData>
|
|||||||
axis: Axis.vertical,
|
axis: Axis.vertical,
|
||||||
child: AbsorbPointerWidget(
|
child: AbsorbPointerWidget(
|
||||||
useIntrinsicSize: true,
|
useIntrinsicSize: true,
|
||||||
|
opacity: 0.3,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -81,7 +81,7 @@ class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
|
|||||||
delegate.cancel();
|
delegate.cancel();
|
||||||
} else {
|
} else {
|
||||||
// Ignore the event if the dragTarget overlaps with the other column's dragTargets.
|
// Ignore the event if the dragTarget overlaps with the other column's dragTargets.
|
||||||
final columnKeys = columnsState.groupDragDragTargets[dragTargetId];
|
final columnKeys = columnsState.groupDragTargetKeys[dragTargetId];
|
||||||
if (columnKeys != null) {
|
if (columnKeys != null) {
|
||||||
final keys = columnKeys.values.toList();
|
final keys = columnKeys.values.toList();
|
||||||
if (dragTargetData.isOverlapWithWidgets(keys)) {
|
if (dragTargetData.isOverlapWithWidgets(keys)) {
|
||||||
@ -102,8 +102,7 @@ class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
|
|||||||
delegate.dragTargetDidMoveToReorderFlex(
|
delegate.dragTargetDidMoveToReorderFlex(
|
||||||
dragTargetId, dragTargetData, index);
|
dragTargetId, dragTargetData, index);
|
||||||
|
|
||||||
columnsState
|
columnsState.reorderFlexActionMap[dragTargetId]
|
||||||
.getReorderFlexState(groupId: dragTargetId)
|
|
||||||
?.resetDragTargetIndex(index);
|
?.resetDragTargetIndex(index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -31,9 +31,32 @@ abstract class ReoderFlexItem {
|
|||||||
String get id;
|
String get id;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ReorderDragTargetIndexKeyStorage {
|
/// Cache each dragTarget's key.
|
||||||
void addKey(String reorderFlexId, String key, GlobalObjectKey value);
|
/// For the moment, the key is used to locate the render object that will
|
||||||
GlobalObjectKey? readKey(String reorderFlexId, String key);
|
/// be passed in the [ScrollPosition]'s [ensureVisible] function.
|
||||||
|
///
|
||||||
|
abstract class ReorderDragTargeKeys {
|
||||||
|
void insertDragTarget(
|
||||||
|
String reorderFlexId,
|
||||||
|
String key,
|
||||||
|
GlobalObjectKey value,
|
||||||
|
);
|
||||||
|
|
||||||
|
GlobalObjectKey? getDragTarget(
|
||||||
|
String reorderFlexId,
|
||||||
|
String key,
|
||||||
|
);
|
||||||
|
|
||||||
|
void removeDragTarget(String reorderFlexId);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class ReorderFlexAction {
|
||||||
|
void Function(void Function(BuildContext)?)? _scrollToBottom;
|
||||||
|
void Function(void Function(BuildContext)?) get scrollToBottom =>
|
||||||
|
_scrollToBottom!;
|
||||||
|
|
||||||
|
void Function(int)? _resetDragTargetIndex;
|
||||||
|
void Function(int) get resetDragTargetIndex => _resetDragTargetIndex!;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReorderFlexConfig {
|
class ReorderFlexConfig {
|
||||||
@ -78,9 +101,12 @@ class ReorderFlex extends StatefulWidget {
|
|||||||
|
|
||||||
final DragTargetInterceptor? interceptor;
|
final DragTargetInterceptor? interceptor;
|
||||||
|
|
||||||
|
/// Save the [DraggingState] if the current [ReorderFlex] get reinitialize.
|
||||||
final DraggingStateStorage? dragStateStorage;
|
final DraggingStateStorage? dragStateStorage;
|
||||||
|
|
||||||
final ReorderDragTargetIndexKeyStorage? dragTargetIndexKeyStorage;
|
final ReorderDragTargeKeys? dragTargetKeys;
|
||||||
|
|
||||||
|
final ReorderFlexAction? reorderFlexAction;
|
||||||
|
|
||||||
final bool reorderable;
|
final bool reorderable;
|
||||||
|
|
||||||
@ -93,10 +119,11 @@ class ReorderFlex extends StatefulWidget {
|
|||||||
required this.onReorder,
|
required this.onReorder,
|
||||||
this.reorderable = true,
|
this.reorderable = true,
|
||||||
this.dragStateStorage,
|
this.dragStateStorage,
|
||||||
this.dragTargetIndexKeyStorage,
|
this.dragTargetKeys,
|
||||||
this.onDragStarted,
|
this.onDragStarted,
|
||||||
this.onDragEnded,
|
this.onDragEnded,
|
||||||
this.interceptor,
|
this.interceptor,
|
||||||
|
this.reorderFlexAction,
|
||||||
this.direction = Axis.vertical,
|
this.direction = Axis.vertical,
|
||||||
}) : assert(children.every((Widget w) => w.key != null),
|
}) : assert(children.every((Widget w) => w.key != null),
|
||||||
'All child must have a key.'),
|
'All child must have a key.'),
|
||||||
@ -109,7 +136,7 @@ class ReorderFlex extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ReorderFlexState extends State<ReorderFlex>
|
class ReorderFlexState extends State<ReorderFlex>
|
||||||
with ReorderFlexMinxi, TickerProviderStateMixin<ReorderFlex> {
|
with ReorderFlexMixin, TickerProviderStateMixin<ReorderFlex> {
|
||||||
/// Controls scrolls and measures scroll progress.
|
/// Controls scrolls and measures scroll progress.
|
||||||
late ScrollController _scrollController;
|
late ScrollController _scrollController;
|
||||||
|
|
||||||
@ -131,11 +158,11 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
void initState() {
|
void initState() {
|
||||||
_notifier = ReorderFlexNotifier();
|
_notifier = ReorderFlexNotifier();
|
||||||
final flexId = widget.reorderFlexId;
|
final flexId = widget.reorderFlexId;
|
||||||
dragState = widget.dragStateStorage?.read(flexId) ??
|
dragState = widget.dragStateStorage?.readState(flexId) ??
|
||||||
DraggingState(widget.reorderFlexId);
|
DraggingState(widget.reorderFlexId);
|
||||||
Log.trace('[DragTarget] init dragState: $dragState');
|
Log.trace('[DragTarget] init dragState: $dragState');
|
||||||
|
|
||||||
widget.dragStateStorage?.remove(flexId);
|
widget.dragStateStorage?.removeState(flexId);
|
||||||
|
|
||||||
_animation = DragTargetAnimation(
|
_animation = DragTargetAnimation(
|
||||||
reorderAnimationDuration: widget.config.reorderAnimationDuration,
|
reorderAnimationDuration: widget.config.reorderAnimationDuration,
|
||||||
@ -148,6 +175,14 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
vsync: this,
|
vsync: this,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
widget.reorderFlexAction?._scrollToBottom = (fn) {
|
||||||
|
scrollToBottom(fn);
|
||||||
|
};
|
||||||
|
|
||||||
|
widget.reorderFlexAction?._resetDragTargetIndex = (index) {
|
||||||
|
resetDragTargetIndex(index);
|
||||||
|
};
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +219,7 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
|
|
||||||
final indexKey = GlobalObjectKey(child.key!);
|
final indexKey = GlobalObjectKey(child.key!);
|
||||||
// Save the index key for quick access
|
// Save the index key for quick access
|
||||||
widget.dragTargetIndexKeyStorage?.addKey(
|
widget.dragTargetKeys?.insertDragTarget(
|
||||||
widget.reorderFlexId,
|
widget.reorderFlexId,
|
||||||
item.id,
|
item.id,
|
||||||
indexKey,
|
indexKey,
|
||||||
@ -212,6 +247,7 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
}
|
}
|
||||||
|
|
||||||
_animation.dispose();
|
_animation.dispose();
|
||||||
|
widget.dragTargetKeys?.removeDragTarget(widget.reorderFlexId);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,8 +272,12 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
/// [childIndex]: the index of the child in a list
|
/// [childIndex]: the index of the child in a list
|
||||||
Widget _wrap(Widget child, int childIndex, GlobalObjectKey indexKey) {
|
Widget _wrap(Widget child, int childIndex, GlobalObjectKey indexKey) {
|
||||||
return Builder(builder: (context) {
|
return Builder(builder: (context) {
|
||||||
final ReorderDragTarget dragTarget =
|
final ReorderDragTarget dragTarget = _buildDragTarget(
|
||||||
_buildDragTarget(context, child, childIndex, indexKey);
|
context,
|
||||||
|
child,
|
||||||
|
childIndex,
|
||||||
|
indexKey,
|
||||||
|
);
|
||||||
int shiftedIndex = childIndex;
|
int shiftedIndex = childIndex;
|
||||||
|
|
||||||
if (dragState.isOverlapWithPhantom()) {
|
if (dragState.isOverlapWithPhantom()) {
|
||||||
@ -342,6 +382,15 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ReorderFlexState of(BuildContext context) {
|
||||||
|
if (context is StatefulElement && context.state is ReorderFlexState) {
|
||||||
|
return context.state as ReorderFlexState;
|
||||||
|
}
|
||||||
|
final ReorderFlexState? result =
|
||||||
|
context.findAncestorStateOfType<ReorderFlexState>();
|
||||||
|
return result!;
|
||||||
|
}
|
||||||
|
|
||||||
ReorderDragTarget _buildDragTarget(
|
ReorderDragTarget _buildDragTarget(
|
||||||
BuildContext builderContext,
|
BuildContext builderContext,
|
||||||
Widget child,
|
Widget child,
|
||||||
@ -364,7 +413,7 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
"[DragTarget] Group:[${widget.dataSource.identifier}] start dragging item at $draggingIndex");
|
"[DragTarget] Group:[${widget.dataSource.identifier}] start dragging item at $draggingIndex");
|
||||||
_startDragging(draggingWidget, draggingIndex, size);
|
_startDragging(draggingWidget, draggingIndex, size);
|
||||||
widget.onDragStarted?.call(draggingIndex);
|
widget.onDragStarted?.call(draggingIndex);
|
||||||
widget.dragStateStorage?.remove(widget.reorderFlexId);
|
widget.dragStateStorage?.removeState(widget.reorderFlexId);
|
||||||
},
|
},
|
||||||
onDragMoved: (dragTargetData, offset) {
|
onDragMoved: (dragTargetData, offset) {
|
||||||
dragTargetData.dragTargetOffset = offset;
|
dragTargetData.dragTargetOffset = offset;
|
||||||
@ -435,6 +484,7 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
draggableTargetBuilder: widget.interceptor?.draggableTargetBuilder,
|
draggableTargetBuilder: widget.interceptor?.draggableTargetBuilder,
|
||||||
useMoveAnimation: widget.config.useMoveAnimation,
|
useMoveAnimation: widget.config.useMoveAnimation,
|
||||||
draggable: widget.reorderable,
|
draggable: widget.reorderable,
|
||||||
|
draggingOpacity: widget.config.draggingWidgetOpacity,
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -487,7 +537,7 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
}
|
}
|
||||||
|
|
||||||
dragState.setStartDraggingIndex(dragTargetIndex);
|
dragState.setStartDraggingIndex(dragTargetIndex);
|
||||||
widget.dragStateStorage?.write(
|
widget.dragStateStorage?.insertState(
|
||||||
widget.reorderFlexId,
|
widget.reorderFlexId,
|
||||||
dragState,
|
dragState,
|
||||||
);
|
);
|
||||||
@ -581,46 +631,46 @@ class ReorderFlexState extends State<ReorderFlex>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollToBottom(VoidCallback? completed) {
|
void scrollToBottom(void Function(BuildContext)? completed) {
|
||||||
if (_scrolling) {
|
if (_scrolling) {
|
||||||
completed?.call();
|
completed?.call(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.dataSource.items.isNotEmpty) {
|
if (widget.dataSource.items.isNotEmpty) {
|
||||||
final item = widget.dataSource.items.last;
|
final item = widget.dataSource.items.last;
|
||||||
final indexKey = widget.dragTargetIndexKeyStorage?.readKey(
|
final dragTargetKey = widget.dragTargetKeys?.getDragTarget(
|
||||||
widget.reorderFlexId,
|
widget.reorderFlexId,
|
||||||
item.id,
|
item.id,
|
||||||
);
|
);
|
||||||
if (indexKey == null) {
|
if (dragTargetKey == null) {
|
||||||
completed?.call();
|
completed?.call(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final indexContext = indexKey.currentContext;
|
final dragTargetContext = dragTargetKey.currentContext;
|
||||||
if (indexContext == null || _scrollController.hasClients == false) {
|
if (dragTargetContext == null || _scrollController.hasClients == false) {
|
||||||
completed?.call();
|
completed?.call(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final renderObject = indexContext.findRenderObject();
|
final dragTargetRenderObject = dragTargetContext.findRenderObject();
|
||||||
if (renderObject != null) {
|
if (dragTargetRenderObject != null) {
|
||||||
_scrolling = true;
|
_scrolling = true;
|
||||||
_scrollController.position
|
_scrollController.position
|
||||||
.ensureVisible(
|
.ensureVisible(
|
||||||
renderObject,
|
dragTargetRenderObject,
|
||||||
alignment: 0.5,
|
alignment: 0.5,
|
||||||
duration: const Duration(milliseconds: 120),
|
duration: const Duration(milliseconds: 120),
|
||||||
)
|
)
|
||||||
.then((value) {
|
.then((value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_scrolling = false;
|
_scrolling = false;
|
||||||
completed?.call();
|
completed?.call(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
completed?.call();
|
completed?.call(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import 'package:flutter/widgets.dart';
|
|||||||
import '../transitions.dart';
|
import '../transitions.dart';
|
||||||
import 'drag_target.dart';
|
import 'drag_target.dart';
|
||||||
|
|
||||||
mixin ReorderFlexMinxi {
|
mixin ReorderFlexMixin {
|
||||||
@protected
|
@protected
|
||||||
Widget makeAppearingWidget(
|
Widget makeAppearingWidget(
|
||||||
Widget child,
|
Widget child,
|
||||||
|
@ -98,6 +98,7 @@ pub struct MoveGroupPayloadPB {
|
|||||||
pub to_group_id: String,
|
pub to_group_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(debug, Debug)]
|
||||||
pub struct MoveGroupParams {
|
pub struct MoveGroupParams {
|
||||||
pub view_id: String,
|
pub view_id: String,
|
||||||
pub from_group_id: String,
|
pub from_group_id: String,
|
||||||
|
@ -173,6 +173,7 @@ impl GridViewRevisionEditor {
|
|||||||
Ok(groups.into_iter().map(GroupPB::from).collect())
|
Ok(groups.into_iter().map(GroupPB::from).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "trace", err)]
|
||||||
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
pub(crate) async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
||||||
let _ = self
|
let _ = self
|
||||||
.group_controller
|
.group_controller
|
||||||
@ -180,7 +181,7 @@ impl GridViewRevisionEditor {
|
|||||||
.await
|
.await
|
||||||
.move_group(¶ms.from_group_id, ¶ms.to_group_id)?;
|
.move_group(¶ms.from_group_id, ¶ms.to_group_id)?;
|
||||||
match self.group_controller.read().await.get_group(¶ms.from_group_id) {
|
match self.group_controller.read().await.get_group(¶ms.from_group_id) {
|
||||||
None => {}
|
None => tracing::warn!("Can not find the group with id: {}", params.from_group_id),
|
||||||
Some((index, group)) => {
|
Some((index, group)) => {
|
||||||
let inserted_group = InsertedGroupPB {
|
let inserted_group = InsertedGroupPB {
|
||||||
group: GroupPB::from(group),
|
group: GroupPB::from(group),
|
||||||
|
@ -135,6 +135,7 @@ where
|
|||||||
self.mut_configuration(|configuration| {
|
self.mut_configuration(|configuration| {
|
||||||
let from_index = configuration.groups.iter().position(|group| group.id == from_id);
|
let from_index = configuration.groups.iter().position(|group| group.id == from_id);
|
||||||
let to_index = configuration.groups.iter().position(|group| group.id == to_id);
|
let to_index = configuration.groups.iter().position(|group| group.id == to_id);
|
||||||
|
tracing::trace!("Swap group index:{:?} with index:{:?}", from_index, to_index);
|
||||||
if let (Some(from), Some(to)) = (from_index, to_index) {
|
if let (Some(from), Some(to)) = (from_index, to_index) {
|
||||||
configuration.groups.swap(from, to);
|
configuration.groups.swap(from, to);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user