Add FadeTransition to Android page transition (#9086)
* Add FadeTransition to Android page transition * Also move starting point up * Add test * Use const fractional offset
This commit is contained in:
parent
1a87e8182a
commit
86e9fc1c68
@ -12,31 +12,38 @@ const double _kMinFlingVelocity = 1.0; // screen width per second
|
|||||||
|
|
||||||
// Used for Android and Fuchsia.
|
// Used for Android and Fuchsia.
|
||||||
class _MountainViewPageTransition extends AnimatedWidget {
|
class _MountainViewPageTransition extends AnimatedWidget {
|
||||||
static final FractionalOffsetTween _kTween = new FractionalOffsetTween(
|
|
||||||
begin: FractionalOffset.bottomLeft,
|
|
||||||
end: FractionalOffset.topLeft
|
|
||||||
);
|
|
||||||
|
|
||||||
_MountainViewPageTransition({
|
_MountainViewPageTransition({
|
||||||
Key key,
|
Key key,
|
||||||
Animation<double> animation,
|
this.routeAnimation,
|
||||||
this.child,
|
this.child,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
listenable: _kTween.animate(new CurvedAnimation(
|
listenable: _kTween.animate(new CurvedAnimation(
|
||||||
parent: animation, // The route's linear 0.0 - 1.0 animation.
|
parent: routeAnimation, // The route's linear 0.0 - 1.0 animation.
|
||||||
curve: Curves.fastOutSlowIn
|
curve: Curves.fastOutSlowIn
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
static final FractionalOffsetTween _kTween = new FractionalOffsetTween(
|
||||||
|
begin: const FractionalOffset(0.0, 0.25),
|
||||||
|
end: FractionalOffset.topLeft
|
||||||
|
);
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
final Animation<double> routeAnimation;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO(ianh): tell the transform to be un-transformed for hit testing
|
// TODO(ianh): tell the transform to be un-transformed for hit testing
|
||||||
return new SlideTransition(
|
return new SlideTransition(
|
||||||
position: listenable,
|
position: listenable,
|
||||||
child: child
|
child: new FadeTransition(
|
||||||
|
opacity: new CurvedAnimation(
|
||||||
|
parent: routeAnimation,
|
||||||
|
curve: Curves.easeIn, // Eyeballed from other Material apps.
|
||||||
|
),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,7 +279,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return new _MountainViewPageTransition(
|
return new _MountainViewPageTransition(
|
||||||
animation: animation,
|
routeAnimation: animation,
|
||||||
child: child
|
child: child
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
41
packages/flutter/test/material/page_test.dart
Normal file
41
packages/flutter/test/material/page_test.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2017 The Chromium 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/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('test Android page transition', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
new MaterialApp(
|
||||||
|
theme: new ThemeData(platform: TargetPlatform.android),
|
||||||
|
home: new Material(child: new Text('Page 1')),
|
||||||
|
routes: <String, WidgetBuilder>{
|
||||||
|
'/next': (BuildContext context) {
|
||||||
|
return new Material(child: new Text('Page 2'));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final Point widget1TopLeft = tester.getTopLeft(find.text('Page 1'));
|
||||||
|
|
||||||
|
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 1));
|
||||||
|
|
||||||
|
final Opacity widget2Opacity =
|
||||||
|
tester.element(find.text('Page 2')).ancestorWidgetOfExactType(Opacity);
|
||||||
|
final Point widget2TopLeft = tester.getTopLeft(find.text('Page 2'));
|
||||||
|
final Size widget2Size = tester.getSize(find.text('Page 2'));
|
||||||
|
|
||||||
|
expect(widget1TopLeft.x == widget2TopLeft.x, true);
|
||||||
|
// Page 1 is above page 2 mid-transition.
|
||||||
|
expect(widget1TopLeft.y < widget2TopLeft.y, true);
|
||||||
|
// Animation begins 3/4 of the way up the page.
|
||||||
|
expect(widget2TopLeft.y < widget2Size.height / 4.0, true);
|
||||||
|
// Animation starts with page 2 being near transparent.
|
||||||
|
expect(widget2Opacity.opacity < 0.01, true);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user