forked from coronalabs/framework-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabBar.lua
More file actions
288 lines (252 loc) · 7.74 KB
/
tabBar.lua
File metadata and controls
288 lines (252 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
-- Copyright (C) 2013 Corona Inc. All Rights Reserved.
-- File: newTabBar unit test.
local widget = require( "widget" )
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local USE_ANDROID_THEME = false
local USE_IOS7_THEME = true
local isGraphicsV1 = ( 1 == display.getDefault( "graphicsCompatibility" ) )
-- Forward reference for test function timer
local testTimer = nil
function scene:createScene( event )
local group = self.view
-- Test android theme
if USE_ANDROID_THEME then
widget.setTheme( "widget_theme_android" )
end
--Display an iOS style background
local background
local xAnchor, yAnchor
if not isGraphicsV1 then
xAnchor = display.contentCenterX
yAnchor = display.contentCenterY
else
xAnchor = 0
yAnchor = 0
end
if USE_IOS7_THEME then
background = display.newRect( xAnchor, yAnchor, display.contentWidth, display.contentHeight )
else
background = display.newImage( "unitTestAssets/background.png" )
background.x, background.y = xAnchor, yAnchor
end
group:insert( background )
if USE_IOS7_THEME then
-- create a white background, 40px tall, to mask / hide the scrollView
local topMask = display.newRect( 0, 0, display.contentWidth, 40 )
topMask:setFillColor( 235, 235, 235, 255 )
group:insert( topMask )
end
local backButtonPosition = 5
local backButtonSize = 52
local fontUsed = native.systemFont
local textFontUsed = native.systemFontBold
if USE_IOS7_THEME then
backButtonPosition = 0
backButtonSize = 40
fontUsed = "HelveticaNeue-Light"
textFontUsed = "HelveticaNeue-Light"
end
--Button to return to unit test listing
local returnToListing = widget.newButton{
id = "returnToListing",
left = display.contentWidth * 0.5,
top = backButtonPosition,
label = "Exit",
width = 200, height = backButtonSize,
cornerRadius = 8,
onRelease = function() storyboard.gotoScene( "unitTestListing" ) end;
}
returnToListing.x = display.contentCenterX
group:insert( returnToListing )
----------------------------------------------------------------------------------------------------------------
-- START OF UNIT TEST
----------------------------------------------------------------------------------------------------------------
-- Toggle these defines to execute tests. NOTE: It is recommended to only enable one of these tests at a time
local TEST_SET_BUTTON_ACTIVE = false
local TEST_IMAGESHEET_TAB_BAR = false
local TEST_THEME_TAB_BAR = true
local tabBar = nil
local labelColors = {
default = { 255, 255, 255, 128 },
over = { 255, 255, 255, 255 },
}
local tabLabelFont = native.systemFontBold
local tabLabelFontSize = 8
local normalTabImage = "unitTestAssets/tabIcon.png"
local overTabImage = "unitTestAssets/tabIcon-down.png"
if USE_IOS7_THEME then
labelColors = {
default = { 146 },
over = { 21, 125, 251, 255 },
}
tabLabelFont = "HelveticaNeue"
tabLabelFontSize = 10
normalTabImage = "unitTestAssets/tabIcon-ios7.png"
overTabImage = "unitTestAssets/tabIcon-down-ios7.png"
end
-- Create the tabBar's buttons
local tabButtons =
{
{
width = 32,
height = 32,
defaultFile = normalTabImage,
overFile = overTabImage,
label = "Tab1",
--labelXOffset = - 20,
--labelYOffset = - 20,
labelColor = labelColors,
font = tabLabelFont,
size = tabLabelFontSize,
onPress = function() print( "Tab 1 pressed" ) end,
selected = false
},
{
width = 32,
height = 32,
defaultFile = normalTabImage,
overFile = overTabImage,
label = "Tab2",
labelColor = labelColors,
font = tabLabelFont,
size = tabLabelFontSize,
onPress = function( event ) print( "Tab 2 pressed" ) end,
selected = true
},
{
width = 32,
height = 32,
defaultFile = normalTabImage,
overFile = overTabImage,
label = "Tab3",
labelColor = labelColors,
font = tabLabelFont,
size = tabLabelFontSize,
onPress = function() print( "Tab 3 pressed" ) end,
selected = false
},
{
width = 32,
height = 32,
defaultFile = normalTabImage,
overFile = overTabImage,
label = "Tab4",
labelColor = labelColors,
font = tabLabelFont,
size = tabLabelFontSize,
onPress = function() print( "Tab 4 pressed" ) end,
selected = false
},
}
-- Create a tab bar
if TEST_THEME_TAB_BAR then
tabBar = widget.newTabBar
{
left = 0,
top = display.contentHeight - 52,
width = display.contentWidth,
buttons = tabButtons,
}
group:insert( tabBar )
end
-- Create a tabBar
if TEST_IMAGE_FILE_TAB_BAR then
tabBar = widget.newTabBar
{
left = 0,
top = display.contentHeight - 52,
width = display.contentWidth,
backgroundFile = "unitTestAssets/woodbg.png",
tabSelectedLeftFile = "unitTestAssets/tabBar_tabSelectedLeftEdge.png",
tabSelectedRightFile = "unitTestAssets/tabBar_tabSelectedRightEdge.png",
tabSelectedMiddleFile = "unitTestAssets/tabBar_tabSelectedMiddle.png",
tabSelectedFrameWidth = 20,
tabSelectedFrameHeight = 100,
buttons = tabButtons,
}
group:insert( tabBar )
end
if TEST_IMAGESHEET_TAB_BAR then
--- IMAGE SHEET TAB BAR
local sheetOptions = require( "unitTestAssets.tabBar.tabBar" )
local imageSheet = graphics.newImageSheet( "unitTestAssets/tabBar/tabBar.png", sheetOptions:getSheet() )
-- Create the tabBar's buttons
local tabButtonsImageSheet =
{
{
width = 32,
height = 32,
defaultFrame = sheetOptions:getFrameIndex( "tabBar_iconInactive" ),
overFrame = sheetOptions:getFrameIndex( "tabBar_iconActive" ),
label = "Tab1",
--labelXOffset = - 20,
--labelYOffset = - 20,
onPress = function() print( "Tab 1 pressed" ) end,
selected = false
},
{
width = 32,
height = 32,
defaultFrame = sheetOptions:getFrameIndex( "tabBar_iconInactive" ),
overFrame = sheetOptions:getFrameIndex( "tabBar_iconActive" ),
label = "Tab2",
onPress = function( event ) print( "Tab 2 pressed" ) end,
selected = true
},
{
width = 32,
height = 32,
defaultFrame = sheetOptions:getFrameIndex( "tabBar_iconInactive" ),
overFrame = sheetOptions:getFrameIndex( "tabBar_iconActive" ),
label = "Tab3",
onPress = function() print( "Tab 3 pressed" ) end,
selected = false
},
{
width = 32,
height = 32,
defaultFrame = sheetOptions:getFrameIndex( "tabBar_iconInactive" ),
overFrame = sheetOptions:getFrameIndex( "tabBar_iconActive" ),
label = "Tab4",
onPress = function() print( "Tab 4 pressed" ) end,
selected = false
},
}
-- Create a tabBar
tabBar = widget.newTabBar
{
left = 0,
top = display.contentHeight - 52,
width = display.contentWidth,
sheet = imageSheet,
backgroundFrame = sheetOptions:getFrameIndex( "tabBar_background" ),
tabSelectedLeftFrame = sheetOptions:getFrameIndex( "tabBar_tabSelectedLeftEdge" ),
tabSelectedRightFrame = sheetOptions:getFrameIndex( "tabBar_tabSelectedRightEdge" ),
tabSelectedMiddleFrame = sheetOptions:getFrameIndex( "tabBar_tabSelectedMiddle" ),
tabSelectedFrameWidth = 5,
tabSelectedFrameHeight = 49,
buttons = tabButtonsImageSheet,
}
group:insert( tabBarImageSheet )
end
----------------------------------------------------------------------------------------------------------------
-- TESTS
----------------------------------------------------------------------------------------------------------------
if TEST_SET_BUTTON_ACTIVE then
testTimer = timer.performWithDelay( 2000, function()
tabBar:setSelected( 4, true )
end, 1 )
end
end
function scene:didExitScene( event )
--Cancel test timer if active
if testTimer ~= nil then
timer.cancel( testTimer )
testTimer = nil
end
storyboard.removeAll()
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "didExitScene", scene )
return scene