Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last item animation #68

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#v1.0.7

# Changelog

## Bug Fixes
- List Will Not Animate When New Item Is Added to the End of the List

## Enhancement
- Allow Disabling Long Press to Start Reorder Gesture

# v1.0.6

# Changelog
Expand Down
3 changes: 2 additions & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class _HomePageState extends State<HomePage> {
addedNumber += 1;

setState(() {
list.insert(1, User(name: "User $addedNumber", index: addedNumber));
list.insert(
list.length, User(name: "User $addedNumber", index: addedNumber));
});
}

Expand Down
30 changes: 15 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.0.6"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -86,26 +86,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -134,10 +134,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.12.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -195,10 +195,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.7.0"
vector_math:
dependency: transitive
description:
Expand All @@ -211,10 +211,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "13.0.0"
version: "14.2.1"
sdks:
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=1.17.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
5 changes: 5 additions & 0 deletions lib/src/animated_reorderable_gridview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class AnimatedReorderableGridView<E extends Object> extends StatelessWidget {
/// transition for the widget that is built.
final AnimatedWidgetBuilder? removeItemBuilder;

/// Whether the items can be dragged by long pressing on them.
final bool longPressDraggable;

const AnimatedReorderableGridView({
Key? key,
required this.items,
Expand All @@ -200,6 +203,7 @@ class AnimatedReorderableGridView<E extends Object> extends StatelessWidget {
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.dragStartBehavior = DragStartBehavior.start,
this.clipBehavior = Clip.hardEdge,
this.longPressDraggable = true,
this.insertItemBuilder,
this.removeItemBuilder,
}) : super(key: key);
Expand Down Expand Up @@ -235,6 +239,7 @@ class AnimatedReorderableGridView<E extends Object> extends StatelessWidget {
scrollDirection: scrollDirection,
insertItemBuilder: insertItemBuilder,
removeItemBuilder: removeItemBuilder,
longPressDraggable: longPressDraggable,
),
),
]);
Expand Down
58 changes: 31 additions & 27 deletions lib/src/animated_reorderable_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,33 +188,36 @@ class AnimatedReorderableListView<E extends Object> extends StatefulWidget {
/// transition for the widget that is built.
final AnimatedWidgetBuilder? removeItemBuilder;

const AnimatedReorderableListView(
{Key? key,
required this.items,
required this.itemBuilder,
required this.onReorder,
this.enterTransition,
this.exitTransition,
this.insertDuration,
this.removeDuration,
this.onReorderStart,
this.onReorderEnd,
this.proxyDecorator,
this.scrollDirection = Axis.vertical,
this.padding,
this.reverse = false,
this.controller,
this.primary,
this.physics,
this.scrollBehavior,
this.restorationId,
this.buildDefaultDragHandles = true,
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.dragStartBehavior = DragStartBehavior.start,
this.clipBehavior = Clip.hardEdge,
this.insertItemBuilder,
this.removeItemBuilder})
: super(key: key);
final bool longPressDraggable;

const AnimatedReorderableListView({
Key? key,
required this.items,
required this.itemBuilder,
required this.onReorder,
this.enterTransition,
this.exitTransition,
this.insertDuration,
this.removeDuration,
this.onReorderStart,
this.onReorderEnd,
this.proxyDecorator,
this.scrollDirection = Axis.vertical,
this.padding,
this.reverse = false,
this.controller,
this.primary,
this.physics,
this.scrollBehavior,
this.restorationId,
this.buildDefaultDragHandles = true,
this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
this.dragStartBehavior = DragStartBehavior.start,
this.clipBehavior = Clip.hardEdge,
this.insertItemBuilder,
this.removeItemBuilder,
this.longPressDraggable = true,
}) : super(key: key);

@override
State<AnimatedReorderableListView<E>> createState() =>
Expand Down Expand Up @@ -254,6 +257,7 @@ class _AnimatedReorderableListViewState<E extends Object>
scrollDirection: widget.scrollDirection,
insertItemBuilder: widget.insertItemBuilder,
removeItemBuilder: widget.removeItemBuilder,
longPressDraggable: widget.longPressDraggable,
),
),
]);
Expand Down
14 changes: 13 additions & 1 deletion lib/src/builder/motion_animated_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MotionBuilder<E> extends StatefulWidget {
final Axis scrollDirection;
final SliverGridDelegate? delegateBuilder;
final bool buildDefaultDragHandles;
final bool longPressDraggable;

const MotionBuilder(
{Key? key,
Expand All @@ -42,7 +43,8 @@ class MotionBuilder<E> extends StatefulWidget {
this.initialCount = 0,
this.delegateBuilder,
this.scrollDirection = Axis.vertical,
required this.buildDefaultDragHandles})
required this.buildDefaultDragHandles,
this.longPressDraggable = false})
: assert(initialCount >= 0),
super(key: key);

