[ALOY-284] Accept Titanium SDK constants in the XML markup
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2013-01-08T16:56:33.000+0000 |
Affected Version/s | 2012 Sprint 19 |
Fix Version/s | Alloy 0.3.5, 2013 Sprint 02 |
Components | XML |
Labels | notable |
Reporter | Benjamin Hatfield |
Assignee | Unknown |
Created | 2012-09-19T14:23:49.000+0000 |
Updated | 2018-03-07T22:25:49.000+0000 |
Description
Currently, the property attributes in the view XML markup do not accept the Titanium SDK constants. For instance, the label will not appear if using:
This works fine in the TSS and controller code.
Side note: On iOS, using the value of the constant works for 'width' but not 'textAlign', that is, setting width='FILL' works but not textAlign='1'. This fails on Android.
The core of the issue is that XML attributes are strings. They have no sense of type. So the default behavior when using the XML attributes is that the value is treated as a string. So right now, when you put the name of a Ti constant in an attribute, the generated code sees
"Ti.UI.TEXT_ALIGNMENT_CENTER"
, notTi.UI.TEXT_ALIGNMENT_CENTER
. I will get Ti constants, Alloy.CFG values, and L() localizations working in XML attributes, but further handling of specific types will require mappings from API property names to the expected type, so conversions can be performed. One such conversion like this already exists. Check out the parser for Ti.Map.Annotation which converts the XML attribute strings for latitude and longitude to floats: https://github.com/appcelerator/alloy/blob/master/Alloy/commands/compile/parsers/Ti.Map.Annotation.jsMoving this to after 3.0.0. Rather than do a partial fix here, we'll save it until we can actually implement a fully dynamic syntax for the xml attributes. Something along the lines of:
The {} syntax is being used for binding. Titanium constants will be made usable as the original description requests.