Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

TableView listener event issue
Started by Hyunjoong Kim Dec 04 2018 11:51 AM

14 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

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?


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

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.
 
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


[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

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.



[TOPIC: post.html]
#5

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

@XeduR That's what I want to say.



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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

 

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



[TOPIC: post.html]
#7

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

@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.



[TOPIC: post.html]
#8

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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.

 

 

 

2. 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.


Edited by roaminggamer, 05 December 2018 - 11:53 AM.

  • XeduR @Spyric likes this

[TOPIC: post.html]
#9

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

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

 

...
                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.


  • roaminggamer likes this

[TOPIC: post.html]
#10

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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

  

Edited by roaminggamer, 05 December 2018 - 12:34 PM.


[TOPIC: post.html]
#11

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

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.


[TOPIC: post.html]
#12

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

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.



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,997 posts
  • Corona SDK

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



[TOPIC: post.html]
#14

Hyunjoong Kim

[GLOBAL: userInfoPane.html]
Hyunjoong Kim
  • Enthusiast

  • 95 posts
  • Corona SDK

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



[TOPIC: post.html]
#15

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]