diff --git a/lib/src/animation/provider/animation_effect.dart b/lib/src/animation/provider/animation_effect.dart index e22f81c..8dba29e 100644 --- a/lib/src/animation/provider/animation_effect.dart +++ b/lib/src/animation/provider/animation_effect.dart @@ -53,17 +53,16 @@ class EffectEntry { Duration get begin => delay; /// The end time for this entry. - Duration get end => duration; + Duration get end => begin+duration; /// Builds a sub-animation based on the properties of this entry. CurveTween buildAnimation({ required Duration totalDuration, Curve? curve, }) { - int ttlT = duration.inMicroseconds; int beginT = begin.inMicroseconds, endT = end.inMicroseconds; return CurveTween( - curve: Interval(beginT / ttlT, endT / totalDuration.inMicroseconds, + curve: Interval(beginT / totalDuration.inMicroseconds, endT / totalDuration.inMicroseconds, curve: curve ?? this.curve), ); } diff --git a/lib/src/builder/motion_animated_builder.dart b/lib/src/builder/motion_animated_builder.dart index ff884ea..68c13f2 100644 --- a/lib/src/builder/motion_animated_builder.dart +++ b/lib/src/builder/motion_animated_builder.dart @@ -115,6 +115,7 @@ class MotionBuilderState extends State for (int i = 0; i < widget.initialCount; i++) { childrenMap[i] = MotionData(); } + super.initState(); } @@ -485,10 +486,10 @@ class MotionBuilderState extends State if (entry.key == itemIndex) { updatedChildrenMap[itemIndex] = motionData; updatedChildrenMap[entry.key + 1] = - entry.value.copyWith(startOffset: _itemOffsetAt(entry.key)); + entry.value.copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key+1), visible: false); } else if (entry.key > itemIndex) { updatedChildrenMap[entry.key + 1] = - entry.value.copyWith(startOffset: _itemOffsetAt(entry.key)); + entry.value.copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key+1), visible: false); } else { updatedChildrenMap[entry.key] = entry.value; } @@ -586,7 +587,7 @@ class MotionBuilderState extends State continue; } else { updatedChildrenMap[entry.key - 1] = childrenMap[entry.key]! - .copyWith(startOffset: _itemOffsetAt(entry.key)); + .copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key-1), visible: false); } } } @@ -600,11 +601,14 @@ class MotionBuilderState extends State final itemRenderBox = _items[index]?.context.findRenderObject() as RenderBox?; if (itemRenderBox == null) return Offset.zero; + + return itemRenderBox.localToGlobal(Offset.zero); } @override Widget build(BuildContext context) { + super.build(context); return widget.delegateBuilder != null ? SliverGrid( @@ -648,6 +652,7 @@ class MotionBuilderState extends State index: index, key: itemGlobalKey, motionData: motionData, + isGrid: isGrid, updateMotionData: (MotionData motionData) { final itemOffset = _itemOffsetAt(index); childrenMap[index] = motionData.copyWith( diff --git a/lib/src/builder/motion_list_base.dart b/lib/src/builder/motion_list_base.dart index dac099b..265e0b2 100644 --- a/lib/src/builder/motion_list_base.dart +++ b/lib/src/builder/motion_list_base.dart @@ -156,23 +156,22 @@ abstract class MotionListBaseState< void addEffect(AnimationEffect effect, List enteries, {required bool enter}) { Duration zero = Duration.zero; - - if (effect.duration != null) { - if (enter) { - _enterDuration = effect.duration! > _enterDuration - ? effect.duration! + final timeForAnimation= (effect.delay??zero) + (effect.duration??kAnimationDuration); + if (enter) { + _enterDuration = timeForAnimation > _enterDuration + ? timeForAnimation : _enterDuration; assert(_enterDuration >= zero, "Duration can not be negative"); } else { _exitDuration = - effect.duration! > _exitDuration ? effect.duration! : _exitDuration; + timeForAnimation > _exitDuration ? timeForAnimation : _exitDuration; assert(_exitDuration >= zero, "Duration can not be negative"); } - } + EffectEntry entry = EffectEntry( animationEffect: effect, delay: effect.delay ?? zero, - duration: effect.duration ?? removeDuration, + duration: effect.duration ?? kAnimationDuration, curve: effect.curve ?? Curves.linear); enteries.add(entry); @@ -203,7 +202,7 @@ abstract class MotionListBaseState< Widget animatedChild = child; for (EffectEntry entry in _enterAnimations) { animatedChild = entry.animationEffect - .build(context, animatedChild, animation, entry, enterDuration); + .build(context, animatedChild, animation, entry, insertDuration); } return animatedChild; } @@ -219,7 +218,7 @@ abstract class MotionListBaseState< Widget animatedChild = child; for (EffectEntry entry in _exitAnimations) { animatedChild = entry.animationEffect - .build(context, animatedChild, animation, entry, exitDuration); + .build(context, animatedChild, animation, entry, removeDuration); } return animatedChild; } diff --git a/lib/src/component/motion_animated_content.dart b/lib/src/component/motion_animated_content.dart index 4913ee4..101895e 100644 --- a/lib/src/component/motion_animated_content.dart +++ b/lib/src/component/motion_animated_content.dart @@ -6,6 +6,7 @@ class MotionAnimatedContent extends StatefulWidget { final Widget child; final Function(MotionData)? updateMotionData; final CapturedThemes? capturedThemes; + final bool isGrid; const MotionAnimatedContent( {Key? key, @@ -13,7 +14,9 @@ class MotionAnimatedContent extends StatefulWidget { required this.motionData, required this.child, this.updateMotionData, - required this.capturedThemes}) + required this.capturedThemes, + required this.isGrid, + }) : super(key: key); @override @@ -86,6 +89,9 @@ class MotionAnimatedContentState extends State visible = true; }); } + if(oldWidget.index!= widget.index && !_dragging && widget.isGrid){ + _updateAnimationTranslation(); + } widget.updateMotionData?.call(widget.motionData); }); super.didUpdateWidget(oldWidget);