diff --git a/packages/flutter/lib/src/widgets/hero_controller.dart b/packages/flutter/lib/src/widgets/hero_controller.dart index 14cce393bc..fb44db9603 100644 --- a/packages/flutter/lib/src/widgets/hero_controller.dart +++ b/packages/flutter/lib/src/widgets/hero_controller.dart @@ -20,9 +20,23 @@ class HeroPageRoute extends PageRoute { }) : super(builder: builder, settings: settings); final HeroController heroController; + NavigatorState _navigator; - void didMakeCurrent() { - heroController?.didMakeCurrent(this); + void didPush(OverlayState overlay, OverlayEntry insertionPoint) { + super.didPush(overlay, insertionPoint); + // TODO(abarth): Pass the NavigatorState explicitly. + if (overlay != null) { + _navigator = Navigator.of(overlay.context); + heroController?.didPush(_navigator, this); + } + } + + void didPop(dynamic result) { + super.didPop(result); + if (_navigator != null) { + heroController?.didPop(_navigator, this); + _navigator = null; + } } } @@ -32,29 +46,47 @@ class HeroController { } HeroParty _party; + PerformanceView _performance; HeroPageRoute _from; HeroPageRoute _to; final List _overlayEntries = new List(); - void didMakeCurrent(PageRoute current) { - assert(current != null); - assert(current.performance != null); - if (_from == null) { - _from = current; - return; + void didPush(NavigatorState navigator, HeroPageRoute route) { + assert(route != null); + assert(route.performance != null); + Route from = navigator.currentRoute; + if (from is HeroPageRoute) + _from = from; + _to = route; + _performance = route.performance; + _checkForHeroQuest(); + } + + void didPop(NavigatorState navigator, HeroPageRoute route) { + assert(route != null); + assert(route.performance != null); + Route to = navigator.currentRoute; + if (to is HeroPageRoute) { + _to = to; + _from = route; + _performance = route.performance; + _checkForHeroQuest(); } - _to = current; - if (_from != _to) { - current.offstage = current.performance.status != PerformanceStatus.completed; + } + + void _checkForHeroQuest() { + if (_from != null && _to != null && _from != _to) { + _to.offstage = _to.performance.status != PerformanceStatus.completed; scheduler.requestPostFrameCallback(_updateQuest); } } void _handleQuestFinished() { _removeHeroesFromOverlay(); - _from = _to; + _from = null; _to = null; + _performance = null; } Rect _getAnimationArea(BuildContext context) { @@ -97,7 +129,7 @@ class HeroController { Map heroesTo = Hero.of(context, mostValuableKeys); _to.offstage = false; - PerformanceView performance = _to.performance; + PerformanceView performance = _performance; Curve curve = Curves.ease; if (performance.status == PerformanceStatus.reverse) { performance = new ReversePerformance(performance); diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index 0dee9abd08..d0b826ac29 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -366,14 +366,17 @@ class HeroParty { PerformanceView _currentPerformance; + void _clearCurrentPerformance() { + _currentPerformance?.removeStatusListener(_handleUpdate); + _currentPerformance = null; + } + Iterable getWidgets(BuildContext context, PerformanceView performance) sync* { assert(performance != null || _heroes.length == 0); if (performance != _currentPerformance) { - if (_currentPerformance != null) - _currentPerformance.removeStatusListener(_handleUpdate); + _clearCurrentPerformance(); _currentPerformance = performance; - if (_currentPerformance != null) - _currentPerformance.addStatusListener(_handleUpdate); + _currentPerformance?.addStatusListener(_handleUpdate); } for (_HeroQuestState hero in _heroes) yield hero.build(context, performance); @@ -389,7 +392,7 @@ class HeroParty { source._resetChild(); } _heroes.clear(); - _currentPerformance = null; + _clearCurrentPerformance(); if (onQuestFinished != null) onQuestFinished(); } diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 9ca90efd71..8223aacf41 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -9,7 +9,6 @@ abstract class Route { List get overlayEntries; void didPush(OverlayState overlay, OverlayEntry insertionPoint); - void didMakeCurrent(); void didPop(dynamic result); } @@ -95,13 +94,11 @@ class NavigatorState extends State { _popAllEphemeralRoutes(); route.didPush(overlay, _currentOverlay); _modal.add(route); - route.didMakeCurrent(); } void pushEphemeral(Route route) { route.didPush(overlay, _currentOverlay); _ephemeral.add(route); - route.didMakeCurrent(); } void _popAllEphemeralRoutes() { @@ -114,7 +111,6 @@ class NavigatorState extends State { void pop([dynamic result]) { _removeCurrentRoute().didPop(result); - currentRoute.didMakeCurrent(); } Widget build(BuildContext context) { diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index 0d4d9ed1ff..98ec21a399 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -17,7 +17,6 @@ class StateRoute extends Route { List get overlayEntries => const []; void didPush(OverlayState overlay, OverlayEntry insertionPoint) { } - void didMakeCurrent() { } void didPop(dynamic result) { if (onPop != null) onPop(); @@ -38,8 +37,6 @@ class OverlayRoute extends Route { } } - void didMakeCurrent() { } - void didPop(dynamic result) { for (OverlayEntry entry in _overlayEntries) entry.remove();