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
This commit is contained in:
@@ -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<OverlayEntry> _overlayEntries = new List<OverlayEntry>();
|
||||
|
||||
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<Object, HeroHandle> 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);
|
||||
|
||||
@@ -366,14 +366,17 @@ class HeroParty {
|
||||
|
||||
PerformanceView _currentPerformance;
|
||||
|
||||
void _clearCurrentPerformance() {
|
||||
_currentPerformance?.removeStatusListener(_handleUpdate);
|
||||
_currentPerformance = null;
|
||||
}
|
||||
|
||||
Iterable<Widget> 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();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ abstract class Route {
|
||||
List<OverlayEntry> get overlayEntries;
|
||||
|
||||
void didPush(OverlayState overlay, OverlayEntry insertionPoint);
|
||||
void didMakeCurrent();
|
||||
void didPop(dynamic result);
|
||||
}
|
||||
|
||||
@@ -95,13 +94,11 @@ class NavigatorState extends State<Navigator> {
|
||||
_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<Navigator> {
|
||||
|
||||
void pop([dynamic result]) {
|
||||
_removeCurrentRoute().didPop(result);
|
||||
currentRoute.didMakeCurrent();
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -17,7 +17,6 @@ class StateRoute extends Route {
|
||||
List<OverlayEntry> get overlayEntries => const <OverlayEntry>[];
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user