alternate solution for INavigationContent mediatation (ie ViewStack, Accordian, TabNav, etc)

Mike's Avatar

Mike

04 May, 2012 08:33 PM

I noticed it was brought up "eons" ago back in all of 2010, but I thought I'd throw my hat out there if anyone wants to take a look. As suggested by the authors, to create a mediator for the sub-children of the container, in some cases it makes more sense to create the mediator at the child level - but this introduces the issue of the children of the view aren't available just yet.

The code extends the basic mediator and looks for the the deferredContentCreated flag, and if it's not found then add a listener for the FlexEvent.CONTENT_CREATION_COMPLETE.

(btw, RL rocks) ;)

package  
{

    import flash.events.Event;

    import mx.core.INavigatorContent;
    import mx.core.UIComponent;
    import mx.events.FlexEvent;

    import org.robotlegs.mvcs.Mediator;

    /**
     * This mediator is intended for INavigatorContent / Spark.NavigatorContent
     * views - when created, unless it is the current visible item based on it's
     * contentCreationPolicy - it will only create the outer shell of the view.
     * 
     * So we check the associated view and if it is deferred - we halt
     * the onRegister process until it has triggered the FlexEvent.CONTENT_CREATION_COMPLETE
     * event.
     */
    public class NavigatorContentMediator extends Mediator 
    {

            public function NavigatorContentMediator() 
            {
                    super();
            }


            override public function onRemove():void 
            {
                    super.onRemove();
                    view.removeEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
            }


            override protected function onCreationComplete(event:Event):void 
            {
                    if (view.deferredContentCreated) super.onCreationComplete(event);
                    else 
                    {
                            view.removeEventListener(event.type, onCreationComplete);
                            view.addEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
                    }
            }

            protected function onContentCreationComplete(event:FlexEvent):void
            {
                    view.removeEventListener(FlexEvent.CONTENT_CREATION_COMPLETE, onContentCreationComplete);
                    super.onCreationComplete(event);
            }


            /**
             * A rare case where we want a private property to the view - this allows us
             * to ensure it's of the interface we want without enforcing the same interface
             * in super mediators - allowing them to type cast a protected or private property
             * as the concrete view it mediates.
             */
            private function get view():INavigatorContent
            {
                    return getViewComponent() as INavigatorContent;
            }

    }
    }
  1. Ondina D.F. closed this discussion on 27 Aug, 2012 10:38 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac