Skip to content

Commit aec5c3e

Browse files
committed
chore: fix insert animation
1 parent 5e6b949 commit aec5c3e

File tree

10 files changed

+111
-58
lines changed

10 files changed

+111
-58
lines changed

frontend/app_flowy/packages/appflowy_board/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Update example
77
* Add AppFlowy style widget
88

9-
## 0.0.2
9+
# 0.0.2
1010

1111
* Update documentation
1212

13-
## 0.0.1
13+
# 0.0.1
1414

1515
* Support drag and drop column
1616
* Support drag and drop column items from one to another

frontend/app_flowy/packages/appflowy_board/example/lib/multi_board_list_example.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
2626
List<AFColumnItem> a = [
2727
TextItem("Card 1"),
2828
TextItem("Card 2"),
29-
// RichTextItem(title: "Card 3", subtitle: 'Aug 1, 2020 4:05 PM'),
29+
RichTextItem(title: "Card 3", subtitle: 'Aug 1, 2020 4:05 PM'),
3030
TextItem("Card 4"),
31+
TextItem("Card 5"),
32+
TextItem("Card 6"),
33+
RichTextItem(title: "Card 7", subtitle: 'Aug 1, 2020 4:05 PM'),
34+
RichTextItem(title: "Card 8", subtitle: 'Aug 1, 2020 4:05 PM'),
35+
TextItem("Card 9"),
3136
];
3237
final column1 = AFBoardColumnData(id: "To Do", items: a);
3338
final column2 = AFBoardColumnData(id: "In Progress", items: <AFColumnItem>[
34-
// RichTextItem(title: "Card 5", subtitle: 'Aug 1, 2020 4:05 PM'),
35-
// TextItem("Card 6"),
39+
RichTextItem(title: "Card 10", subtitle: 'Aug 1, 2020 4:05 PM'),
40+
TextItem("Card 11"),
3641
]);
3742

3843
final column3 = AFBoardColumnData(id: "Done", items: <AFColumnItem>[]);
@@ -93,7 +98,7 @@ class _MultiBoardListExampleState extends State<MultiBoardListExample> {
9398
return Align(
9499
alignment: Alignment.centerLeft,
95100
child: Padding(
96-
padding: const EdgeInsets.symmetric(horizontal: 20),
101+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 40),
97102
child: Text(item.s),
98103
),
99104
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const DART_LOG = "Dart_LOG";
66
class Log {
77
// static const enableLog = bool.hasEnvironment(DART_LOG);
88
// static final shared = Log();
9-
static const enableLog = false;
9+
static const enableLog = true;
1010

1111
static void info(String? message) {
1212
if (enableLog) {
@@ -16,19 +16,19 @@ class Log {
1616

1717
static void debug(String? message) {
1818
if (enableLog) {
19-
debugPrint('🐛[Debug]=> $message');
19+
debugPrint('🐛[Debug] - ${DateTime.now().second}=> $message');
2020
}
2121
}
2222

2323
static void warn(String? message) {
2424
if (enableLog) {
25-
debugPrint('🐛[Warn]=> $message');
25+
debugPrint('🐛[Warn] - ${DateTime.now().second} => $message');
2626
}
2727
}
2828

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class AFBoardDataController extends ChangeNotifier
197197
assert(index != -1);
198198
if (index != -1) {
199199
if (index != newIndex) {
200-
// Log.debug('[$BoardPhantomController] update $toColumnId:$index to $toColumnId:$phantomIndex');
200+
Log.debug(
201+
'[$BoardPhantomController] update $columnId:$index to $columnId:$newIndex');
201202
final item = columnDataController.removeAt(index, notify: false);
202203
columnDataController.insert(newIndex, item, notify: false);
203204
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FlexDragTargetData extends DragTargetData {
4343
}
4444

4545
class DraggingState {
46-
final String id;
46+
final String reorderFlexId;
4747

4848
/// The member of widget.children currently being dragged.
4949
Widget? _draggingWidget;
@@ -72,7 +72,7 @@ class DraggingState {
7272
/// The additional margin to place around a computed drop area.
7373
static const double _dropAreaMargin = 0.0;
7474

75-
DraggingState(this.id);
75+
DraggingState(this.reorderFlexId);
7676

7777
Size get dropAreaSize {
7878
if (feedbackSize == null) {
@@ -132,7 +132,7 @@ class DraggingState {
132132
}
133133

134134
void updateNextIndex(int index) {
135-
Log.trace('updateNextIndex: $index');
135+
Log.trace('$reorderFlexId updateNextIndex: $index');
136136
nextIndex = index;
137137
}
138138

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:appflowy_board/src/utils/log.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter/scheduler.dart';
34
import 'package:provider/provider.dart';
@@ -222,10 +223,10 @@ class DragTargetAnimation {
222223
value: 0, vsync: vsync, duration: reorderAnimationDuration);
223224

224225
insertController = AnimationController(
225-
value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 100));
226+
value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 200));
226227

227228
deleteController = AnimationController(
228-
value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 10));
229+
value: 0.0, vsync: vsync, duration: const Duration(milliseconds: 1));
229230
}
230231

231232
void startDragging() {
@@ -371,6 +372,7 @@ class _DragTargeMovePlaceholderState extends State<DragTargeMovePlaceholder> {
371372
}
372373

373374
abstract class FakeDragTargetEventTrigger {
375+
void fakeOnDragStart(void Function(int?) callback);
374376
void fakeOnDragEnded(VoidCallback callback);
375377
}
376378

@@ -421,6 +423,10 @@ class _FakeDragTargetState<T extends DragTargetData>
421423
/// Start insert animation
422424
widget.insertAnimationController.forward(from: 0.0);
423425

426+
widget.eventTrigger.fakeOnDragStart((insertIndex) {
427+
Log.debug("[$FakeDragTarget] on drag $insertIndex");
428+
});
429+
424430
widget.eventTrigger.fakeOnDragEnded(() {
425431
WidgetsBinding.instance.addPostFrameCallback((_) {
426432
widget.onDragEnded(widget.eventData.dragTargetData as T);

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
24

35
import '../../utils/log.dart';
@@ -8,6 +10,8 @@ import 'reorder_flex.dart';
810
/// [DragTargetInterceptor] is used to intercept the [DragTarget]'s
911
/// [onWillAccept], [OnAccept], and [onLeave] event.
1012
abstract class DragTargetInterceptor {
13+
String get reorderFlexId;
14+
1115
/// Returns [yes] to receive the [DragTarget]'s event.
1216
bool canHandler(FlexDragTargetData dragTargetData);
1317

@@ -37,7 +41,7 @@ abstract class OverlapDragTargetDelegate {
3741
int dragTargetIndex,
3842
);
3943

40-
bool canMoveTo(String dragTargetId);
44+
int canMoveTo(String dragTargetId);
4145
}
4246

4347
/// [OverlappingDragTargetInterceptor] is used to receive the overlapping
@@ -47,6 +51,7 @@ abstract class OverlapDragTargetDelegate {
4751
/// Receive the [DragTarget] event if the [acceptedReorderFlexId] contains
4852
/// the passed in dragTarget' reorderFlexId.
4953
class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
54+
@override
5055
final String reorderFlexId;
5156
final List<String> acceptedReorderFlexId;
5257
final OverlapDragTargetDelegate delegate;
@@ -72,8 +77,11 @@ class OverlappingDragTargetInterceptor extends DragTargetInterceptor {
7277
if (dragTargetId == dragTargetData.reorderFlexId) {
7378
delegate.cancel();
7479
} else {
75-
if (delegate.canMoveTo(dragTargetId)) {
76-
delegate.moveTo(dragTargetId, dragTargetData, 0);
80+
final index = delegate.canMoveTo(dragTargetId);
81+
Log.trace(
82+
'[$OverlappingDragTargetInterceptor] move to $dragTargetId at $index');
83+
if (index != -1) {
84+
delegate.moveTo(dragTargetId, dragTargetData, index);
7785
}
7886
}
7987

@@ -96,6 +104,7 @@ abstract class CrossReorderFlexDragTargetDelegate {
96104
}
97105

98106
class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
107+
@override
99108
final String reorderFlexId;
100109
final List<String> acceptedReorderFlexIds;
101110
final CrossReorderFlexDragTargetDelegate delegate;
@@ -119,8 +128,12 @@ class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
119128
/// If the columnId equal to the dragTargetData's columnId,
120129
/// it means the dragTarget is dragging on the top of its own list.
121130
/// Otherwise, it means the dargTarget was moved to another list.
131+
Log.trace(
132+
"[$CrossReorderFlexDragTargetInterceptor] $reorderFlexId accept ${dragTargetData.reorderFlexId} ${reorderFlexId != dragTargetData.reorderFlexId}");
122133
return reorderFlexId != dragTargetData.reorderFlexId;
123134
} else {
135+
Log.trace(
136+
"[$CrossReorderFlexDragTargetInterceptor] not accept ${dragTargetData.reorderFlexId}");
124137
return false;
125138
}
126139
}
@@ -151,6 +164,9 @@ class CrossReorderFlexDragTargetInterceptor extends DragTargetInterceptor {
151164
dragTargetIndex,
152165
);
153166

167+
Log.debug(
168+
'[$CrossReorderFlexDragTargetInterceptor] dargTargetIndex: $dragTargetIndex, reorderFlexId: $reorderFlexId');
169+
154170
if (isNewDragTarget == false) {
155171
delegate.updateDragTargetData(reorderFlexId, dragTargetIndex);
156172
reorderFlexState.handleOnWillAccept(context, dragTargetIndex);

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class ReorderFlexConfig {
3636
final double draggingWidgetOpacity = 0.3;
3737

3838
// How long an animation to reorder an element
39-
final Duration reorderAnimationDuration = const Duration(milliseconds: 250);
39+
final Duration reorderAnimationDuration = const Duration(milliseconds: 300);
4040

4141
// How long an animation to scroll to an off-screen element
42-
final Duration scrollAnimationDuration = const Duration(milliseconds: 250);
42+
final Duration scrollAnimationDuration = const Duration(milliseconds: 300);
4343

4444
final bool useMoveAnimation;
4545

@@ -213,8 +213,8 @@ class ReorderFlexState extends State<ReorderFlex>
213213
shiftedIndex = dragState.calculateShiftedIndex(childIndex);
214214
}
215215

216-
Log.trace(
217-
'Rebuild: Column:[${dragState.id}] ${dragState.toString()}, childIndex: $childIndex shiftedIndex: $shiftedIndex');
216+
// Log.trace(
217+
// 'Rebuild: Column:[${dragState.id}] ${dragState.toString()}, childIndex: $childIndex shiftedIndex: $shiftedIndex');
218218
final currentIndex = dragState.currentIndex;
219219
final dragPhantomIndex = dragState.phantomIndex;
220220

@@ -330,6 +330,8 @@ class ReorderFlexState extends State<ReorderFlex>
330330
widget.onDragStarted?.call(draggingIndex);
331331
},
332332
onDragEnded: (dragTargetData) {
333+
if (!mounted) return;
334+
333335
Log.debug(
334336
"[DragTarget]: Column:[${widget.dataSource.identifier}] end dragging");
335337
_notifier.updateDragTargetIndex(-1);
@@ -346,21 +348,21 @@ class ReorderFlexState extends State<ReorderFlex>
346348
});
347349
},
348350
onWillAccept: (FlexDragTargetData dragTargetData) {
351+
// Do not receive any events if the Insert item is animating.
349352
if (_animation.deleteController.isAnimating) {
350353
return false;
351354
}
352355

353356
assert(widget.dataSource.items.length > dragTargetIndex);
354-
if (_interceptDragTarget(
355-
dragTargetData,
356-
(interceptor) => interceptor.onWillAccept(
357+
if (_interceptDragTarget(dragTargetData, (interceptor) {
358+
interceptor.onWillAccept(
357359
context: builderContext,
358360
reorderFlexState: this,
359361
dragTargetData: dragTargetData,
360362
dragTargetId: reorderFlexItem.id,
361363
dragTargetIndex: dragTargetIndex,
362-
),
363-
)) {
364+
);
365+
})) {
364366
return true;
365367
} else {
366368
return handleOnWillAccept(builderContext, dragTargetIndex);
@@ -524,7 +526,7 @@ class ReorderFlexState extends State<ReorderFlex>
524526
// screen, then it is already on-screen.
525527
final double margin = widget.direction == Axis.horizontal
526528
? dragState.dropAreaSize.width
527-
: dragState.dropAreaSize.height;
529+
: dragState.dropAreaSize.height / 2.0;
528530
if (_scrollController.hasClients) {
529531
final double scrollOffset = _scrollController.offset;
530532
final double topOffset = max(

0 commit comments

Comments
 (0)