-
-
Save DoubleSlashDesign2/3e3e257256b54345712f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local widget = require( "widget" ) | |
local myList | |
local myData = {} | |
myData[1] = { name="Fred", phone="555-555-1234" } | |
myData[2] = { name="Barney", phone="555-555-1235" } | |
myData[3] = { name="Wilma", phone="555-555-1236" } | |
myData[4] = { name="Betty", phone="555-555-1237" } | |
myData[5] = { name="Pebbles", phone="555-555-1238" } | |
myData[6] = { name="BamBam", phone="555-555-1239" } | |
myData[7] = { name="Dino", phone="555-555-1240" } | |
local function onRowRender( event ) | |
--Set up the localized variables to be passed via the event table | |
local row = event.row | |
local id = row.index | |
local params = event.row.params | |
row.bg = display.newRect( 0, 0, display.contentWidth, 60 ) | |
row.bg.anchorX = 0 | |
row.bg.anchorY = 0 | |
row.bg:setFillColor( 1, 1, 1 ) | |
row:insert( row.bg ) | |
if ( event.row.params ) then | |
row.nameText = display.newText( params.name, 12, 0, native.systemFontBold, 18 ) | |
row.nameText.anchorX = 0 | |
row.nameText.anchorY = 0.5 | |
row.nameText:setFillColor( 0 ) | |
row.nameText.y = 20 | |
row.nameText.x = 42 | |
row.phoneText = display.newText( params.phone, 12, 0, native.systemFont, 18 ) | |
row.phoneText.anchorX = 0 | |
row.phoneText.anchorY = 0.5 | |
row.phoneText:setFillColor( 0.5 ) | |
row.phoneText.y = 40 | |
row.phoneText.x = 42 | |
row.rightArrow = display.newImageRect( "rightarrow.png", 15 , 40, 40 ) | |
row.rightArrow.x = display.contentWidth - 20 | |
row.rightArrow.y = row.height / 2 | |
row:insert( row.nameText ) | |
row:insert( row.phoneText ) | |
row:insert( row.rightArrow ) | |
end | |
return true | |
end | |
local function reloadData() | |
-- you provide this function | |
-- fetch your updated ata | |
-- flush the table with: | |
myList:deleteAllRows() | |
-- reinsert your data | |
end | |
local springStart = 0 | |
local needToReload = false | |
local function scrollListener( event ) | |
if ( event.phase == "began" ) then | |
springStart = event.target.parent.parent:getContentPosition() | |
needToReload = false | |
elseif ( event.phase == "moved" ) then | |
if ( event.target.parent.parent:getContentPosition() > springStart + 60 ) then | |
needToReload = true | |
end | |
elseif ( event.limitReached == true and event.phase == nil and event.direction == "down" and needToReload == true ) then | |
--print( "Reloading Table!" ) | |
needToReload = false | |
reloadTable() | |
end | |
return true | |
end | |
local navBarHeight = 60 | |
local tabBarHeight = 50 | |
myList = widget.newTableView { | |
top = navBarHeight, | |
width = display.contentWidth, | |
height = display.contentHeight - navBarHeight - tabBarHeight, | |
onRowRender = onRowRender, | |
onRowTouch = onRowTouch, | |
listener = scrollListener | |
} | |
for i = 1, #myData do | |
myList:insertRow{ | |
rowHeight = 60, | |
isCategory = false, | |
rowColor = { 1, 1, 1 }, | |
lineColor = { 0.90, 0.90, 0.90 }, | |
params = { | |
name = myData[i].name, | |
phone = myData[i].phone | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment