ViewMediator changes after windowresize
Hello,
we might have found a bug. Everything is described here:
https://stackoverflow.com/questions/25057618/flex-3-6-and-robotlegs-viewmediator-changes-after-windowresize
We think that it should not be a normal behaviour to change a existing mediator only because a parent changed.
Regards,
KBC
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
Support Staff 1 Posted by Ondina D.F. on 05 Aug, 2014 02:44 PM
Hello,
For a fact, the view is first removed from stage and then added to the stage again! That's what Adobe calls 'reparenting':
"A view state can change the parent container of a component. Changing the parent container of a component is called reparenting the component."
More details here:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c...
I don't recall exactly whether re-parenting after resizing was a Flex bug or not, but if it was a bug it seems that it hasn't been resolved. However, re-parenting of components happens under other circumstances as well: drag and drop, transition effects..
Secondly, Amy is absolutely right! Mediators shouldn't hold state. That's what Models are for. Maybe it's time to refactor your Mediators? :)
Anyway, a workaround could be this:
You set the autoRemove of the mediator to false, in order to keep it alive when the view gets reparented. Of course, you'll have to remove the mediator manually, if need be.
Then, you create a guard. For the sake of an example I created it inside of SomeMediator. You can use another class, if you wish.
Inside your view you create getters and setters for a needsMediator and set it to true.
Then, you set the view.needsMediator = false within mediator's initialize().
The first time SomeMediator is about to be created, view.needsMediator is true, so the guard will 'approve' the creation of the mediator.
Next time, after reparenting the view, view.needsMediator will return false, thus the guard won't approve the creation of a new mediator for SomeView. The old mediator will react to events coming from SomeView or framework classes.
needsMediator is a silly name. It's up to you how you name the flag, and whether it is a property of the view or of the mediator.
You'll have to try this out with your settings to see if it works for you. I can't reproduce your use case on my end, thus I can't guarantee that my workaround will solve your problem.
Let us know about your progress.
Ondina
Support Staff 2 Posted by Ondina D.F. on 01 Sep, 2014 12:30 PM
I'm assuming you've resolved the issue, thus I'm going to close this discussion. Feel free to re-open it, if you want to respond or if you need more assistance with this.
Ondina D.F. closed this discussion on 01 Sep, 2014 12:30 PM.