chore: reduce rebuild when end dragging

This commit is contained in:
appflowy 2022-08-30 09:39:20 +08:00
parent 236fcedcd3
commit 4b7713d7b8
4 changed files with 21 additions and 7 deletions

View File

@ -26,7 +26,7 @@ class Log {
static void trace(String? message) { static void trace(String? message) {
if (enableLog) { if (enableLog) {
// debugPrint('❗️[Trace] - ${DateTime.now().second}=> $message'); debugPrint('❗️[Trace] - ${DateTime.now().second}=> $message');
} }
} }
} }

View File

@ -112,7 +112,7 @@ class AFBoardColumnWidget extends StatefulWidget {
this.cornerRadius = 0.0, this.cornerRadius = 0.0,
this.backgroundColor = Colors.transparent, this.backgroundColor = Colors.transparent,
}) : globalKey = GlobalObjectKey(dataSource.columnData.id), }) : globalKey = GlobalObjectKey(dataSource.columnData.id),
config = const ReorderFlexConfig(), config = const ReorderFlexConfig(setStateWhenEndDrag: false),
super(key: key); super(key: key);
@override @override

View File

@ -46,12 +46,20 @@ class ReorderFlexConfig {
// How long an animation to scroll to an off-screen element // How long an animation to scroll to an off-screen element
final Duration scrollAnimationDuration = const Duration(milliseconds: 300); final Duration scrollAnimationDuration = const Duration(milliseconds: 300);
/// Determines if setSatte method needs to be called when the drag is complete.
/// Default value is [true].
///
/// If the [ReorderFlex] will be rebuild after the [ReorderFlex]'s children
/// were changed, then the [setStateWhenEndDrag] should set to [false].
final bool setStateWhenEndDrag;
final bool useMoveAnimation; final bool useMoveAnimation;
final bool useMovePlaceholder; final bool useMovePlaceholder;
const ReorderFlexConfig({ const ReorderFlexConfig({
this.useMoveAnimation = true, this.useMoveAnimation = true,
this.setStateWhenEndDrag = true,
}) : useMovePlaceholder = !useMoveAnimation; }) : useMovePlaceholder = !useMoveAnimation;
} }
@ -370,11 +378,11 @@ class ReorderFlexState extends State<ReorderFlex>
}, },
onDragEnded: (dragTargetData) { onDragEnded: (dragTargetData) {
if (!mounted) return; if (!mounted) return;
Log.debug( Log.debug(
"[DragTarget]: Column:[${widget.dataSource.identifier}] end dragging"); "[DragTarget]: Column:[${widget.dataSource.identifier}] end dragging");
_notifier.updateDragTargetIndex(-1); _notifier.updateDragTargetIndex(-1);
setState(() {
onDragEnded() {
if (dragTargetData.reorderFlexId == widget.reorderFlexId) { if (dragTargetData.reorderFlexId == widget.reorderFlexId) {
_onReordered( _onReordered(
dragState.dragStartIndex, dragState.dragStartIndex,
@ -383,7 +391,13 @@ class ReorderFlexState extends State<ReorderFlex>
} }
dragState.endDragging(); dragState.endDragging();
widget.onDragEnded?.call(); widget.onDragEnded?.call();
}); }
if (widget.config.setStateWhenEndDrag) {
setState(() => onDragEnded());
} else {
onDragEnded();
}
}, },
onWillAccept: (FlexDragTargetData dragTargetData) { onWillAccept: (FlexDragTargetData dragTargetData) {
// Do not receive any events if the Insert item is animating. // Do not receive any events if the Insert item is animating.

View File

@ -28,14 +28,14 @@ packages:
path: "packages/appflowy_board" path: "packages/appflowy_board"
relative: true relative: true
source: path source: path
version: "0.0.5" version: "0.0.6"
appflowy_editor: appflowy_editor:
dependency: "direct main" dependency: "direct main"
description: description:
path: "packages/appflowy_editor" path: "packages/appflowy_editor"
relative: true relative: true
source: path source: path
version: "0.0.2" version: "0.0.3"
args: args:
dependency: transitive dependency: transitive
description: description: