From 837b1a321d3f00034556ef5b385abb93c0843715 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 27 Jul 2020 22:40:08 -0700 Subject: [PATCH] [animations] Remove copy of curves (#182) --- .../lib/src/fade_scale_transition.dart | 6 +- .../lib/src/shared_axis_transition.dart | 29 +++++++- packages/animations/lib/src/utils/curves.dart | 66 ------------------- 3 files changed, 30 insertions(+), 71 deletions(-) delete mode 100644 packages/animations/lib/src/utils/curves.dart diff --git a/packages/animations/lib/src/fade_scale_transition.dart b/packages/animations/lib/src/fade_scale_transition.dart index 63d217c42f15..19d76597ebac 100644 --- a/packages/animations/lib/src/fade_scale_transition.dart +++ b/packages/animations/lib/src/fade_scale_transition.dart @@ -2,13 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' + hide decelerateEasing; // ignore: undefined_hidden_name +// TODO(goderbauer): Remove implementation import when material properly exports the file. +import 'package:flutter/src/material/curves.dart'; // ignore: implementation_imports // TODO(shihaohong): Remove DualTransitionBuilder once flutter/flutter's `stable` // branch contains DualTransitionBuilder. import 'dual_transition_builder.dart' as dual_transition_builder; import 'modal.dart'; -import 'utils/curves.dart'; /// The modal transition configuration for a Material fade transition. /// diff --git a/packages/animations/lib/src/shared_axis_transition.dart b/packages/animations/lib/src/shared_axis_transition.dart index 79404304c46c..503386c2179e 100644 --- a/packages/animations/lib/src/shared_axis_transition.dart +++ b/packages/animations/lib/src/shared_axis_transition.dart @@ -4,13 +4,18 @@ import 'package:flutter/animation.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' + hide + decelerateEasing, // ignore: undefined_hidden_name + standardEasing, // ignore: undefined_hidden_name + accelerateEasing; // ignore: undefined_hidden_name +// TODO(goderbauer): Remove implementation import when material properly exports the file. +import 'package:flutter/src/material/curves.dart'; // ignore: implementation_imports import 'package:flutter/widgets.dart'; // TODO(shihaohong): Remove DualTransitionBuilder once flutter/flutter's `stable` // branch contains DualTransitionBuilder. import 'dual_transition_builder.dart' as dual_transition_builder; -import 'utils/curves.dart'; /// Determines which type of shared axis transition is used. enum SharedAxisTransitionType { @@ -398,7 +403,7 @@ class _ExitTransition extends StatelessWidget { final Color fillColor; final Widget child; - static final Animatable _fadeOutTransition = FlippedCurveTween( + static final Animatable _fadeOutTransition = _FlippedCurveTween( curve: accelerateEasing, ).chain(CurveTween(curve: const Interval(0.0, 0.3))); @@ -478,3 +483,21 @@ class _ExitTransition extends StatelessWidget { return null; // unreachable } } + +/// Enables creating a flipped [CurveTween]. +/// +/// This creates a [CurveTween] that evaluates to a result that flips the +/// tween vertically. +/// +/// This tween sequence assumes that the evaluated result has to be a double +/// between 0.0 and 1.0. +class _FlippedCurveTween extends CurveTween { + /// Creates a vertically flipped [CurveTween]. + _FlippedCurveTween({ + @required Curve curve, + }) : assert(curve != null), + super(curve: curve); + + @override + double transform(double t) => 1.0 - super.transform(t); +} diff --git a/packages/animations/lib/src/utils/curves.dart b/packages/animations/lib/src/utils/curves.dart deleted file mode 100644 index f464679b1cc3..000000000000 --- a/packages/animations/lib/src/utils/curves.dart +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2019 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/animation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; - -// The easing curves of the Material Library -/// The standard easing curve in the Material specification. -/// -/// Elements that begin and end at rest use standard easing. -/// They speed up quickly and slow down gradually, in order -/// to emphasize the end of the transition. -/// -/// See also: -/// * -const Curve standardEasing = Cubic(0.4, 0.0, 0.2, 1); - -/// The accelerate easing curve in the Material specification. -/// -/// Elements exiting a screen use acceleration easing, -/// where they start at rest and end at peak velocity. -/// -/// See also: -/// * -const Curve accelerateEasing = Cubic(0.4, 0.0, 1.0, 1.0); - -/// The decelerate easing curve in the Material specification. -/// -/// Incoming elements are animated using deceleration easing, -/// which starts a transition at peak velocity (the fastest -/// point of an element’s movement) and ends at rest. -/// -/// See also: -/// * -const Curve decelerateEasing = Cubic(0.0, 0.0, 0.2, 1.0); - -// A tween that starts from 1.0 and ends at 0.0. -final Tween _flippedTween = Tween( - begin: 1.0, - end: 0.0, -); - -/// Enables creating a flipped [CurveTween]. -/// -/// This creates a [CurveTween] that evaluates to a result that flips the -/// tween vertically. -/// -/// This tween sequence assumes that the evaluated result has to be a double -/// between 0.0 and 1.0. -class FlippedCurveTween extends CurveTween { - /// Creates a vertically flipped [CurveTween]. - FlippedCurveTween({ - @required Curve curve, - }) : assert(curve != null), - super(curve: curve); - - @override - double transform(double t) => 1.0 - super.transform(t); -} - -/// Flips the incoming passed in [Animation] to start from 1.0 and end at 0.0. -Animation flipTween(Animation animation) { - return _flippedTween.animate(animation); -}