[ALOY-1324] Support Boolean (and Number) values in XML views
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | None |
| Status | Closed |
| Resolution | Duplicate |
| Resolution Date | 2016-03-21T08:40:39.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | XML |
| Labels | n/a |
| Reporter | Fokke Zandbergen |
| Assignee | Bruce Wayne |
| Created | 2015-11-03T16:22:16.000+0000 |
| Updated | 2016-03-21T08:40:39.000+0000 |
Description
This is a new attempt after ALOY-968 was closed with little discussion.
The following view snippet:
<Label focusable="false" borderWidth="5" borderColor="#000">Hello, world!</Label>
Will compile to:
$.__views.__alloyId0 = Ti.UI.createLabel({
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: "Hello, world!",
focusable: "false",
borderWidth: "5",
borderColor: "#000",
id: "__alloyId0"
});
For some properties/values (mostly Number) this is not a problem, but focusable: "false" will evaluate to true.
Of course these could and in most cases _should_ be set in TSS which supports Boolean and Number types. However, in particular boolean flags that impact the markup/layout (show, hide, animate..) it can make sense to set them in the XML view.
Simply casting all /^[0-9]+$/ values to Number and all /^(true|false)$/ to Boolean might break apps and will make it impossible to keep them as strings if that is in fact what you want.
A workaround for Boolean values would be to set Alloy.Globals.TRUE = true; in alloy.js and then use this as value in the XML. Maybe we can introduce Ti.TRUE and Ti.FALSE as an official "workaround"?
I must say I'm not keen on either two.. so open for other ideas.
Is partly duplicated by ALOY-1355