Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8280] iOS: Titanium.UI.Button: Layout of the button is getting distorted intermittently

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2012-03-27T08:42:43.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sn/a
ComponentsiOS
Labelsqe-ios031912
ReporterAnshu Mittal
AssigneeVishal Duggal
Created2012-03-24T13:23:17.000+0000
Updated2017-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

FileDateSize
Screenshot 2012.03.23 17.54.23.png2012-03-24T13:23:17.000+000026844

Comments

  1. Vishal Duggal 2012-03-26

    Need test code
  2. Vishal Duggal 2012-03-27

    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.
       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,j=0; i < 12,j<4; j++,i+=3) {
                       Titanium.API.info("Creating a toolbar ...");
        
                       toolbar[j] = Titanium.UI.iOS.createToolbar({
                           items : [solutionButton[i], flexSpace, solutionButton[i + 1], flexSpace, solutionButton[i + 2]],
                           top : 40 * j,
                           borderTop : false,
                           borderBottom : true
                       });
                       win.add(toolbar[j]);
                   }
        
                   Titanium.API.info("Opening the window ...");    
            
       win.open();
       
  3. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source