onRemove function not called fast enough
Hi there,
i have 2 views with 2 Mediators (a thumbnail overview and a
detail view). For transitions between them i use a sliding
effect.
When getting back from detail view i encounter that the onRemove()
function of the detail Mediator is not immediately called, with the
effect that (if i'm fast enough) i can click a thumbnail on the
overview and am getting back to the same detail view as before
(since onRemove() and the whole removal from Stage didn't
happen).
I tried listening to the TRANSITION_COMPLETE event in the detail
Mediator (which is actually called before onRemove()), but then i'm
just getting an empty view when getting back as described above,
since the onRegister() function is not called.
Is there a way to force Robotlegs to initiate the detail view
removal faster, i.e. right after i know that the transition to the
overview is over ?
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 22 Mar, 2013 01:05 PM
Hey Valley,
First of all, sorry for the late response.
That’s a bit tricky. When using effects, components get re-parented. removedEffect causes the components to be first removed from stage, then added to the stage and then removed again.
So, in your case by the time you click fast on a new thumbnail a new view is added to the stage, while the old one hasn’t finished transitioning and its mediator hasn’t been destroyed yet.
A workaround could be the following:
In the DetailsView you add events handlers for EffectEvent.effectEnd.
DetailsMediator
When addedEffect ends, you dispatch an event, say, SomeEvent.VIEW_ADDED.
DetailsMediator listens for it and re-dispatches it:
ThumbsMediator listens for SomeEvent.VIEW_ADDED and sets thumbsContainer.enabled to true, which was set to false in ThumbsView when a thumbnail was clicked to prevent clicking on other thumbs while a DetailView is about to be added.
If you want to add the new view first after the old one has been removed from stage, you can listen to SomeEvent.VIEW_REMOVED, dispatched by the DetailsView first after the removedEffect has finished.
ThumbsMediator
ThumbsView
Does this help?
Ondina
2 Posted by rivella50 on 22 Mar, 2013 02:47 PM
Hi Ondina,
no problem, thanks for answering.
Speaking clear this means when DetailsMediator dispatches the VIEW_REMOVED Event in onRemove() the ThumbsMediator receives that one (i hope the onRegister() function has already been passed so that context listener is ready) and can then check if the user meanwhile has already clicked on another thumbnail (stored in awaitingView list) which can then be served.
Clever idea. I will test this.
Hopefully when i dispatch the VIEW_REMOVED Event at last in onRemove() there isn't another time delay for really removing the DetailsMediator so that the new details request will be correctly served.
Thanks so far, i let you know if that worked.
valley
Support Staff 3 Posted by Ondina D.F. on 22 Mar, 2013 02:55 PM
You’re welcome! Yes, try it out, and please let me know how it goes :)
Oh, now I see this line in my code snippet:
var viewToAdd:SomeViewToAdd = new SomeViewToAdd();
It has to be
var viewToAdd:DetailsView = new DetailsView ();
Support Staff 4 Posted by Ondina D.F. on 28 Mar, 2013 05:12 PM
I guess this is resolved as well, right?
5 Posted by rivella50 on 28 Mar, 2013 09:12 PM
I couldn't test it yet, but it sounds promising. So yes, you can close it.
As soon as i have time i will try it.
Thank you.
valley
Support Staff 6 Posted by Ondina D.F. on 29 Mar, 2013 09:20 AM
No problem!
Ondina D.F. closed this discussion on 29 Mar, 2013 09:20 AM.