Visitar URL original
[animations] adds alignment parameter to FadeScaleTransition by grinder15 · Pull Request #187 · flutter/packages · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[animations] added some tests.
  • Loading branch information
grinder15 authored and Jerome Arenas committed Aug 7, 2020
commit b91673171cd872df7ed4195b85c481f7931b021b
3 changes: 3 additions & 0 deletions packages/animations/lib/src/fade_scale_transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ class FadeScaleTransition extends StatelessWidget {
///
/// [animation] is typically an [AnimationController] that drives the transition
/// animation. [animation] cannot be null.
///
/// The [alignment] defaults to [Alignment.center] and cannot be null.
const FadeScaleTransition({
Key key,
@required this.animation,
this.alignment = Alignment.center,
Comment thread
grinder15 marked this conversation as resolved.
Resolved
this.child,
}) : assert(animation != null),
assert(alignment != null),
super(key: key);

/// The animation that drives the [child]'s entrance and exit.
Expand Down
27 changes: 27 additions & 0 deletions packages/animations/test/fade_scale_transition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ void main() {
// Opacity duration: First 30% of 150ms, linear transition
double topFadeTransitionOpacity = _getOpacity(key, tester);
double topScale = _getScale(key, tester);
Alignment topScaleAlignment = _getScaleAlignment(key, tester);
Comment thread
grinder15 marked this conversation as resolved.
Resolved
expect(topFadeTransitionOpacity, 0.0);
expect(topScale, 0.80);
expect(topScaleAlignment, Alignment.center);

// 3/10 * 150ms = 45ms (total opacity animation duration)
// 1/2 * 45ms = ~23ms elapsed for halfway point of opacity
Expand All @@ -83,6 +85,8 @@ void main() {
topScale = _getScale(key, tester);
expect(topScale, greaterThan(0.80));
expect(topScale, lessThan(1.0));
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.center);

// End of opacity animation
await tester.pump(const Duration(milliseconds: 22));
Expand All @@ -91,17 +95,23 @@ void main() {
topScale = _getScale(key, tester);
expect(topScale, greaterThan(0.80));
expect(topScale, lessThan(1.0));
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.center);

// 100ms into the animation
await tester.pump(const Duration(milliseconds: 55));
topScale = _getScale(key, tester);
expect(topScale, greaterThan(0.80));
expect(topScale, lessThan(1.0));
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.center);

// Get to the end of the animation
await tester.pump(const Duration(milliseconds: 50));
topScale = _getScale(key, tester);
expect(topScale, 1.0);
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.center);

await tester.pump();
expect(find.byType(_FlutterLogoModal), findsOneWidget);
Expand Down Expand Up @@ -146,27 +156,35 @@ void main() {
// No scale animations on exit transition.
double topFadeTransitionOpacity = _getOpacity(key, tester);
double topScale = _getScale(key, tester);
Alignment topScaleAlignment = _getScaleAlignment(key, tester);
expect(topFadeTransitionOpacity, 1.0);
expect(topScale, 1.0);
expect(topScaleAlignment, Alignment.center);

await tester.pump(const Duration(milliseconds: 25));
topFadeTransitionOpacity = _getOpacity(key, tester);
topScale = _getScale(key, tester);
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topFadeTransitionOpacity, closeTo(0.66, 0.05));
expect(topScale, 1.0);
expect(topScaleAlignment, Alignment.center);

await tester.pump(const Duration(milliseconds: 25));
topFadeTransitionOpacity = _getOpacity(key, tester);
topScale = _getScale(key, tester);
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topFadeTransitionOpacity, closeTo(0.33, 0.05));
expect(topScale, 1.0);
expect(topScaleAlignment, Alignment.center);

// End of opacity animation
await tester.pump(const Duration(milliseconds: 25));
topFadeTransitionOpacity = _getOpacity(key, tester);
expect(topFadeTransitionOpacity, 0.0);
topScale = _getScale(key, tester);
expect(topScale, 1.0);
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.center);
Comment thread
grinder15 marked this conversation as resolved.
Resolved

await tester.pump(const Duration(milliseconds: 1));
expect(find.byType(_FlutterLogoModal), findsNothing);
Expand Down Expand Up @@ -471,6 +489,15 @@ double _getScale(GlobalKey key, WidgetTester tester) {
});
}

Alignment _getScaleAlignment(GlobalKey key, WidgetTester tester) {
final Finder finder = find.ancestor(
of: find.byKey(key),
matching: find.byType(ScaleTransition),
);
final ScaleTransition transition = tester.widget(finder);
return transition.alignment;
}

class _FlutterLogoModal extends StatefulWidget {
const _FlutterLogoModal({
Key key,
Expand Down