Mediator for viewstack
Hi all,
Maybe this is common knowledge but it took me 2 days to figure it out. If you want to map a viewstack's NavigatorContent you need to set the creationPolicy to all cause ViewStack children are created only when needed by default.
Hope this helps
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
1 Posted by Brady White on 03 Nov, 2010 04:59 PM
I'd love to see a best practice for how to manage mediators of viewstack children. Setting the viewstack's creationPolicy to all doesn't sound like the best solution as far as performance, but definitely works.
I'm experimenting with the following.:
Code on Parent Mediator of ViewStack
`
The ApplicationContext has each child of the viewstack manually mediated as follows:
mediatorMap.mapView( MyChildView, MyChildViewMediator, null, false, false );
This currently is not working because the mediator is being created before the child view when the index changes. Thoughts on this?
Support Staff 2 Posted by Shaun Smith on 04 Nov, 2010 02:22 AM
Howdy,
Auto-mediation (the default) is designed to work with deferred instantiation. Setting "creationPolicy" to "all" and/or manually creating mediators on viewstack-index-change defeats the point. From the very first RL demo:
https://github.com/robotlegs/robotlegs-demos-Bundle/blob/v1.1.2/Hel...
https://github.com/robotlegs/robotlegs-demos-Bundle/blob/v1.1.2/Hel...
3 Posted by Brady White on 04 Nov, 2010 03:05 PM
Shaun,
Thanks for pointing this out, I haven't looked at the demo for months.
The key difference between the demo and what I am asking is that my viewstack children have mediators whereas the demo's viewstack children (i.e. DemoCanvas) do not have mediators.
If the demo were to match my app, then DemoCanvas would have a mediator. This is where errors are being thrown because if creationPolicy is not set to 'all' on the viewstack, the DemoCanvas is null when the mediator is created and is running onRegister().
For RobotLegs to work properly, should all viewstack (TabNavigator, Accordion, etc) children be wrapped in a canvas?
4 Posted by christomanos on 04 Nov, 2010 03:29 PM
If I don't set the creation policy to all I always get the null object error...
Shaun is it possible to make a RL demo with viewstack items mediated?
Support Staff 5 Posted by Shaun Smith on 04 Nov, 2010 06:21 PM
Did you look at the actual lines that I linked to?
6 Posted by christomanos on 04 Nov, 2010 06:40 PM
Yes, the accordion and its childs are already created which is not the same with the viewstack's childs if creation policy is not all
Support Staff 7 Posted by Shaun Smith on 04 Nov, 2010 06:47 PM
What makes you say that?
Support Staff 8 Posted by Shaun Smith on 04 Nov, 2010 06:52 PM
The purpose of that part of the demo was to show deferred mediation in action.
Support Staff 9 Posted by Shaun Smith on 05 Nov, 2010 12:45 PM
Apologies if I came across a bit rude - very tired from traveling/moving to a new country. The bottom line is this: RL mediators are explicitly designed to work with deferred instantiation - map a mediator class to a view class and an instance of that mediator will be created just-in-time when its corresponding view component lands on stage. The whole point of that work-flow is to ease development when dealing with things like ViewStacks, TabNavigators, Accordions etc, where children don't exist immediately.. hence the class (as opposed to instance) mapping thing.
You will only hit null-pointer errors if you try to manipulate children directly from their containers (parent) before they are ready. But you don't need to do that with RL's mediator implementation - the child mediator's onRegister hook will only fire when that view component is ready.
Here's a ZIP with a ViewStack demo. Hopefully it will clear things up a bit. Cheers
10 Posted by christomanos on 09 Nov, 2010 03:17 PM
OK this is working perfect. I am trying now to see why my implementation fails...
Stray closed this discussion on 13 Feb, 2011 04:54 PM.