Handling two overlapping touch events

I have a sliding menu panel with a touch listener called “swipe”. This listener enables the panel to follow the user’s finger swipes. Then I have a table widget on the menu with the normal “OnRowTouch” listener. 

These two objects and listeners overlap. The table is in the center of the panel. Whenever the panel is swiped, it does as stated in the swipe listener but when ever the user tries to swipe on the area where the table is, the swipe listener isn’t activated.

I’m trying to set things up in a way that when the table is swiped, the swipe listener on the pane below it is called, when it’s clicked, the normal “OnRowTouch” listener is called. I tried removing the “return true” but it didn’t work.

currently i just used the “swipeleft” “swiperight” of the onRowTouch to close the menu but I want it to follow the users finger movements like in swipe.

Here’s my current code, its kinda mess looking:

swipe:

local function swipe(event) if (event.phase == "began") then dialog\_object.startX = dialog\_object.x dialog\_object.lastTime = event.time dialog\_object.speed = 0 elseif (event.phase == "moved") then dialog\_object.deltaTime = event.time - dialog\_object.lastTime dist = ( (event.x - (backdrop.width/2)) - (event.xStart - (backdrop.width/2)) ) dialog\_object.speed = dist / dialog\_object.deltaTime print ( dialog\_object.speed ) if (dialog\_object.startX + dist) \<= dialog\_object.limit then dialog\_object.x = dialog\_object.startX + dist end elseif (event.phase == "cancelled") or (event.phase == "ended") then if (dialog\_object.x \<= obj\_edge) or (( dialog\_object.speed \* (-1) ) \>= 0.8) then group:close() else transition.to(dialog\_object, { x= dialog\_object.limit, time = 100, transition=easing.linear}) end end

onRowTouch:

local function onRowTouch( event ) local row = event.target local params=event.target.params print (event.phase ) if event.phase == "press" then rowMoved = false wrongMoved = false elseif event.phase == "swipeLeft" then rowMoved = true if opt.align == "left" then wrongMoved = false group:close() else wrongMoved = true end elseif event.phase == "swipeRight" then rowMoved = true if opt.align == "right" then wrongMoved = false group:close() else wrongMoved = true end elseif event.phase == "release" or event.phase == "ended" then if wrongMoved == false then group:close() end if params.onClick and (rowMoved == false) then params.onClick() end end return true end

I’d appreciate the help, thanks :slight_smile:

You need to be setting the display.currentStage:setFocus( target ) so that the touch event is assigned to a particular object. This means the object which you want to receive the touch events will continue to get them.

Here’s an example touch listener:

 function parent:touch(e) event = e if (e.phase == "began") then display.currentStage:setFocus( e.target ) e.target.hasFocus = true return true elseif (e.target.hasFocus) then if (e.phase == "moved") then else display.currentStage:setFocus( nil ) e.target.hasFocus = nil end return true end return false end parent:addEventListener( "touch", parent )

I’m sort of confused, I tried setting the panel below it to focus but when the user swipes on the table, the panel below it isn’t reached at all so it’s never set to focus. I tired setting the panel to focus in the rowTouch too, that way when the user swipes left or right, the panel below it is set to focus but that doesn’t work either, no matter what I do, the panel below the table receives no touch input at all when the table is touched

You need to be setting the display.currentStage:setFocus( target ) so that the touch event is assigned to a particular object. This means the object which you want to receive the touch events will continue to get them.

Here’s an example touch listener:

 function parent:touch(e) event = e if (e.phase == "began") then display.currentStage:setFocus( e.target ) e.target.hasFocus = true return true elseif (e.target.hasFocus) then if (e.phase == "moved") then else display.currentStage:setFocus( nil ) e.target.hasFocus = nil end return true end return false end parent:addEventListener( "touch", parent )

I’m sort of confused, I tried setting the panel below it to focus but when the user swipes on the table, the panel below it isn’t reached at all so it’s never set to focus. I tired setting the panel to focus in the rowTouch too, that way when the user swipes left or right, the panel below it is set to focus but that doesn’t work either, no matter what I do, the panel below the table receives no touch input at all when the table is touched