From da987ed21784d278ff64756163d8d400c813d7f7 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 30 Mar 2016 16:04:43 -0700 Subject: [PATCH] Snackbar opacity animation shouldn't trigger on reverse Fixes #617 --- .../flutter/lib/src/animation/curves.dart | 19 +++++++++++++++++++ .../flutter/lib/src/material/dropdown.dart | 4 ++-- .../flutter/lib/src/material/snack_bar.dart | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/animation/curves.dart b/packages/flutter/lib/src/animation/curves.dart index d6c5f9bef2..40b9082545 100644 --- a/packages/flutter/lib/src/animation/curves.dart +++ b/packages/flutter/lib/src/animation/curves.dart @@ -95,6 +95,25 @@ class Interval extends Curve { } } +/// A curve that is 0.0 until it hits the threshold, then it jumps to 1.0. +class Step extends Curve { + const Step(this.threshold); + + /// The value before which the curve is 0.0 and after which the curve is 1.0. + /// + /// At exactly step, the curve has the value 1.0. + final double threshold; + + @override + double transform(double t) { + assert(threshold >= 0.0); + assert(threshold <= 1.0); + if (t == 0.0 || t == 1.0) + return t; + return t < threshold ? 0.0 : 1.0; + } +} + /// A cubic polynomial mapping of the unit interval. class Cubic extends Curve { const Cubic(this.a, this.b, this.c, this.d); diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index b4b6eb88d5..d0e594efd9 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -82,7 +82,7 @@ class _DropDownMenu extends StatusTransitionWidget { for (int itemIndex = 0; itemIndex < route.items.length; ++itemIndex) { CurvedAnimation opacity; if (itemIndex == route.selectedIndex) { - opacity = new CurvedAnimation(parent: route.animation, curve: const Interval(0.0, 0.001), reverseCurve: const Interval(0.75, 1.0)); + opacity = new CurvedAnimation(parent: route.animation, curve: const Step(0.0), reverseCurve: const Interval(0.75, 1.0)); } else { final double start = (0.5 + (itemIndex + 1) * unit).clamp(0.0, 1.0); final double end = (start + 1.5 * unit).clamp(0.0, 1.0); @@ -112,7 +112,7 @@ class _DropDownMenu extends StatusTransitionWidget { final CurvedAnimation resize = new CurvedAnimation( parent: route.animation, curve: const Interval(0.25, 0.5), - reverseCurve: const Interval(0.0, 0.001) + reverseCurve: const Step(0.0) ); final Tween menuTop = new Tween( diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index e5bf115369..528f505520 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -105,7 +105,7 @@ class SnackBar extends StatelessWidget { if (action != null) children.add(action); CurvedAnimation heightAnimation = new CurvedAnimation(parent: animation, curve: _snackBarHeightCurve); - CurvedAnimation fadeAnimation = new CurvedAnimation(parent: animation, curve: _snackBarFadeCurve); + CurvedAnimation fadeAnimation = new CurvedAnimation(parent: animation, curve: _snackBarFadeCurve, reverseCurve: const Step(0.0)); ThemeData theme = Theme.of(context); return new ClipRect( child: new AnimatedBuilder(