Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1703] XML attribute shortcuts for verticalAlign are not used on Android

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionWon't Fix
Resolution Date2019-09-04T20:42:45.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterBrenton House
AssigneeEwan Harris
Created2019-08-30T15:55:56.000+0000
Updated2020-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

FileDateSize
Screenshot_1567180243.png2019-08-30T15:54:55.000+0000112921
Screenshot_1567180456.png2019-08-30T15:54:55.000+0000113205

Comments

  1. Joshua Quick 2019-08-30

    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.
  2. Brenton House 2019-08-30

    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!
  3. Joshua Quick 2019-08-30

    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.
  4. Ewan Harris 2019-09-04

    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" to Ti.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.
  5. Brenton House 2019-09-04

    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
  6. Brenton House 2020-01-24

    I've created a PR for Alloy here: https://github.com/appcelerator/alloy/pull/953

JSON Source