Layers/groups events behavior...

Hi!
I am working for an app that will pull data from a remote site, and show it in a TableView. I have it almost done, but I am stucked in a few issues that I think are corona bugs? or they’re not implemented right? not sure, but here is the issue…

What I am doing is creating 3 groups with 100% height and width. The first one contains a TableView that is scrollable. The second contain a header with 2 buttons that’s a total of 136px height and 100% width and a footer with 100% width and 29px height. The third is is a popup that will fill the whole screen with a bg with alpha (so its transparent), text and a couple images. Having that order, the tableview is behind the second group wich contains the header with 2 buttons and the footer right. You can scroll the table and tap an item. When you tap an item the third group overlaps everything showing the content.

So the issue starts here. The tableview will be scrollable even if the second group header overlaps it; you can scroll the table swiping your fingers over the the logo that’s in the header!!! also, tap it and the popup is shown!!! The popup has an event that when you tap the area, it should close, but, nothing happens, because the tableview wich is in the back (3 layers back) is still reacting.

I was thinkin that maybe using this:

display.getCurrentStage():setFocus( Popup );

But not, It doesn’t work, the table view keeps doing the same thing (also the header buttons of the second layers that’s behind the popup keep receiving events!)

So I am trapped in a big issue here.

I think the problem here is that Corona is doing something totally out of sense (with all respect). I mean we have layers right? and if I have one layer over other, supposedly the one that should receive the button hit event, or whatever event, is the layer on top! (call it group) right?

This is and issue I think how Corona is controlling the events.

I am Flash/ActionScript developer, and this is a simple logic, if you have 2 layers, in one you create a bg, with a button, and in the second layer, another bg, with a button, I mean 2 MovieClips/Groups one over the other, the front most button will react first for any user interaction always. That’s how Flash works, and other systems like this, wich makes sense, but Corona is not doing this right…

Just guessing what the problem is, or I am wrong and there’s a way actually to do this???

Here I am attaching a flash test based on ActionScript 2:

http://www.ibobx.com/corona/testlayersevents.html

Showing this concept.

You can download the fla here: http://www.ibobx.com/corona/testlayersevents.fla and open with the Flash Ide to see what I mean…

Please point me out if this is a bug, an addition that I should wait for, or simply I am digging this badly…

Thanks a Lot for your help!!

Roberto.
[import]uid: 6046 topic_id: 1875 reply_id: 301875[/import]

Sorry, Corona doesn’t have layers. It has groups. Groups are just for organizing and ordering content regarding the display process. Groups are not related to touch events. Corona handles the touch event in the way these devices (Iphone, Android) work. That is just the way it works on the mobile devices. [import]uid: 5712 topic_id: 1875 reply_id: 5528[/import]

I’ve found a workaround for getting my app to work.
In the function “newListItemHandler” inside the TableView library, at the very beginning, I’ve added this:

 if event.y \< top or event.y \> (display.contentHeight-bottom) then  
 return nil;  
 end  

That makes the buttons of the header to work properly and also both header and footer will prevent the touch events on the tableview that’s behind it.

Now, when the popup is opened, the only way I’ve found is hiding all behind it, and put an screenshot of the whole screen, previously taken, behind the popup to simulate things are still there; and when the popup closes, before close I show all the items again and so on…

I insist Corona should have a way to control events giving priority to the objects/groups/layers index, responding based on the z position, the top most respond first no matter what, something like this,because keep patching like this is a little nonsense and can cause lots of headaches with big codes…

(btw, this little piece of code I’ve included I think should be added to the TableView lib examples to prevent others headatches…)

Thanks.
Roberto.

[import]uid: 6046 topic_id: 1875 reply_id: 5550[/import]

Hmmm, I see…
I supposed groups, that overlaps, with objects inside, where layers? At least these works as layers in most systems, and usually, the events works the way i’ve commented. :slight_smile:
I think iPhone + Android SDK’s doesn’t “have that way to work” we’re on different scenarios right?, this is totally a new UI based on OpenGL so engineers need to implement everything, how events works, priorities, etc; It’s not a fully native use of what’s on the iPhone or Android SDK components event handlers right?
So anyway, any idea if there is a solution, workaround?
Thanks. [import]uid: 6046 topic_id: 1875 reply_id: 5529[/import]

I got just exactly the same Problem. Is there already a solution beside the workaround?
[import]uid: 7190 topic_id: 1875 reply_id: 6947[/import]

@iBobX,

From my testing the top layer object’s listener is called first and if the listener returns true, no other listeners are called. I’ve seen some issues in this area and I’m trying to determine if there is a problem. It sounds like you have an object that is in front of the tableview and touching the object fires the tableview listener instead. Is this what you’re seeing?

Is it possible to send me a some sample code showing the problem you’re seeing? It’s easier to work with existing code than trying to write new code to duplicate the problem. You can send it to tom @ anscamobile.com

Thanks,
-Tom

[import]uid: 7559 topic_id: 1875 reply_id: 7065[/import]

Hi Tom! thank for your answer.
I’ve figured the need of the “return true” wich solved some of the issues, but still had the other issue that I’ve solved with that workaround I’ve commented in here; that about the top layer that “should” (well at least makes sense) make the layer behind it to stop responding “in that area” if you know what I mean (I know this can have another/s workaround, but I thing it makes sense to work this way) … This is shown in the little video I sent, also sending you a zip with the code…
Thank you so much for all-
Roberto.
[import]uid: 6046 topic_id: 1875 reply_id: 7177[/import]

Roberto,

Thank you for spending the time to create the video and send in the code.

I looked at the issue and I believe everything is working correctly. The objects on top do get the focus for touch events and as long as you “return true” in the listeners, it will stop other listeners from being called.

As far as touching the header and footer and having the table items selected, that’s because there is a listener for table items and non for the header and footer. I believe that is by design so you can use detect a touch object under another object. If we masked the touches for only visible objects that may limit what can be done.

Since object touches do respect the display order, my solution to your header/footer touch problem was creating a touch listener for the header and footer that did nothing else but return true. Here is the code that I added to the end of main.lua.

-- Handle header and footer touches  
local function headerFooterTouched( event )  
 print( "headerFooterTouched" )  
 return true  
end  
  
innerHeaderImage:addEventListener( "touch", headerFooterTouched )  
innerFooterImage:addEventListener( "touch", headerFooterTouched )  

I believe allowing touches to occur through other objects allows for a flexible design and adding extra listeners is one way to get the desired results.

Thanks,
-Tom [import]uid: 7559 topic_id: 1875 reply_id: 7184[/import]

Hi Tom!
Well maybe you’re right, it’s better this way, but, if you think about it, to use this solution for every layer that’s doing nothing, just overlapping, this in a big project means wasted cpu power because Corona will be attending these events. But yeah that’s the workaround that makes sense in this case.
Thanks again for your help!
Roberto.

[import]uid: 6046 topic_id: 1875 reply_id: 7191[/import]

If you want a conceptual overview of events and how they are propagated, check out the “Hit Events” section of this article:

http://developer.anscamobile.com/content/application-programming-guide-event-handling [import]uid: 26 topic_id: 1875 reply_id: 8358[/import]