Example #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();
                }
            }
        }
Example #2
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);
        }
Example #3
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;
        }