Visitar URL original
[animations] adds alignment parameter to FadeScaleTransition by grinder15 · Pull Request #187 · flutter/packages · GitHub
Skip to content
Closed
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 tests with different scale alignment.
  • Loading branch information
grinder15 authored and Jerome Arenas committed Aug 10, 2020
commit f46afda3f452435cc594733dc094aec3eed7992e
172 changes: 171 additions & 1 deletion packages/animations/test/fade_scale_transition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void main() {
);

testWidgets(
'FadeScaleTransitionConfiguration runs forward',
'FadeScaleTransitionConfiguration runs backwards',
(WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
Expand Down Expand Up @@ -191,6 +191,161 @@ void main() {
},
);

testWidgets(
'FadeScaleTransitionConfiguration runs forward with different scale '
'alignment',
(WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(builder: (BuildContext context) {
return Center(
child: RaisedButton(
onPressed: () {
showModal<void>(
context: context,
configuration:
const _ModifiedFadeScaleTransitionConfiguration(),
builder: (BuildContext context) {
return _FlutterLogoModal(key: key);
},
);
},
child: const Icon(Icons.add),
),
);
}),
),
),
);
await tester.tap(find.byType(RaisedButton));
await tester.pump();
// Opacity duration: First 30% of 150ms, linear transition
double topFadeTransitionOpacity = _getOpacity(key, tester);
double topScale = _getScale(key, tester);
Alignment topScaleAlignment = _getScaleAlignment(key, tester);
expect(topFadeTransitionOpacity, 0.0);
expect(topScale, 0.80);
expect(topScaleAlignment, Alignment.topRight);

// 3/10 * 150ms = 45ms (total opacity animation duration)
// 1/2 * 45ms = ~23ms elapsed for halfway point of opacity
// animation
await tester.pump(const Duration(milliseconds: 23));
topFadeTransitionOpacity = _getOpacity(key, tester);
expect(topFadeTransitionOpacity, closeTo(0.5, 0.05));
topScale = _getScale(key, tester);
expect(topScale, greaterThan(0.80));
expect(topScale, lessThan(1.0));
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.topRight);

// End of opacity animation
await tester.pump(const Duration(milliseconds: 22));
topFadeTransitionOpacity = _getOpacity(key, tester);
expect(topFadeTransitionOpacity, 1.0);
topScale = _getScale(key, tester);
expect(topScale, greaterThan(0.80));
expect(topScale, lessThan(1.0));
topScaleAlignment = _getScaleAlignment(key, tester);
expect(topScaleAlignment, Alignment.topRight);

// 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.topRight);

// 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.topRight);

await tester.pump();
expect(find.byType(_FlutterLogoModal), findsOneWidget);
},
);

testWidgets(
'FadeScaleTransitionConfiguration runs backwards with different scale '
'alignment',
(WidgetTester tester) async {
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(builder: (BuildContext context) {
return Center(
child: RaisedButton(
onPressed: () {
showModal<void>(
context: context,
configuration:
const _ModifiedFadeScaleTransitionConfiguration(),
builder: (BuildContext context) {
return _FlutterLogoModal(key: key);
},
);
},
child: const Icon(Icons.add),
),
);
}),
),
),
);
// Show the incoming modal and let it animate in fully.
await tester.tap(find.byType(RaisedButton));
await tester.pumpAndSettle();

// Tap on modal barrier to start reverse animation.
await tester.tapAt(Offset.zero);
await tester.pump();

// Opacity duration: Linear transition throughout 75ms
// 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.topRight);

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.topRight);

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.topRight);

// 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.topRight);

await tester.pump(const Duration(milliseconds: 1));
expect(find.byType(_FlutterLogoModal), findsNothing);
},
);

testWidgets(
'FadeScaleTransitionConfiguration does not jump when interrupted',
(WidgetTester tester) async {
Expand Down Expand Up @@ -526,3 +681,18 @@ class _FlutterLogoModalState extends State<_FlutterLogoModal> {
);
}
}

class _ModifiedFadeScaleTransitionConfiguration
extends FadeScaleTransitionConfiguration {
const _ModifiedFadeScaleTransitionConfiguration();

@override
Widget transitionBuilder(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return FadeScaleTransition(
animation: animation,
alignment: Alignment.topRight,
child: child,
);
}
}