Overide tableview widget touch detection

Hi 

I’m trying to create a basic pull to the side menu al la the current facebook/linked in.

I have various bits of code for the drag function and that works fine with normal objects such as buttons and pictures.  

However if I add a tableview widget in, it overrides the touch capture and it cannot be dragged, as it only recognizes pressed, not moved as an event.

I’ve tried adding in buttons to the table, using a slideview, listeners etc but to no avail.

Does anyone know if there is a way to override the touch function for the tableview widget or at least pass the event up the line so that if the finger is dragged sideways the whole screen can slide.

Thanks

Michael

Here’s what I did:

[lua]

local slide = {

  left = 0,

  right = display.contentWidth * 2 / 3,

  position = “left”,

  startthreshold = 5,

  swipethreshold = 75

}

local tableview = widget.newTableView({

  left = slide[slide.position],

  width = display.contentWidth,

  height = display.contentHeight

})

function tableview:position(leftorright)

  if self.x == slide[leftorright] then return end

  slide.position = leftorright

  self.x = slide[leftorright]

end

function tableview:restoreposition()

  self:position(slide.position)

end

function tableview:switchposition()

  local leftorright = “left”

  if slide.position == “left” then leftorright = “right” end

  self:position(leftorright)

end

– FIXME; can break on any new widget version,

– but for now probably a better solution than keeping a fork of the widget library.

– The problem is that the TableView widget uses up all touch hook points for its

– implementation of table scrolling and row selecting & swiping, and doesn’t

– provide any possibility for touch extension through its API.

– The tableview[2] part is the dirty hack here.

local view = tableview[2]

local widgettouch = view.touch

function view:touch (event)

  local direction = “left”

  if event.x > event.xStart then direction = “right” end

  if direction ~= slide.position then

    local distance = math.abs(event.x - event.xStart)

    if “moved” == event.phase then

      if distance > slide.startthreshold then

        tableview.x = tableview.x + (event.x - slide.prevx)

      end

    elseif “ended” == event.phase or “canceled” == event.phase then

      if distance > slide.swipethreshold then

        tableview:switchposition()

      else

        tableview:restoreposition()

      end

    end

  end

  slide.prevx = event.x

  widgettouch(view, event)

  return true

end

[/lua]

Thanks

I’ll give it a try.  I’ve tried to just use a slideView as faux table view and disable the horizontal scrolling on it.  This works to a degree, but means I have to manually build the table.

I’ll let you know how it goes.

Michael

Hi

I gave this a shot, I like your slide code better than mine as it seems to detect when the finger slides of the screen (although I cannot pinpoint where).

Thanks for the help.

Michael

Edit occurred because I’m an idiot and I forgot some basic code, hence my question is null and void

Glad it worked out. The “finger off the screen” you noticed is probably because events are only trapped when direction ~= slide.position

Here’s what I did:

[lua]

local slide = {

  left = 0,

  right = display.contentWidth * 2 / 3,

  position = “left”,

  startthreshold = 5,

  swipethreshold = 75

}

local tableview = widget.newTableView({

  left = slide[slide.position],

  width = display.contentWidth,

  height = display.contentHeight

})

function tableview:position(leftorright)

  if self.x == slide[leftorright] then return end

  slide.position = leftorright

  self.x = slide[leftorright]

end

function tableview:restoreposition()

  self:position(slide.position)

end

function tableview:switchposition()

  local leftorright = “left”

  if slide.position == “left” then leftorright = “right” end

  self:position(leftorright)

end

– FIXME; can break on any new widget version,

– but for now probably a better solution than keeping a fork of the widget library.

– The problem is that the TableView widget uses up all touch hook points for its

– implementation of table scrolling and row selecting & swiping, and doesn’t

– provide any possibility for touch extension through its API.

– The tableview[2] part is the dirty hack here.

local view = tableview[2]

local widgettouch = view.touch

function view:touch (event)

  local direction = “left”

  if event.x > event.xStart then direction = “right” end

  if direction ~= slide.position then

    local distance = math.abs(event.x - event.xStart)

    if “moved” == event.phase then

      if distance > slide.startthreshold then

        tableview.x = tableview.x + (event.x - slide.prevx)

      end

    elseif “ended” == event.phase or “canceled” == event.phase then

      if distance > slide.swipethreshold then

        tableview:switchposition()

      else

        tableview:restoreposition()

      end

    end

  end

  slide.prevx = event.x

  widgettouch(view, event)

  return true

end

[/lua]

Thanks

I’ll give it a try.  I’ve tried to just use a slideView as faux table view and disable the horizontal scrolling on it.  This works to a degree, but means I have to manually build the table.

I’ll let you know how it goes.

Michael

Hi

I gave this a shot, I like your slide code better than mine as it seems to detect when the finger slides of the screen (although I cannot pinpoint where).

Thanks for the help.

Michael

Edit occurred because I’m an idiot and I forgot some basic code, hence my question is null and void

Glad it worked out. The “finger off the screen” you noticed is probably because events are only trapped when direction ~= slide.position