[ALOY-812] Alloy: Automatically convert string-values for number-properties like borderWidth in TSS

GitHub Issuen/a
TypeNew Feature
Resolution Date2014-03-25T16:15:46.000+0000
Affected Version/sAlloy 1.2.1
Fix Version/sn/a
Labelsalloy, android, dip, px, tss
ReporterFokke Zandbergen
AssigneeTim Poulsen


When doing an app for both iOS and Android, I usually set the default unit to dp. This works great, but some properties like borderWidth and borderRadius are always interpreted as px on Android. So for the right size, I need to use Alloy's builtin measurement.dpToPx. However, TSS does not (longer) support using methods, only (global) values. This means for every different value I use, I need to pre-calculate the px-value in alloy.js and store it in Alloy.Globals so I can use it in the TSS. This is far from ideal. Why not add builtin casting of non-number values to number-values for properties that require that type? For example, in TSS I'd have:
"View": {
  borderWidth: '5dp'
Which then would be compiled to:
borderWidth: Alloy.measurement.toNumber('5dp');
The Alloy.measurement.toNumber method then should read the unit from the string and perform the appropriate conversion to get the number-value (px).




  1. Fokke Zandbergen 2013-08-29 Just fixing these properties to also honor the default unit setting in the Titanium SDK would be even better, but of course break existing apps.
  2. Tim Poulsen 2014-03-25 See the attached screen. I don't believe this is a valid issue. Alloy app, default unit set in tiapp.xml to system with borderWidth:20 on the left and borderWidth:'20dp' on the right. If I set the default unit to dp in tiapp.xml, the result with 20 and '20dp' match, as would be expected.
  3. Tim Poulsen 2014-03-25 Marking as invalid pending developer response
  4. Tim Poulsen 2014-03-26
  5. Fokke Zandbergen 2014-04-17 [~skypanther] this indeed seems to be fixed now https://github.com/appcelerator/titanium_mobile/pull/5521/files added support for specifying a unit with the value.
  6. Eric Merriman 2018-03-07 Closing as invalid. If this is incorrect, please reopen.

JSON Source