public void start(_HeroFlightManifest initialManifest) { D.assert(!_aborted); D.assert(() => { Animation <float> initial = initialManifest.animation; D.assert(initial != null); HeroFlightDirection type = initialManifest.type; switch (type) { case HeroFlightDirection.pop: return(initial.value == 1.0f && initialManifest.isUserGestureTransition ? initial.status == AnimationStatus.completed : initial.status == AnimationStatus.reverse); case HeroFlightDirection.push: return(initial.value == 0.0f && initial.status == AnimationStatus.forward); } throw new Exception("Unknown type: " + type); }); manifest = initialManifest; if (manifest.type == HeroFlightDirection.pop) { _proxyAnimation.parent = new ReverseAnimation(manifest.animation); } else { _proxyAnimation.parent = manifest.animation; } manifest.fromHero.startFlight(shouldIncludedChildInPlaceholder: manifest.type == HeroFlightDirection.push); manifest.toHero.startFlight(); heroRectTween = _doCreateRectTween( HeroUtils._boundingBoxFor(manifest.fromHero.context, manifest.fromRoute.subtreeContext), HeroUtils._boundingBoxFor(manifest.toHero.context, manifest.toRoute.subtreeContext) ); overlayEntry = new OverlayEntry(builder: _buildOverlay); manifest.overlay.insert(overlayEntry); }
void _startHeroTransition( PageRoute from, PageRoute to, Animation <float> animation, HeroFlightDirection flightType, bool isUserGestureTransition ) { if (navigator == null || from.subtreeContext == null || to.subtreeContext == null) { to.offstage = false; // in case we set this in _maybeStartHeroTransition return; } Rect navigatorRect = HeroUtils._boundingBoxFor(navigator.context);//_globalBoundingBoxFor(navigator.context); Dictionary <object, _HeroState> fromHeroes = Hero._allHeroesFor(from.subtreeContext, isUserGestureTransition, navigator); Dictionary <object, _HeroState> toHeroes = Hero._allHeroesFor(to.subtreeContext, isUserGestureTransition, navigator); to.offstage = false; foreach (object tag in fromHeroes.Keys) { if (toHeroes.ContainsKey(tag)) { HeroFlightShuttleBuilder fromShuttleBuilder = fromHeroes[tag].widget.flightShuttleBuilder; HeroFlightShuttleBuilder toShuttleBuilder = toHeroes[tag].widget.flightShuttleBuilder; bool isDiverted = _flights.ContainsKey(tag); _HeroFlightManifest manifest = new _HeroFlightManifest( type: flightType, overlay: navigator.overlay, navigatorRect: navigatorRect, fromRoute: from, toRoute: to, fromHero: fromHeroes[tag], toHero: toHeroes[tag], createRectTween: createRectTween, shuttleBuilder: toShuttleBuilder ?? fromShuttleBuilder ?? _defaultHeroFlightShuttleBuilder, isUserGestureTransition: isUserGestureTransition, isDiverted: isDiverted ); //if (_flights.TryGetValue(tag, out var result)) { if (isDiverted) { _flights[tag].divert(manifest); } else { _flights[tag] = new _HeroFlight(_handleFlightEnded); _flights[tag].start(manifest); } } else if (_flights.TryGetValue(tag, out var result)) { result.abort(); } } foreach (object tag in toHeroes.Keys) { _HeroState heroState = null; if (!fromHeroes.TryGetValue(tag, out heroState)) { toHeroes[tag].ensurePlaceholderIsHidden(); } } }
public void divert(_HeroFlightManifest newManifest) { D.assert(manifest.tag == newManifest.tag); if (manifest.type == HeroFlightDirection.push && newManifest.type == HeroFlightDirection.pop) { D.assert(newManifest.animation.status == AnimationStatus.reverse); D.assert(manifest.fromHero == newManifest.toHero); D.assert(manifest.toHero == newManifest.fromHero); D.assert(manifest.fromRoute == newManifest.toRoute); D.assert(manifest.toRoute == newManifest.fromRoute); _proxyAnimation.parent = new ReverseAnimation(newManifest.animation); heroRectTween = new ReverseTween <Rect>(heroRectTween); } else if (manifest.type == HeroFlightDirection.pop && newManifest.type == HeroFlightDirection.push) { D.assert(newManifest.animation.status == AnimationStatus.forward); D.assert(manifest.toHero == newManifest.fromHero); D.assert(manifest.toRoute == newManifest.fromRoute); _proxyAnimation.parent = newManifest.animation.drive( new FloatTween( begin: manifest.animation.value, end: 1.0f ) ); if (manifest.fromHero != newManifest.toHero) { manifest.fromHero.endFlight(keepPlaceholder: true); newManifest.toHero.startFlight(); heroRectTween = _doCreateRectTween( heroRectTween.end, HeroUtils._boundingBoxFor(newManifest.toHero.context, newManifest.toRoute.subtreeContext) ); } else { heroRectTween = _doCreateRectTween(heroRectTween.end, heroRectTween.begin); } } else { D.assert(manifest.fromHero != newManifest.fromHero); D.assert(manifest.toHero != newManifest.toHero); heroRectTween = _doCreateRectTween( heroRectTween.evaluate(_proxyAnimation), HeroUtils._boundingBoxFor(newManifest.toHero.context, newManifest.toRoute.subtreeContext) ); shuttle = null; if (newManifest.type == HeroFlightDirection.pop) { _proxyAnimation.parent = new ReverseAnimation(newManifest.animation); } else { _proxyAnimation.parent = newManifest.animation; } manifest.fromHero.endFlight(keepPlaceholder: true); manifest.toHero.endFlight(keepPlaceholder: true); // Let the heroes in each of the routes rebuild with their placeholders. newManifest.fromHero.startFlight(shouldIncludedChildInPlaceholder: newManifest.type == HeroFlightDirection.push); newManifest.toHero.startFlight(); overlayEntry.markNeedsBuild(); } _aborted = false; manifest = newManifest; }