Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9102] iOS: getVisible() / getEnabled() functions could return null value

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-03-05T21:13:44.000+0000
Affected Version/sRelease 2.1.0, Release 2.0.1, Release 3.1.0, Release 3.2.0
Fix Version/sRelease 4.0.0
ComponentsiOS
Labelsapi, qe-4.0.0, supportTeam
ReporterFederico Casali
AssigneePedro Enrique
Created2012-05-06T01:45:04.000+0000
Updated2015-03-18T21:43:49.000+0000

Description

Problem description

Boolean functions like getVisible() or getEnabled() can return null value

Code sample

var win = Ti.UI.createWindow({
	exitOnClose:true
});
var view = Ti.UI.createView({
	top:0,
	left:0,
	width: 10, 
	height:10
});

var button = Ti.UI.createButton({
	title:'Click Me!'
});

button.addEventListener('click', function(e) { 
	alert(view.getVisible());
	view.setVisible(!view.getVisible()); 
});


win.add(button);
win.add(view);

win.open();
Result: After running the sample code, click on the button to execute view.getVisible(), which return value 'null'. Expected result: If the property was never defined by the user, then the default value should be returned.

Comments

  1. jithinpv 2013-04-12

    view.getVisible() returns undefined. Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
  2. Pedro Enrique 2015-02-10

    Some quick unit tests
       var win = Ti.UI.createWindow({
       	backgroundColor: '#ccc'
       });
       
       var button1 = Ti.UI.createButton({
       	top: 0, height: 10, width: 100
       });
       var slider = Ti.UI.createSlider({
       	top: 0, height: 10, width: 100
       });
       var _switch = Ti.UI.createSwitch({
       	top: 0, height: 10, width: 100
       });
       var textArea = Ti.UI.createTextArea({
       	top: 0, height: 10, width: 100
       });
       var textField = Ti.UI.createTextField({
       	top: 0, height: 10, width: 100
       });
       var view = Ti.UI.createView({
       	top: 0, height: 10, width: 100
       });
        
       var button2 = Ti.UI.createButton({
       	title:'Click Me!',
       	bottom: 10
       });
       
       win.add(button1);
       win.add(slider);
       win.add(_switch);
       win.add(textArea);
       win.add(textField);
       win.add(button2);
       win.add(view);
       win.open();
        
       function assert(what, actual, expected) {
       	Ti.API.info(what + ' should be "' + expected + '" actual is "' + actual + '"');
       	if(actual != expected) {
       		throw new Error(what + ' expected to be "' + expected + '" but was "' + actual + '"');
       	}
       }
       
       button2.addEventListener('click', function(e) { 
       	Ti.API.info('==============================');
       	assert('button1.enabled', button1.enabled, true);
       	assert('slider.enabled', slider.enabled, true);
       	assert('_switch.enabled', _switch.enabled, true);
       	assert('textArea.enabled', textArea.enabled, true);
       	assert('textField.enabled', textField.enabled, true);
       	assert('view.visible', view.visible, true);
       	Ti.API.info('==============================');
       	button1.enabled = !button1.enabled;
       	slider.enabled = !slider.enabled;
       	_switch.enabled = !_switch.enabled;
       	textArea.enabled = !textArea.enabled;
       	textField.enabled = !textField.enabled;
       	view.visible = !view.visible;
       	Ti.API.info('==============================');
       	assert('button1.enabled', button1.enabled, false);
       	assert('slider.enabled', slider.enabled, false);
       	assert('_switch.enabled', _switch.enabled, false);
       	assert('textArea.enabled', textArea.enabled, false);
       	assert('textField.enabled', textField.enabled, false);
       	assert('view.visible', view.visible, false);
       	Ti.API.info('==============================');
       	Ti.API.info('');
       	Ti.API.info('==============================');
       	assert('button1.getEnabled()', button1.getEnabled(), false);
       	assert('slider.getEnabled()', slider.getEnabled(), false);
       	assert('_switch.getEnabled()', _switch.getEnabled(), false);
       	assert('textArea.getEnabled()', textArea.getEnabled(), false);
       	assert('textField.getEnabled()', textField.getEnabled(), false);
       	assert('view.getVisible()', view.getVisible(), false);
       	Ti.API.info('==============================');
       	button1.setEnabled(!button1.getEnabled());
       	slider.setEnabled(!slider.getEnabled());
       	_switch.setEnabled(!_switch.getEnabled());
       	textArea.setEnabled(!textArea.getEnabled());
       	textField.setEnabled(!textField.getEnabled());
       	view.setVisible(!view.getVisible());
       	assert('button1.getEnabled()', button1.getEnabled(), true);
       	assert('slider.getEnabled()', slider.getEnabled(), true);
       	assert('_switch.getEnabled()', _switch.getEnabled(), true);
       	assert('textArea.getEnabled()', textArea.getEnabled(), true);
       	assert('textField.getEnabled()', textField.getEnabled(), true);
       	assert('view.getVisible()', view.getVisible(), true);
       	Ti.API.info('==============================');
       });
       
  3. Pedro Enrique 2015-02-10

    PR https://github.com/appcelerator/titanium_mobile/pull/6634
  4. Pedro Enrique 2015-02-10

    Ignore my last comment. PR: https://github.com/appcelerator/titanium_mobile/pull/6635
  5. Khushbu Agrawal 2015-02-25

    Verified the fix with below Test Environment. Appc Studio : 4.0.0.201502171827 Ti SDK : 4.0.0.v20150224141439 Mac OSX : 10.10.1 Alloy : 1.5.1 CLI - 3.6.0-dev Code Processor: 1.1.1 iPhone 6+: iOS 8.1 console.log("Visible property value", + view.getVisible()); view.getVisible() method works fine.If the user hasn't assigned any value to visible property then it returns default value (1). console.log("Enabled property value", + view.getEnabled()); //Enabled property value NaN view.getEnabled() method doesn't work as expected.If the user hasn't assigned any value to enabled property then it returns NaN as default value which is unexpected. So Reopening this ticket.
  6. Ingo Muschenetz 2015-02-27

    [~emerriman] to review.
  7. Eric Wieber 2015-02-27

    I see the same as Khushbu reported, using: Titanium SDK 4.0.0.v20150227065820 Studio 3.4.2.201502181619 CLI 3.4.2-alpha Xcode 6.2b5 On iPhone 6 and iPhone 6 sim. The unit test above is returning correct values, but it fails to cover the case of checking getEnabled() before setting the enabled property to a value. When calling getEnabled() before setting the enabled property, I see a return value of 'undefined'. Should be 'true', the default.
  8. Vishal Duggal 2015-03-05

    enabled is not a property supported on the base View object on iOS platform. So it return undefined
  9. Eric Wieber 2015-03-18

    Ah, you're right Vishal. In light of that: Verified fixed using: Titanium SDK 4.0.0.v20150317234215 Studio 4.0.0.201503171723 CLI 3.4.2 Xcode 6.2 Node 0.12 On: iPhone 6, iOS 8.2 iPad Air 2, iOS 8.2

JSON Source