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

Add reverseCurve parameter #96

Open
wants to merge 1 commit into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ Text("Hello World!").animate().fade().scale()
> **NOTE:** The shortform style is used in this README, but all functionality is
> available in either format.

Delay, duration, curve
Delay, duration, curve, reverseCurve
----------------------------------------

Effects have optional `delay`, `duration`, and `curve` parameters. Effects run
Effects have optional `delay`, `duration`, `curve`, and `reverseCurve` parameters. Effects run
in parallel, but you can use a `delay` to run them sequentially:

``` dart
Expand Down
2 changes: 2 additions & 0 deletions lib/src/animate.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_animate/src/warn.dart';

import '../flutter_animate.dart';

/// The Flutter Animate library makes adding beautiful animated effects to your widgets
Expand Down Expand Up @@ -250,6 +251,7 @@ class Animate extends StatefulWidget with AnimateManager<Animate> {
delay: delay,
duration: effect.duration ?? prior?.duration ?? Animate.defaultDuration,
curve: effect.curve ?? prior?.curve ?? Animate.defaultCurve,
reverseCurve: effect.reverseCurve ?? prior?.reverseCurve,
owner: this,
);

Expand Down
9 changes: 9 additions & 0 deletions lib/src/effects/blur_effect.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

Expand All @@ -20,12 +21,14 @@ class BlurEffect extends Effect<Offset> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
Offset? begin,
Offset? end,
}) : super(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? neutralValue,
end: end ?? (begin == null ? defaultValue : neutralValue),
);
Expand Down Expand Up @@ -87,6 +90,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) {
Expand All @@ -96,6 +100,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: BlurEffect.neutralValue.copyWith(dx: begin),
end: BlurEffect.neutralValue.copyWith(dx: end),
));
Expand All @@ -107,6 +112,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) {
Expand All @@ -116,6 +122,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: BlurEffect.neutralValue.copyWith(dy: begin),
end: BlurEffect.neutralValue.copyWith(dy: end),
));
Expand All @@ -127,6 +134,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) {
Expand All @@ -136,6 +144,7 @@ extension BlurEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: Offset(begin, begin),
end: Offset(end, end),
));
Expand Down
4 changes: 4 additions & 0 deletions lib/src/effects/box_shadow_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class BoxShadowEffect extends Effect<BoxShadow> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
BoxShadow? begin,
BoxShadow? end,
this.borderRadius,
}) : super(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? neutralValue,
end: end ?? (begin == null ? defaultValue : neutralValue),
);
Expand Down Expand Up @@ -61,6 +63,7 @@ extension BoxShadowEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
BoxShadow? begin,
BoxShadow? end,
BorderRadius? borderRadius,
Expand All @@ -69,6 +72,7 @@ extension BoxShadowEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin,
end: end,
borderRadius: borderRadius,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/effects/color_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class ColorEffect extends Effect<Color?> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
Color? begin,
Color? end,
this.blendMode,
}) : super(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? neutralValue,
end: end ?? (begin == null ? defaultValue : neutralValue),
);
Expand Down Expand Up @@ -72,6 +74,7 @@ extension ColorEffectExtension<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
Color? begin,
Color? end,
BlendMode? blendMode,
Expand All @@ -80,6 +83,7 @@ extension ColorEffectExtension<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin,
end: end,
blendMode: blendMode,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/effects/crossfade_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ class CrossfadeEffect extends Effect<double> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
required this.builder,
this.alignment,
}) : super(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: 0,
end: 1,
);
Expand Down Expand Up @@ -54,13 +56,15 @@ extension CrossfadeEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
required WidgetBuilder builder,
Alignment? alignment,
}) =>
addEffect(CrossfadeEffect(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
builder: builder,
alignment: alignment,
));
Expand Down
7 changes: 6 additions & 1 deletion lib/src/effects/custom_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ class CustomEffect extends Effect<double> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) : super(
delay: delay,
duration: duration,
curve: curve,
begin: begin ?? 0.0, // Should this use "smart" defaults?
reverseCurve: reverseCurve,
begin: begin ?? 0.0,
// Should this use "smart" defaults?
end: end ?? 1.0,
);

Expand Down Expand Up @@ -61,6 +64,7 @@ extension CustomEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) =>
Expand All @@ -69,6 +73,7 @@ extension CustomEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin,
end: end,
));
Expand Down
14 changes: 13 additions & 1 deletion lib/src/effects/effect.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import '../../flutter_animate.dart';

/// An empty effect that all other effects extend.
Expand All @@ -23,6 +24,10 @@ class Effect<T> {
/// previous effect, or use [Animate.defaultCurve] if this is the first effect.
final Curve? curve;

/// The specified easing curve for the effect. If null, will inherit the curve from the
/// previous effect, or use [Animate.defaultCurve] if this is the first effect.
final Curve? reverseCurve;

/// The begin value for the effect. If null, effects should use a reasonable
/// default value when appropriate.
final T? begin;
Expand All @@ -31,7 +36,14 @@ class Effect<T> {
/// default value when appropriate.
final T? end;

const Effect({this.delay, this.duration, this.curve, this.begin, this.end});
const Effect({
this.delay,
this.duration,
this.curve,
this.reverseCurve,
this.begin,
this.end,
});

/// Builds the widgets that implement the effect on the target [child],
/// based on the provided [AnimationController] and [EffectEntry].
Expand Down
4 changes: 4 additions & 0 deletions lib/src/effects/elevation_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ElevationEffect extends Effect<double> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
Color? color,
Expand All @@ -27,6 +28,7 @@ class ElevationEffect extends Effect<double> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? neutralValue,
end: end ?? (begin == null ? defaultValue : neutralValue),
);
Expand Down Expand Up @@ -61,6 +63,7 @@ extension ElevationEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
Color? color,
Expand All @@ -70,6 +73,7 @@ extension ElevationEffectExtensions<T> on AnimateManager<T> {
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin,
end: end,
color: color,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/effects/fade_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class FadeEffect extends Effect<double> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) : super(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? (end == null ? defaultValue : neutralValue),
end: end ?? neutralValue,
);
Expand All @@ -44,13 +46,15 @@ extension FadeEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
double? end,
}) =>
addEffect(FadeEffect(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin,
end: end,
));
Expand All @@ -61,12 +65,14 @@ extension FadeEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
}) =>
addEffect(FadeEffect(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? FadeEffect.defaultValue,
end: 1.0,
));
Expand All @@ -77,12 +83,14 @@ extension FadeEffectExtensions<T> on AnimateManager<T> {
Duration? delay,
Duration? duration,
Curve? curve,
Curve? reverseCurve,
double? begin,
}) =>
addEffect(FadeEffect(
delay: delay,
duration: duration,
curve: curve,
reverseCurve: reverseCurve,
begin: begin ?? FadeEffect.neutralValue,
end: 0.0,
));
Expand Down
Loading