Merge pull request #748 from abarth/inital_performance
The intial route shouldn't run its entrance animation
This commit is contained in:
commit
e80756d669
@ -68,9 +68,15 @@ abstract class Route<T> {
|
||||
}
|
||||
|
||||
class NamedRouteSettings {
|
||||
const NamedRouteSettings({ this.name, this.mostValuableKeys });
|
||||
const NamedRouteSettings({
|
||||
this.name,
|
||||
this.mostValuableKeys,
|
||||
this.isInitialRoute: false
|
||||
});
|
||||
|
||||
final String name;
|
||||
final Set<Key> mostValuableKeys;
|
||||
final bool isInitialRoute;
|
||||
|
||||
String toString() {
|
||||
String result = '"$name"';
|
||||
@ -161,7 +167,8 @@ class NavigatorState extends State<Navigator> {
|
||||
assert(config.observer == null || config.observer.navigator == null);
|
||||
config.observer?._navigator = this;
|
||||
_push(config.onGenerateRoute(new NamedRouteSettings(
|
||||
name: config.initialRoute ?? Navigator.defaultRouteName
|
||||
name: config.initialRoute ?? Navigator.defaultRouteName,
|
||||
isInitialRoute: true
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/animation.dart';
|
||||
|
||||
import 'navigator.dart';
|
||||
import 'overlay.dart';
|
||||
import 'routes.dart';
|
||||
@ -19,6 +21,13 @@ abstract class PageRoute<T> extends ModalRoute<T> {
|
||||
bool canTransitionTo(TransitionRoute nextRoute) => nextRoute is PageRoute;
|
||||
bool canTransitionFrom(TransitionRoute nextRoute) => nextRoute is PageRoute;
|
||||
|
||||
Performance createPerformanceController() {
|
||||
Performance performance = super.createPerformanceController();
|
||||
if (settings.isInitialRoute)
|
||||
performance.progress = 1.0;
|
||||
return performance;
|
||||
}
|
||||
|
||||
// Subclasses can override this method to customize way heroes are inserted
|
||||
void insertHeroOverlayEntry(OverlayEntry entry, Object tag, OverlayState overlay) {
|
||||
overlay.insert(entry);
|
||||
|
@ -28,7 +28,7 @@ class TestTransition extends TransitionComponent {
|
||||
}
|
||||
|
||||
class TestRoute<T> extends PageRoute<T> {
|
||||
TestRoute(this.child);
|
||||
TestRoute({ this.child, NamedRouteSettings settings}) : super(settings: settings);
|
||||
final Widget child;
|
||||
Duration get transitionDuration => kMaterialPageRouteTransitionDuration;
|
||||
Color get barrierColor => null;
|
||||
@ -71,7 +71,8 @@ void main() {
|
||||
switch (settings.name) {
|
||||
case '/':
|
||||
return new TestRoute(
|
||||
new Builder(
|
||||
settings: settings,
|
||||
child: new Builder(
|
||||
key: insideKey,
|
||||
builder: (BuildContext context) {
|
||||
PageRoute route = ModalRoute.of(context);
|
||||
@ -90,30 +91,18 @@ void main() {
|
||||
}
|
||||
)
|
||||
);
|
||||
case '/2': return new TestRoute(new Text('E'));
|
||||
case '/3': return new TestRoute(new Text('F'));
|
||||
case '/4': return new TestRoute(new Text('G'));
|
||||
case '/2': return new TestRoute(settings: settings, child: new Text('E'));
|
||||
case '/3': return new TestRoute(settings: settings, child: new Text('F'));
|
||||
case '/4': return new TestRoute(settings: settings, child: new Text('G'));
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// TODO(ianh): Remove the first part of this test once the first page doesn't animate in
|
||||
|
||||
NavigatorState navigator = insideKey.currentContext.ancestorStateOfType(NavigatorState);
|
||||
|
||||
expect(state(), equals('AC')); // transition ->1 is at 0.0
|
||||
|
||||
tester.pump(kFourTenthsOfTheTransitionDuration);
|
||||
expect(state(), equals('AC')); // transition ->1 is at 0.4
|
||||
|
||||
tester.pump(kFourTenthsOfTheTransitionDuration);
|
||||
expect(state(), equals('BC')); // transition ->1 is at 0.8
|
||||
|
||||
tester.pump(kFourTenthsOfTheTransitionDuration);
|
||||
expect(state(), equals('BC')); // transition ->1 is at 1.0
|
||||
|
||||
|
||||
navigator.openTransaction((NavigatorTransaction transaction) => transaction.pushNamed('/2'));
|
||||
expect(state(), equals('BC')); // transition 1->2 is not yet built
|
||||
tester.pump();
|
||||
|
Loading…
x
Reference in New Issue
Block a user