Skip to content

Commit 03a5756

Browse files
authored
Merge pull request #930 from AppFlowy-IO/feat/reorder_flex_opti
chore: reduce rebuild when end dragging
2 parents 236fced + 4b7713d commit 03a5756

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

frontend/app_flowy/packages/appflowy_board/lib/src/utils/log.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Log {
2626

2727
static void trace(String? message) {
2828
if (enableLog) {
29-
// debugPrint('❗️[Trace] - ${DateTime.now().second}=> $message');
29+
debugPrint('❗️[Trace] - ${DateTime.now().second}=> $message');
3030
}
3131
}
3232
}

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/board_column/board_column.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class AFBoardColumnWidget extends StatefulWidget {
112112
this.cornerRadius = 0.0,
113113
this.backgroundColor = Colors.transparent,
114114
}) : globalKey = GlobalObjectKey(dataSource.columnData.id),
115-
config = const ReorderFlexConfig(),
115+
config = const ReorderFlexConfig(setStateWhenEndDrag: false),
116116
super(key: key);
117117

118118
@override

frontend/app_flowy/packages/appflowy_board/lib/src/widgets/reorder_flex/reorder_flex.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ class ReorderFlexConfig {
4646
// How long an animation to scroll to an off-screen element
4747
final Duration scrollAnimationDuration = const Duration(milliseconds: 300);
4848

49+
/// Determines if setSatte method needs to be called when the drag is complete.
50+
/// Default value is [true].
51+
///
52+
/// If the [ReorderFlex] will be rebuild after the [ReorderFlex]'s children
53+
/// were changed, then the [setStateWhenEndDrag] should set to [false].
54+
final bool setStateWhenEndDrag;
55+
4956
final bool useMoveAnimation;
5057

5158
final bool useMovePlaceholder;
5259

5360
const ReorderFlexConfig({
5461
this.useMoveAnimation = true,
62+
this.setStateWhenEndDrag = true,
5563
}) : useMovePlaceholder = !useMoveAnimation;
5664
}
5765

@@ -370,11 +378,11 @@ class ReorderFlexState extends State<ReorderFlex>
370378
},
371379
onDragEnded: (dragTargetData) {
372380
if (!mounted) return;
373-
374381
Log.debug(
375382
"[DragTarget]: Column:[${widget.dataSource.identifier}] end dragging");
376383
_notifier.updateDragTargetIndex(-1);
377-
setState(() {
384+
385+
onDragEnded() {
378386
if (dragTargetData.reorderFlexId == widget.reorderFlexId) {
379387
_onReordered(
380388
dragState.dragStartIndex,
@@ -383,7 +391,13 @@ class ReorderFlexState extends State<ReorderFlex>
383391
}
384392
dragState.endDragging();
385393
widget.onDragEnded?.call();
386-
});
394+
}
395+
396+
if (widget.config.setStateWhenEndDrag) {
397+
setState(() => onDragEnded());
398+
} else {
399+
onDragEnded();
400+
}
387401
},
388402
onWillAccept: (FlexDragTargetData dragTargetData) {
389403
// Do not receive any events if the Insert item is animating.

frontend/app_flowy/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ packages:
2828
path: "packages/appflowy_board"
2929
relative: true
3030
source: path
31-
version: "0.0.5"
31+
version: "0.0.6"
3232
appflowy_editor:
3333
dependency: "direct main"
3434
description:
3535
path: "packages/appflowy_editor"
3636
relative: true
3737
source: path
38-
version: "0.0.2"
38+
version: "0.0.3"
3939
args:
4040
dependency: transitive
4141
description:

0 commit comments

Comments
 (0)