Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Tableview isCategory row - tap event passing through it to row below
Started by tabrezk Jan 21 2013 11:58 PM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

tabrezk

[GLOBAL: userInfoPane.html]
tabrezk
  • Observer

  • 8 posts
  • Corona SDK

I've got a tableView with tappable rows that open external urls (youtube videos)
The first row has isCategory parameter == true.
So it sticks to the top (as it should.)
And the following rows then slide up underneath it (as they should.)
Great so far....

The problem is that if I tap the Category row, the row directly behind it receives the tap and opens its url.
Not good :(

Can anyone suggest how to get around this? Is it a bug?

Thanks people!

My onRowTouch code is below:
p.s. how do you enter code into forums so that it displays nicely like in the corona proj manage IDE.
is it just a print screen?

--================================================
-- onEvent listener for the tableView
local function onRowTouch( event )
local row = event.target
local rowGroup = event.view

if event.phase == "press" then
if not row.isCategory then rowGroup.alpha = 0.5; end

elseif event.phase == "tap" then
if not row.isCategory then
row.reRender = true
system.openURL( rowInfo[event.index].theURL)
end

elseif event.phase == "release" then
if not row.isCategory then
row.reRender = true
end
end

return true
end
uid: 194387 topic_id: 35197 reply_id: 335197


[TOPIC: post.html]
#2

richard9

[GLOBAL: userInfoPane.html]
richard9
  • Corona Geek

  • 1,118 posts
  • Enterprise

1. Use < code > < / code > (without the spaces) when posting code to the forum. :)

2. Not really sure why you're using touch and tap listeners in one function but generally speaking return true for tap doesn't work versus touch and vice versa. So with this hybrid approach you might have to addEventListener() to the same function for both touch and tap, or seperate it out?

uid: 41884 topic_id: 35197 reply_id: 139930


[TOPIC: post.html]
#3

tabrezk

[GLOBAL: userInfoPane.html]
tabrezk
  • Observer

  • 8 posts
  • Corona SDK

@richard9 -
1. thanks for the tip
2. the tap phase is in the onRowTouch event simply because that's how they have it in the sample code for Corona tableView tutorial.

I just can't seem to prevent, at least on the simulator anyway, the 'TAP' from propagating past the Category row to the normal row behind it. Is anyone having the same issue? Im using trial build 2012.971 (the latest one)

uid: 194387 topic_id: 35197 reply_id: 140065


[TOPIC: post.html]
#4

richard9

[GLOBAL: userInfoPane.html]
richard9
  • Corona Geek

  • 1,118 posts
  • Enterprise

Sorry, my week has been a real mess. This is the first time I've had a chance to sit and look at this again. Originally I thought you meant the touch was going through to the background.

Using the exact code below, I couldn't replicate your problem. It's possible a fix was made since .971, but you'd have to check the change logs to be sure. Maybe somebody at Corona remembers offhand?

The only advice I can give is to add print statements and check for those rather then checking for code actions; sometimes that's the best way to tell what is actually a bug versus simply conflicting code.

local widget = require("widget")
local list = widget.newTableView{ top = display.statusBarHeight }

local function onRowTouch(event)
  local row = event.target; local rowGroup = event.view

  if event.phase == "press" then
    if not row.isCategory then rowGroup.alpha = 0.5 end

  elseif event.phase == "tap" then
    if not row.isCategory then row.reRender = true; print("tap!") end

  elseif event.phase == "release" then
    if not row.isCategory then row.reRender = true; print("press!") end
  end

  return true
end

local function onRowRender(event)
  local row = event.target
  local rowGroup = event.view
  local text = display.newText( "Row #"..event.index, 12, 0, "HelveticaNeue-Bold", 18)
  text:setReferencePoint(display.CenterLeftReferencePoint)
  text.y = row.height * 0.5
  if not row.isCategory then
    text.x = 15
    text:setTextColor(0)
  end
  rowGroup:insert(text)
end

for i = 1, 100 do
  local rowHeight, rowColor, lineColor, isCategory

  if i == 1 or i == 10 then
    isCategory = true; rowHeight = 24; rowColor = {70,70,130,255}; lineColor = {0,0,0,255}
  end

  list:insertRow{
    onEvent = onRowTouch,
    onRender = onRowRender,
    height = rowHeight,
    isCategory = isCategory,
    rowColor = rowColor,
    lineColor = lineColor
  }
end
uid: 41884 topic_id: 35197 reply_id: 140330



[topic_controls]
[/topic_controls]