[ALOY-812] Alloy: Automatically convert string-values for number-properties like borderWidth in TSS
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2014-03-25T16:15:46.000+0000 |
Affected Version/s | Alloy 1.2.1 |
Fix Version/s | n/a |
Components | n/a |
Labels | alloy, android, dip, px, tss |
Reporter | Fokke Zandbergen |
Assignee | Tim Poulsen |
Created | 2013-08-29T10:39:50.000+0000 |
Updated | 2018-03-07T22:28:27.000+0000 |
Description
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).
Attachments
File | Date | Size |
---|---|---|
S420.png | 2014-03-25T16:15:16.000+0000 | 105815 |
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.
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.
Marking as invalid pending developer response
[~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.
Closing as invalid. If this is incorrect, please reopen.