Commit 70b14e8a authored by Adam Barth's avatar Adam Barth

Heroes don't reverse any more

We need to use the performance for the "from" route when going backwards. Also,
fix a bug in the HeroParty where it would call the quest finished callback
multiple times.

Fixes #1958
parent fa50aaec
...@@ -20,9 +20,23 @@ class HeroPageRoute extends PageRoute { ...@@ -20,9 +20,23 @@ class HeroPageRoute extends PageRoute {
}) : super(builder: builder, settings: settings); }) : super(builder: builder, settings: settings);
final HeroController heroController; final HeroController heroController;
NavigatorState _navigator;
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 didMakeCurrent() { void didPop(dynamic result) {
heroController?.didMakeCurrent(this); super.didPop(result);
if (_navigator != null) {
heroController?.didPop(_navigator, this);
_navigator = null;
}
} }
} }
...@@ -32,29 +46,47 @@ class HeroController { ...@@ -32,29 +46,47 @@ class HeroController {
} }
HeroParty _party; HeroParty _party;
PerformanceView _performance;
HeroPageRoute _from; HeroPageRoute _from;
HeroPageRoute _to; HeroPageRoute _to;
final List<OverlayEntry> _overlayEntries = new List<OverlayEntry>(); final List<OverlayEntry> _overlayEntries = new List<OverlayEntry>();
void didMakeCurrent(PageRoute current) { void didPush(NavigatorState navigator, HeroPageRoute route) {
assert(current != null); assert(route != null);
assert(current.performance != null); assert(route.performance != null);
if (_from == null) { Route from = navigator.currentRoute;
_from = current; if (from is HeroPageRoute)
return; _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); scheduler.requestPostFrameCallback(_updateQuest);
} }
} }
void _handleQuestFinished() { void _handleQuestFinished() {
_removeHeroesFromOverlay(); _removeHeroesFromOverlay();
_from = _to; _from = null;
_to = null; _to = null;
_performance = null;
} }
Rect _getAnimationArea(BuildContext context) { Rect _getAnimationArea(BuildContext context) {
...@@ -97,7 +129,7 @@ class HeroController { ...@@ -97,7 +129,7 @@ class HeroController {
Map<Object, HeroHandle> heroesTo = Hero.of(context, mostValuableKeys); Map<Object, HeroHandle> heroesTo = Hero.of(context, mostValuableKeys);
_to.offstage = false; _to.offstage = false;
PerformanceView performance = _to.performance; PerformanceView performance = _performance;
Curve curve = Curves.ease; Curve curve = Curves.ease;
if (performance.status == PerformanceStatus.reverse) { if (performance.status == PerformanceStatus.reverse) {
performance = new ReversePerformance(performance); performance = new ReversePerformance(performance);
......
...@@ -366,14 +366,17 @@ class HeroParty { ...@@ -366,14 +366,17 @@ class HeroParty {
PerformanceView _currentPerformance; PerformanceView _currentPerformance;
void _clearCurrentPerformance() {
_currentPerformance?.removeStatusListener(_handleUpdate);
_currentPerformance = null;
}
Iterable<Widget> getWidgets(BuildContext context, PerformanceView performance) sync* { Iterable<Widget> getWidgets(BuildContext context, PerformanceView performance) sync* {
assert(performance != null || _heroes.length == 0); assert(performance != null || _heroes.length == 0);
if (performance != _currentPerformance) { if (performance != _currentPerformance) {
if (_currentPerformance != null) _clearCurrentPerformance();
_currentPerformance.removeStatusListener(_handleUpdate);
_currentPerformance = performance; _currentPerformance = performance;
if (_currentPerformance != null) _currentPerformance?.addStatusListener(_handleUpdate);
_currentPerformance.addStatusListener(_handleUpdate);
} }
for (_HeroQuestState hero in _heroes) for (_HeroQuestState hero in _heroes)
yield hero.build(context, performance); yield hero.build(context, performance);
...@@ -389,7 +392,7 @@ class HeroParty { ...@@ -389,7 +392,7 @@ class HeroParty {
source._resetChild(); source._resetChild();
} }
_heroes.clear(); _heroes.clear();
_currentPerformance = null; _clearCurrentPerformance();
if (onQuestFinished != null) if (onQuestFinished != null)
onQuestFinished(); onQuestFinished();
} }
......
...@@ -9,7 +9,6 @@ abstract class Route { ...@@ -9,7 +9,6 @@ abstract class Route {
List<OverlayEntry> get overlayEntries; List<OverlayEntry> get overlayEntries;
void didPush(OverlayState overlay, OverlayEntry insertionPoint); void didPush(OverlayState overlay, OverlayEntry insertionPoint);
void didMakeCurrent();
void didPop(dynamic result); void didPop(dynamic result);
} }
...@@ -95,13 +94,11 @@ class NavigatorState extends State<Navigator> { ...@@ -95,13 +94,11 @@ class NavigatorState extends State<Navigator> {
_popAllEphemeralRoutes(); _popAllEphemeralRoutes();
route.didPush(overlay, _currentOverlay); route.didPush(overlay, _currentOverlay);
_modal.add(route); _modal.add(route);
route.didMakeCurrent();
} }
void pushEphemeral(Route route) { void pushEphemeral(Route route) {
route.didPush(overlay, _currentOverlay); route.didPush(overlay, _currentOverlay);
_ephemeral.add(route); _ephemeral.add(route);
route.didMakeCurrent();
} }
void _popAllEphemeralRoutes() { void _popAllEphemeralRoutes() {
...@@ -114,7 +111,6 @@ class NavigatorState extends State<Navigator> { ...@@ -114,7 +111,6 @@ class NavigatorState extends State<Navigator> {
void pop([dynamic result]) { void pop([dynamic result]) {
_removeCurrentRoute().didPop(result); _removeCurrentRoute().didPop(result);
currentRoute.didMakeCurrent();
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -17,7 +17,6 @@ class StateRoute extends Route { ...@@ -17,7 +17,6 @@ class StateRoute extends Route {
List<OverlayEntry> get overlayEntries => const <OverlayEntry>[]; List<OverlayEntry> get overlayEntries => const <OverlayEntry>[];
void didPush(OverlayState overlay, OverlayEntry insertionPoint) { } void didPush(OverlayState overlay, OverlayEntry insertionPoint) { }
void didMakeCurrent() { }
void didPop(dynamic result) { void didPop(dynamic result) {
if (onPop != null) if (onPop != null)
onPop(); onPop();
...@@ -38,8 +37,6 @@ class OverlayRoute extends Route { ...@@ -38,8 +37,6 @@ class OverlayRoute extends Route {
} }
} }
void didMakeCurrent() { }
void didPop(dynamic result) { void didPop(dynamic result) {
for (OverlayEntry entry in _overlayEntries) for (OverlayEntry entry in _overlayEntries)
entry.remove(); entry.remove();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment