Beispiel #1
0
        void _startHeroTransition(
            PageRoute from,
            PageRoute to,
            Animation <float> animation,
            HeroFlightDirection flightType,
            bool isUserGestureTransition
            )
        {
            if (this.navigator == null || from.subtreeContext == null || to.subtreeContext == null)
            {
                to.offstage = false; // in case we set this in _maybeStartHeroTransition
                return;
            }

            Rect navigatorRect = HeroUtils._globalBoundingBoxFor(this.navigator.context);

            Dictionary <object, _HeroState> fromHeroes =
                Hero._allHeroesFor(from.subtreeContext, isUserGestureTransition, this.navigator);
            Dictionary <object, _HeroState> toHeroes =
                Hero._allHeroesFor(to.subtreeContext, isUserGestureTransition, this.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;

                    _HeroFlightManifest manifest = new _HeroFlightManifest(
                        type: flightType,
                        overlay: this.navigator.overlay,
                        navigatorRect: navigatorRect,
                        fromRoute: from,
                        toRoute: to,
                        fromHero: fromHeroes[tag],
                        toHero: toHeroes[tag],
                        createRectTween: this.createRectTween,
                        shuttleBuilder:
                        toShuttleBuilder ?? fromShuttleBuilder ?? _defaultHeroFlightShuttleBuilder,
                        isUserGestureTransition: isUserGestureTransition
                        );

                    if (this._flights.TryGetValue(tag, out var result))
                    {
                        result.divert(manifest);
                    }
                    else
                    {
                        this._flights[tag] = new _HeroFlight(this._handleFlightEnded);
                        this._flights[tag].start(manifest);
                    }
                }
                else if (this._flights.TryGetValue(tag, out var result))
                {
                    result.abort();
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void start(_HeroFlightManifest initialManifest)
        {
            D.assert(!this._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);
            });

            this.manifest = initialManifest;

            if (this.manifest.type == HeroFlightDirection.pop)
            {
                this._proxyAnimation.parent = new ReverseAnimation(this.manifest.animation);
            }
            else
            {
                this._proxyAnimation.parent = this.manifest.animation;
            }

            this.manifest.fromHero.startFlight();
            this.manifest.toHero.startFlight();

            this.heroRectTween = this._doCreateRectTween(
                HeroUtils._globalBoundingBoxFor(this.manifest.fromHero.context),
                HeroUtils._globalBoundingBoxFor(this.manifest.toHero.context)
                );

            this.overlayEntry = new OverlayEntry(builder: this._buildOverlay);
            this.manifest.overlay.insert(this.overlayEntry);
        }
Beispiel #4
0
        public void divert(_HeroFlightManifest newManifest)
        {
            D.assert(this.manifest.tag == newManifest.tag);

            if (this.manifest.type == HeroFlightDirection.push && newManifest.type == HeroFlightDirection.pop)
            {
                D.assert(newManifest.animation.status == AnimationStatus.reverse);
                D.assert(this.manifest.fromHero == newManifest.toHero);
                D.assert(this.manifest.toHero == newManifest.fromHero);
                D.assert(this.manifest.fromRoute == newManifest.toRoute);
                D.assert(this.manifest.toRoute == newManifest.fromRoute);

                this._proxyAnimation.parent = new ReverseAnimation(newManifest.animation);
                this.heroRectTween          = new ReverseTween <Rect>(this.heroRectTween);
            }
            else if (this.manifest.type == HeroFlightDirection.pop && newManifest.type == HeroFlightDirection.push)
            {
                D.assert(newManifest.animation.status == AnimationStatus.forward);
                D.assert(this.manifest.toHero == newManifest.fromHero);
                D.assert(this.manifest.toRoute == newManifest.fromRoute);

                this._proxyAnimation.parent = newManifest.animation.drive(
                    new FloatTween(
                        begin: this.manifest.animation.value,
                        end: 1.0f
                        )
                    );

                if (this.manifest.fromHero != newManifest.toHero)
                {
                    this.manifest.fromHero.endFlight();
                    newManifest.toHero.startFlight();
                    this.heroRectTween = this._doCreateRectTween(this.heroRectTween.end,
                                                                 HeroUtils._globalBoundingBoxFor(newManifest.toHero.context));
                }
                else
                {
                    this.heroRectTween = this._doCreateRectTween(this.heroRectTween.end, this.heroRectTween.begin);
                }
            }
            else
            {
                D.assert(this.manifest.fromHero != newManifest.fromHero);
                D.assert(this.manifest.toHero != newManifest.toHero);

                this.heroRectTween = this._doCreateRectTween(this.heroRectTween.evaluate(this._proxyAnimation),
                                                             HeroUtils._globalBoundingBoxFor(newManifest.toHero.context));
                this.shuttle = null;

                if (newManifest.type == HeroFlightDirection.pop)
                {
                    this._proxyAnimation.parent = new ReverseAnimation(newManifest.animation);
                }
                else
                {
                    this._proxyAnimation.parent = newManifest.animation;
                }

                this.manifest.fromHero.endFlight();
                this.manifest.toHero.endFlight();

                newManifest.fromHero.startFlight();
                newManifest.toHero.startFlight();

                this.overlayEntry.markNeedsBuild();
            }

            this._aborted = false;
            this.manifest = newManifest;
        }
Beispiel #5
0
        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;
        }