Hi All,
I am new to Corona SDK and to Lua scripting but have done my basic reading and developed some scenes to create a prototype of the app. Now time to understand optimisation and modular coding.
Essentially, I have a common tabBar across most of the pages and therefore would like to modularise thecode to be able to create a tabbar along with it’s buttons and handler events in a common module and be able to call this from various scenes. I know this should be pretty straight forward but I am just not sure what am I missing.
Can the experts please help. Following is the simplified code:
– main.lua
local composer = require ( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
function scene:create(event)
local loadCommonMod = require “comModule”
local catTabBar = loadCommonMod.initateNavBar()
sceneGroup:insert( catTabBar )
end
– comModule.lua
t={}
– initiateNavBar
function initiateNavBar ()
function displayNavBar(){
{
width = 72,
height = 60,
defaultFile = “images/refresh.png”,
label = “Start Over”,
size = 16,
labelYOffset = -8,
onPress = handleStartOverEvent
},
{
width = 72,
height = 60,
defaultFile = “images/basket.png”,
label = “My Basket”,
size = 16,
labelYOffset = -8,
onPress = handleMyBasketEvent
}
}
– -- Create the widget
local tabBar = widget.newTabBar
{
left = 0,
top = 0,
width = display.contentWidth,
height = 150,
buttons = tabButtons
}
end
displayNavBar()
--tabBar = display.newText(“Test”,0,0,global.font,20)
--tabBar:setFillColor( 0,0,1 )
return tabBar
end
t.initateNavBar=initiateNavBar()
– initiateNavBar
return t
Any help will be much appreciated,
Thanks