Exemple #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();
                }
            }
        }
Exemple #2
0
 public _HeroFlightManifest(
     HeroFlightDirection type,
     OverlayState overlay,
     Rect navigatorRect,
     PageRoute fromRoute,
     PageRoute toRoute,
     _HeroState fromHero,
     _HeroState toHero,
     CreateRectTween createRectTween,
     HeroFlightShuttleBuilder shuttleBuilder,
     bool isUserGestureTransition
     )
 {
     D.assert(fromHero.widget.tag == toHero.widget.tag);
     this.type                    = type;
     this.overlay                 = overlay;
     this.navigatorRect           = navigatorRect;
     this.fromRoute               = fromRoute;
     this.toRoute                 = toRoute;
     this.fromHero                = fromHero;
     this.toHero                  = toHero;
     this.createRectTween         = createRectTween;
     this.shuttleBuilder          = shuttleBuilder;
     this.isUserGestureTransition = isUserGestureTransition;
 }
Exemple #3
0
 public _HeroFlightManifest(
     HeroFlightDirection type                = default,
     OverlayState overlay                    = null,
     Rect navigatorRect                      = null,
     PageRoute fromRoute                     = null,
     PageRoute toRoute                       = null,
     _HeroState fromHero                     = null,
     _HeroState toHero                       = null,
     CreateRectTween createRectTween         = null,
     HeroFlightShuttleBuilder shuttleBuilder = null,
     bool?isUserGestureTransition            = null,
     bool?isDiverted = null
     )
 {
     D.assert(fromHero.widget.tag.Equals(toHero.widget.tag));
     this.type                    = type;
     this.overlay                 = overlay;
     this.navigatorRect           = navigatorRect;
     this.fromRoute               = fromRoute;
     this.toRoute                 = toRoute;
     this.fromHero                = fromHero;
     this.toHero                  = toHero;
     this.createRectTween         = createRectTween;
     this.shuttleBuilder          = shuttleBuilder;
     this.isUserGestureTransition = isUserGestureTransition ?? false;
     this.isDiverted              = isDiverted ?? false;
 }
Exemple #4
0
        void _maybeStartHeroTransition(
            Route fromRoute,
            Route toRoute,
            HeroFlightDirection flightType,
            bool isUserGestureTransition
            )
        {
            if (toRoute != fromRoute && toRoute is PageRoute && fromRoute is PageRoute)
            {
                PageRoute         from      = (PageRoute)fromRoute;
                PageRoute         to        = (PageRoute)toRoute;
                Animation <float> animation = (flightType == HeroFlightDirection.push) ? to.animation : from.animation;

                switch (flightType)
                {
                case HeroFlightDirection.pop:
                    if (animation.value == 0.0f)
                    {
                        return;
                    }

                    break;

                case HeroFlightDirection.push:
                    if (animation.value == 1.0f)
                    {
                        return;
                    }

                    break;
                }

                if (isUserGestureTransition && flightType == HeroFlightDirection.pop && to.maintainState)
                {
                    this._startHeroTransition(from, to, animation, flightType, isUserGestureTransition);
                }
                else
                {
                    to.offstage = to.animation.value == 0.0f;

                    WidgetsBinding.instance.addPostFrameCallback((TimeSpan value) => {
                        this._startHeroTransition(from, to, animation, flightType, isUserGestureTransition);
                    });
                }
            }
        }