[TIMOB-8280] iOS: Titanium.UI.Button: Layout of the button is getting distorted intermittently
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-03-27T08:42:43.000+0000 |
Affected Version/s | Release 2.0.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | qe-ios031912 |
Reporter | Anshu Mittal |
Assignee | Vishal Duggal |
Created | 2012-03-24T13:23:17.000+0000 |
Updated | 2017-03-09T23:14:12.000+0000 |
Description
Layout of the button is getting distorted intermittently.
Steps to reproduce:
1.Launch app a couple of times.
Expected results:
Should see random numbered buttons in 4 toolbars and will not crash. Layout of all buttons should be correct every time.
Actual:
The layout of the last button gets distorted when test steps are repeated couple of times. Please find the screenshot attached.
App.js
var win = Ti.UI.createWindow({
backgroundColor : 'black'
});
var goal = Math.floor(Math.random() * 21) + 10;
var solutionValue = [];
solutionValue[0] = Math.floor(Math.random() * (goal - (goal / 2) - 1)) + 1;
solutionValue[1] = Math.floor(Math.random() * (goal - (goal / 2) - 1)) + 1;
solutionValue[2] = goal - (solutionValue[0] + solutionValue[1]);
for(var i = 3; i < 12; i++) {
solutionValue[i] = Math.floor(Math.random() * (goal - (goal / 2) - 1)) + 1;
}
Titanium.API.info("Goal: " + goal);
for( i = 0; i < 12; i++) {
Titanium.API.info("Solution " + i + ": " + solutionValue[i]);
}
// Create a banner with the goal
var goalLabel = Titanium.UI.createButton({
title : goal,
color : '#fff', // white text
style : Titanium.UI.iPhone.SystemButtonStyle.PLAIN
});
win.add(goalLabel);
var assigned = [];
for( i = 0; i < 12; i++) {
assigned[i] = 0;
}
var solutionButton = [];
for( i = 0; i < 12; i++) {
var valueIndex = Math.floor(Math.random() * 12);
if(valueIndex == 12) {
valueIndex = 11;
}
while(assigned[valueIndex] == 1) {
valueIndex += 1;
}
assigned[valueIndex] = 1;
Titanium.API.info("Creating a button ...");
solutionButton[i] = Titanium.UI.createButton({
title : solutionValue[valueIndex],
style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
}
Titanium.API.info("All buttons created");
var flexSpace = Titanium.UI.createButton({
systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});
var toolbar = [];
for( i = 0; i < 4; i++) {
Titanium.API.info("Creating a toolbar ...");
toolbar[i] = Titanium.UI.iOS.createToolbar({
items : [solutionButton[i], flexSpace, solutionButton[i + 1], flexSpace, solutionButton[i + 2]],
top : 40 * i,
borderTop : false,
borderBottom : true
});
win.add(toolbar[i]);
}
Titanium.API.info("Opening the window ...");
win.open();
Attachments
File | Date | Size |
---|---|---|
Screenshot 2012.03.23 17.54.23.png | 2012-03-24T13:23:17.000+0000 | 26844 |
Need test code
The code is adding the same button to different toolbars which will result in undefined behavior on IOS. Use this code instead which ensures that a button is added to a toolbar only once.
Closing ticket as invalid.