Expand Down Expand Up @@ -504,6 +506,7 @@ class MotionBuilderState extends State<MotionBuilder>
});
} else {
childrenMap[itemIndex] = motionData;
sizeController.value = kAlwaysCompleteAnimation.value;
controller.forward().then<void>((_) {
_removeActiveItemAt(_incomingItems, incomingItem.itemIndex)!
.controller!
Expand Down Expand Up @@ -692,6 +695,14 @@ class MotionBuilderState extends State<MotionBuilder>
return true;
}());
final Key itemGlobalKey = _MotionBuilderItemGlobalKey(item.key!, this);

if (!widget.longPressDraggable) {
return ReorderableGridDragStartListener(
key: itemGlobalKey,
index: index,
child: itemWithSemantics,
);
}
if (widget.buildDefaultDragHandles) {
switch (Theme.of(context).platform) {
case TargetPlatform.linux:
Expand Down Expand Up @@ -835,6 +846,7 @@ class MotionBuilderState extends State<MotionBuilder>
final Animation<double> sizeAnimation =
incomingItem?.sizeAnimation ?? kAlwaysCompleteAnimation;
return SizeTransition(
axis: widget.scrollDirection,
sizeFactor: sizeAnimation,
child: widget.insertAnimationBuilder(context, child, animation));
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/builder/motion_list_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class MotionListBase<W extends Widget, E extends Object>
final AnimatedWidgetBuilder? insertItemBuilder;
final AnimatedWidgetBuilder? removeItemBuilder;
final bool? buildDefaultDragHandles;
final bool? longPressDraggable;

const MotionListBase(
{Key? key,
Expand All @@ -48,7 +49,8 @@ abstract class MotionListBase<W extends Widget, E extends Object>
this.sliverGridDelegate,
this.insertItemBuilder,
this.removeItemBuilder,
this.buildDefaultDragHandles})
this.buildDefaultDragHandles,
this.longPressDraggable})
: super(key: key);
}

Expand Down Expand Up @@ -123,6 +125,10 @@ abstract class MotionListBaseState<
@protected
bool get buildDefaultDragHandles => widget.buildDefaultDragHandles ?? false;

@nonVirtual
@protected
bool get longPressDraggable => widget.longPressDraggable ?? false;

@override
void initState() {
super.initState();
Expand Down
13 changes: 9 additions & 4 deletions lib/src/builder/motion_list_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class MotionListImpl<E extends Object> extends MotionListBase<Widget, E> {
required Axis scrollDirection,
AnimatedWidgetBuilder? insertItemBuilder,
AnimatedWidgetBuilder? removeItemBuilder,
bool? buildDefaultDragHandles})
bool? buildDefaultDragHandles,
bool? longPressDraggable})
: super(
key: key,
items: items,
Expand All @@ -36,7 +37,8 @@ class MotionListImpl<E extends Object> extends MotionListBase<Widget, E> {
scrollDirection: scrollDirection,
insertItemBuilder: insertItemBuilder,
removeItemBuilder: removeItemBuilder,
buildDefaultDragHandles: buildDefaultDragHandles);
buildDefaultDragHandles: buildDefaultDragHandles,
longPressDraggable: longPressDraggable);

const MotionListImpl.grid(
{Key? key,
Expand All @@ -54,7 +56,8 @@ class MotionListImpl<E extends Object> extends MotionListBase<Widget, E> {
required Axis scrollDirection,
AnimatedWidgetBuilder? insertItemBuilder,
AnimatedWidgetBuilder? removeItemBuilder,
bool? buildDefaultDragHandles})
bool? buildDefaultDragHandles,
bool? longPressDraggable})
: super(
key: key,
items: items,
Expand All @@ -71,7 +74,8 @@ class MotionListImpl<E extends Object> extends MotionListBase<Widget, E> {
scrollDirection: scrollDirection,
insertItemBuilder: insertItemBuilder,
removeItemBuilder: removeItemBuilder,
buildDefaultDragHandles: buildDefaultDragHandles);
buildDefaultDragHandles: buildDefaultDragHandles,
longPressDraggable: longPressDraggable);

@override
MotionListImplState<E> createState() => MotionListImplState<E>();
Expand All @@ -96,6 +100,7 @@ class MotionListImplState<E extends Object>
scrollDirection: scrollDirection,
delegateBuilder: sliverGridDelegate,
buildDefaultDragHandles: buildDefaultDragHandles,
longPressDraggable: longPressDraggable,
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: animated_reorderable_list
description: A Flutter Reorderable Animated List with simple implementation and smooth transition.
version: 1.0.6
version: 1.0.7
repository: https://github.com/canopas/animated_reorderable_list

environment:
Expand Down
Loading