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.
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
Some quick unit tests
PR https://github.com/appcelerator/titanium_mobile/pull/6634
Ignore my last comment. PR: https://github.com/appcelerator/titanium_mobile/pull/6635
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.
[~emerriman] to review.
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.
enabled is not a property supported on the base View object on iOS platform. So it return undefined
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