TableView listener event issue

For the touch event, “began” is received only once.

However, the listener event in the table view receives “began” several times.

I think it’s a bug. is not it?

I suspect there is no bug, but a misunderstanding instead.

Make an tiny legible example that demonstrates this, zip it up, share it here.  Then we’ll see what you’re doing right or wrong and give you feedback.

Click ‘more reply options’ button below-right to attach project  zip file to post.

I’m not saying post code, but instead give us a example we can run and test by downloading it.

Just corona sample code.

It only minimizes the code to see only the listener events.

@roaminggamer I can predict how you will answer. I do not need that kind of help.

[lua]

local widget = require( “widget” )

local function tableViewListener( event )

      local phase = event.phase

      print( os.time(), event.phase )

end

local tableView = widget.newTableView

{

      top = 0,

      left = 0,

      width = display.contentWidth,

      height = display.contentHeight,

      hideBackground = true,

      listener = tableViewListener,

}

for i=1, 50 do

      tableView:insertRow

      {

            rowHeight = 100,

            rowColor = {1},

            lineColor = {0},

      }

end

[/lua]

There seems to be about 20 pixel threshold that you can drag from the starting position until the tableView starts to scroll. During this, the “began” phase seems to fire continuously until the dragging stops or exceeds the 20 pixel threshold.

I have no idea if that is the intended behaviour, but it seems really odd.

@XeduR That’s what I want to say.

You can download the code for the widget library and debug this.

https://github.com/coronalabs/framework-widget

@roaminggamer What do you want me to say? If you do not understand my question correctly, I do not want to respond to this pointless answer.

This is not a pointless answer.  I understand your question fine.  

You can’t drop a ‘problem’ on the floor and hope others will solve it for you. 

  1. You can file a bug ( link at top of page), but you will need to provide a working example that demonstrates the problem.

So, if you are going to file a bug, why not share the same working example with us?  i.e. My first post requesting a project so we could easily see what you’re seeing. 

I find it lazy when users expect me to make a project to debug their issue. All I’m asking is that you help me to help you.

  1. If you don’t file a bug, or even if you do, you can get ahead of this and look at the code to see how it works and maybe find the bug on your own.

Then, you can file a bug report and suggest the fix.

Note: Posting a question in the forums doesn’t get a bug filed automatically.  That is on you.

Update: With the source code (which I linked) you can find and fix the issue.  This will let you continue to make progress on your app/game (use your fixed copy of widget lib instead of the one that gets downloaded during builds).  This way if you do not file a bug or if the bug is rejected you are still good to go.   So… again, not pointless.

I was curious, so I actually took a look at the code now that Ed linked it. It’s definitely not a bug.

 

... &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;local dy = mAbs( event.y - event.yStart ) local moveThresh = 20 if "moved" == phase and not self.\_isUsedInPickerWheel then if dy \< moveThresh and self.\_initialTouch then if event.phase ~= "ended" and event.phase ~= "cancelled" then event.phase = "began" end else ...

The approximate 20 pixel movement threshold that I mentioned is clearly stated there. As long as that threshold is not crossed, the phase is set to “began”. So, if you want to change that, you can do it from there.

You can probably also modify your listener to ignore duplicate ‘began’ events.
 
I’d suggest doing this by:

  1. Turn on multi-touch if you don’t have it on:  https://docs.coronalabs.com/api/library/system/activate.html

  2. On receiving a touch began, grab the touch ID in a table (attached to scroller or not; up to you)

  3. On future ‘began’ detections check if the touch ID is in the table.  If so, ignore it.

  4. On the ended phase, remove the ID from the table.
     
    Tip: The ID stays the same for any specific touch.
     
    Example of how to get ID:

    local function listener( event ) local id = event.id

Complete example of what I’m saying:
 

local function listener( event ) local scroller = event.target local phase = event.phase local id = event.id -- scroller.ids = scroller.ids or {} -- if( phase == "began" and not scroller.ids[id] ) then scroller.ids[id] = id -- BEGAN WORK elseif( phase == "moved" ) then -- MOVED WORK elseif( phase == "ended" ) then scroller.ids[id] = nil -- ENDED WORK end return false end

I do not have any problems.

This is what you missed the intention of my question.

I just wanted to know the legitimate reason that “began” should be called many times.

p.s: 

scroller.ids = scroller.ids or {} <- You do not need to use an array.

You do need to use an array for multi-touch.

You can have multiple separate fingers on the screen at the same time.  They will all have a different ID.

I’m not sure why you’re listening for these events anyway. If you want to know if a row was touched, there is a specific “onRowTouch” event that triggers when you interact with a row. You should put any expected touch handling in that event function.

The main listener is there mostly to detect when scrolling starts and stops.

We did a tutorial on advanced tableView tactics: https://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/

There is some code in there that uses the listener to implement spring reloading.

Rob

@Rob Because of your answer, I realized. This is a forum for newbies.

This isn’t really a forum just for newbies, but a lot of newbie questions are asked here. It’s a forum for developers of all skill levels who use Corona. However, it could be that, due to the language barrier or other issues, your question or intentions weren’t fully understood.

I suspect there is no bug, but a misunderstanding instead.

Make an tiny legible example that demonstrates this, zip it up, share it here.  Then we’ll see what you’re doing right or wrong and give you feedback.

Click ‘more reply options’ button below-right to attach project  zip file to post.

I’m not saying post code, but instead give us a example we can run and test by downloading it.

Just corona sample code.

It only minimizes the code to see only the listener events.

@roaminggamer I can predict how you will answer. I do not need that kind of help.

[lua]

local widget = require( “widget” )

local function tableViewListener( event )

      local phase = event.phase

      print( os.time(), event.phase )

end

local tableView = widget.newTableView

{

      top = 0,

      left = 0,

      width = display.contentWidth,

      height = display.contentHeight,

      hideBackground = true,

      listener = tableViewListener,

}

for i=1, 50 do

      tableView:insertRow

      {

            rowHeight = 100,

            rowColor = {1},

            lineColor = {0},

      }

end

[/lua]

There seems to be about 20 pixel threshold that you can drag from the starting position until the tableView starts to scroll. During this, the “began” phase seems to fire continuously until the dragging stops or exceeds the 20 pixel threshold.

I have no idea if that is the intended behaviour, but it seems really odd.

@XeduR That’s what I want to say.

You can download the code for the widget library and debug this.

https://github.com/coronalabs/framework-widget