is TableView blocking touch events ?

Hi Vasek,

If you add “return true” at the end of the touch listener for the overlay rectangle, it should receive all events. But then, how will the user interact with the tableView below?

Best regards,

Brent

Hi,

you are right. Adding return true to the touch listener will block event to propagates towards table view below. This is certainly not what i’m trying to achieve there :slight_smile: I jut need to keep table view interacting with user and to capture users touch movements simultaneously.  

Best Regards

Vasek

Hi Vasek,

I still don’t understand the usage case. Do you want the ability to “drag” the table view around the screen, but it also still behaves as normal when the user touches the actual table view?

Brent

Yes, that is it. I have several table views ordered in columns and I just need to swipe/drag between them.

Vasek

Hi Vasek,

I can’t think of any “perfect” way to maintain tableView functionality (flicking it up and down) while also being able to drag it around the screen. You may want to place some kind of “frame” around it with a visual indication that the user can move it around by dragging on that part of the overall element, but not by moving around on the tableView itself.

Brent

If I understand correctly I think Vaclav wants to go between tableviews like a slideview. Maybe this helps. I added a tableview listener and propagate the touches over to the touch rect.

[lua]

– touch listener

local function myTouchListener( event )

    if ( event.phase == “began” ) then

        --code executed when the button is touched

        print( "object touched = "…tostring(event.target) )  --‘event.target’ is the touched object

    elseif ( event.phase == “moved” ) then

        --code executed when the touch is moved over the object

        print( “touch location in content coordinates = “…event.x…”,”…event.y )

    elseif ( event.phase == “ended” ) then

        --code executed when the touch lifts off the object

        print( "touch ended on object "…tostring(event.target) )

    end

    --return true  --prevents touch propagation to underlying objects

end

– called when new row is added

local function onRowRender(event)

    – Get reference to the row group

    local group = event.row;

    local h = event.row.contentHeight;

    local w = event.row.contentWidth;

    

    – fill row with red rectangle

    local rect = display.newRect(group, w*0.5, h*0.5, w, h*0.9);

    rect:setFillColor(1,0,0);

end


local group =  display.newGroup();

– table view size

local rowHeight = 100; – content px

local rowCount = 10;

local tableViewHeight = display.contentHeight*0.5;

local tableViewWidth =  display.contentWidth*0.5;

local tableViewTop = (display.contentHeight - tableViewHeight)*0.5;

local tableViewLeft = (display.contentWidth - tableViewWidth)*0.5;

– rectangle size

local rectHeight = display.contentHeight;

local rectWidth = display.contentWidth;

– add table view

local touchDetectingRectangle = display.newRect(group, display.contentCenterX, display.contentCenterY, rectWidth, rectHeight);

touchDetectingRectangle:setFillColor(0.5,0.5);

local function tableViewListener(event)

    myTouchListener({phase = event.phase, target = touchDetectingRectangle, y = event.y, x = event.y})

end

local widget = require(“widget”)

local options =

{

    top = tableViewTop, left= tableViewLeft,

    hideBackground = true,

    onRowRender  = function(event) onRowRender(event) end,

    width = tableViewWidth,–self.width-2*self.rowMargin,

    height = tableViewHeight,

    listener = tableViewListener,

    isBounceEnabled = false;

    --noLines = true,

}

local levelsTable = widget.newTableView( options);

group:insert(levelsTable);

local rowOptions =

{

    rowHeight =  rowHeight,

    rowColor = { default={0,0}},

    

}

for i=1, rowCount do

    levelsTable:insertRow(rowOptions)

end

– add event capturing rectangle over table view

touchDetectingRectangle:toFront(); – to make sure thad rectangke is abowe the table view

touchDetectingRectangle:addEventListener( “touch”, myTouchListener )

[/lua]

Hi jojonsson,

you get it right. I’m trying to do slideview containing table views.

The event propagation you proposed works. But trouble is, that table view touch events are bit different.  All events have event.phase == “begin” until the first change in Y direction occurs. So if you manage to do you move perfectly horizontal no scrolling wil occur. This is of course very special case so i decided to neglect it for now.

Thank you very much for your help !

Vasek