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

Changed position to position + 1 to fix logic #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -70,3 +70,6 @@ build/
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
example/ios/Flutter/flutter_export_environment.sh
example/pubspec.lock
pubspec.lock
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.1.4] - 2019-05-02
### Added
- [#10](https://github.com/mobiten/flutter_staggered_animations/issues/10) Takes a lot of time to animate...
- Added property resetDelayEvery to reset the delay every N rows (optional)

## [0.1.3] - 2019-05-01
### Fixed
- Fixed position 0 and 1 loading at the same time

## [0.1.2] - 2019-09-11
### Fixed
- [#1](https://github.com/mobiten/flutter_staggered_animations/issues/1) Do not forward animation after dispose
Expand Down
9 changes: 9 additions & 0 deletions lib/src/animation_configuration.dart
Expand Up @@ -26,6 +26,12 @@ class AnimationConfiguration extends InheritedWidget {
/// The column count of the grid
final int columnCount;

/// How many rows on the `mainAxis` until the delay is reset to 0.
/// Use on very long `ListView` or `GridView` to avoid a very high [delay].
/// Keep the number similar to the expected number of rows in screen.
/// An alternative to `AnimationLimiter`.
final int resetDelayEvery;

/// Configure the children's animation to be synchronized (all the children's animation start at the same time).
///
/// Default value for [duration] is 225ms.
Expand All @@ -38,6 +44,7 @@ class AnimationConfiguration extends InheritedWidget {
}) : position = 0,
delay = Duration.zero,
columnCount = 1,
resetDelayEvery = 1,
assert(duration != null),
assert(child != null),
super(key: key, child: child);
Expand Down Expand Up @@ -66,6 +73,7 @@ class AnimationConfiguration extends InheritedWidget {
@required this.position,
this.duration = const Duration(milliseconds: 225),
this.delay,
this.resetDelayEvery,
@required Widget child,
}) : columnCount = 1,
assert(duration != null),
Expand Down Expand Up @@ -98,6 +106,7 @@ class AnimationConfiguration extends InheritedWidget {
@required this.position,
this.duration = const Duration(milliseconds: 225),
this.delay,
this.resetDelayEvery,
@required this.columnCount,
@required Widget child,
}) : assert(duration != null),
Expand Down
26 changes: 18 additions & 8 deletions lib/src/animation_configurator.dart
Expand Up @@ -34,30 +34,40 @@ class AnimationConfigurator extends StatelessWidget {
);
}

final _position = animationConfiguration.position ?? 0;
final _position = animationConfiguration.position ?? 0 + 1;
final _duration = duration ?? animationConfiguration.duration;
final _delay = delay ?? animationConfiguration.delay;
final _columnCount = animationConfiguration.columnCount;
final _resetDelayEvery = animationConfiguration.resetDelayEvery;

return AnimationExecutor(
duration: _duration,
delay: stagger(_position, _duration, _delay, _columnCount),
delay:
stagger(_position, _duration, _delay, _columnCount, _resetDelayEvery),
builder: (context, animationController) =>
animatedChildBuilder(animationController),
);
}

Duration stagger(
int position, Duration duration, Duration delay, int columnCount) {
var delayInMilliseconds =
(delay == null ? duration.inMilliseconds ~/ 6 : delay.inMilliseconds);
Duration stagger(int position, Duration duration, Duration delay,
int columnCount, int resetDelayEvery) {
final delayInMilliseconds =
(delay?.inMilliseconds ?? duration.inMilliseconds ~/ 6);

int _computeStaggeredGridDuration() {
return (position ~/ columnCount + position % columnCount) *
delayInMilliseconds;
var row = position ~/ columnCount;
if (resetDelayEvery != null) {
row = row % resetDelayEvery;
}
var calculatedPosition = row + position % columnCount;
return calculatedPosition * delayInMilliseconds;
}

int _computeStaggeredListDuration() {
if (resetDelayEvery != null) {
return (position ~/ resetDelayEvery) * delayInMilliseconds;
}

return position * delayInMilliseconds;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: flutter_staggered_animations
description: Easily add staggered animations to your ListView, GridView, Column and Row children as shown in Material Design guidelines
version: 0.1.2
version: 0.1.4
authors:
- Aurélien Lepage <aurelien@mobiten.com>
- Charles-Henri Dumalin <charles-henri@mobiten.com>
Expand Down