[ALOY-1703] XML attribute shortcuts for verticalAlign are not used on Android
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2019-09-04T20:42:45.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Brenton House |
Assignee | Ewan Harris |
Created | 2019-08-30T15:55:56.000+0000 |
Updated | 2020-01-24T15:10:06.000+0000 |
Description
When using shortcuts for verticalAlign: i.e. "center" for "Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER", the text is instead top aligned.
This does not work:
<Alloy>
<Window class="container" id="index">
<View layout="vertical" height="size">
<ImageView image="/images/axway-logo.png" width="80%" onClick="Alloy.Globals.Start" />
<Label id="label" onClick="Alloy.Globals.Start" text="Begin Survey" top="100" width="75%" backgroundColor="#c23838" color="white" textAlign="center" verticalAlign="center" height="100" font.fontSize="30" />
<Button id="label" onClick="Alloy.Globals.Start" title="Begin Survey" top="100" width="75%" backgroundColor="#c23838" color="white" textAlign="center" verticalAlign="center" height="100" font.fontSize="30" />
</View>
</Window>
</Alloy>
Whereas this does work:
<Alloy>
<Window class="container" id="index">
<View layout="vertical" height="size">
<ImageView image="/images/axway-logo.png" width="80%" onClick="Alloy.Globals.Start" />
<Label id="label" onClick="Alloy.Globals.Start" text="Begin Survey" top="100" width="75%" backgroundColor="#c23838" color="white" textAlign="center" verticalAlign="Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER" height="100" font.fontSize="30" />
<Button id="label" onClick="Alloy.Globals.Start" title="Begin Survey" top="100" width="75%" backgroundColor="#c23838" color="white" textAlign="center" verticalAlign="Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER" height="100" font.fontSize="30" />
</View>
</Window>
</Alloy>
Attachments
File | Date | Size |
---|---|---|
Screenshot_1567180243.png | 2019-08-30T15:54:55.000+0000 | 112921 |
Screenshot_1567180456.png | 2019-08-30T15:54:55.000+0000 | 113205 |
Android's
Ti.UI.TEXT_VERTICAL_ALIGNMENT_CENTER
constant is set to"middle"
, not"center"
. [UIModule.java#L248](https://github.com/appcelerator/titanium_mobile/blob/1a8f487da199055828b11e0537923c1bac3a344d/android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java#L248) And on Windows, this constant is set to"TEXT_VERTICAL_ALIGNMENT_CENTER"
. [Constants.cpp#L1134](https://github.com/appcelerator/titanium_mobile_windows/blob/5c59f2f5bc6778d8302ecd971b92778ca1715dfd/Source/TitaniumKit/src/UI/Constants.cpp#L1134) I don't think you should be making assumptions about what the constant value is assigned to.ah! ok. I was just assuming that since I could use "center" instead of Ti.UI.TEXT_ALIGNMENT_CENTER in XML View I would be able to use "center" instead of Ti.UI.TEXT_VERTICAL_ALIGNMENT_CENTER as well. I will just alias it in Alloy so that either one will work. Thanks!
Ideally (and to be fair), string constants that Titanium defines should match between platforms. However, some constants map directly to their native equivalents on Android and iOS. Those constants will never be the same between platforms. Especially the numeric ones. I guess the real issue here is that it's inconvenient to write out such long constant names repeatedly.
Based off Josh's comment I'm going to close this as it's down to the SDK. I don't think we should accept a PR to alias
"center"
toTi.UI.TEXT_ALIGNMENT_CENTER
in Alloy as it would change the meaning of values defined in the SDK which (imo) we should not be doing.I understand but if anyone is curious, you can see how I implemented it here. Works great as I can now use "center" in my xml! https://github.com/brentonhouse/titanium-turbo/pull/51/files#diff-4a4e7dbd8f9f9fd70e648e82873bd3fd
I've created a PR for Alloy here: https://github.com/appcelerator/alloy/pull/953