Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-24866

Android: Setting a TextField's "padding" resets its alignment to left/center

    Details

    • Story Points:
      3
    • Sprint:
      2017 Sprint 17 SDK, 2017 Sprint 18 SDK, 2017 Sprint 19 SDK, 2017 Sprint 20 SDK, 2017 Sprint 21 SDK, 2017 Sprint 22 SDK, 2017 Sprint 23 SDK

      Description

      Summary:
      Setting the padding on a TextField wrongly resets its horizontal "textAlign" and "verticalAlign" properties to left and center respectively.

      Steps to reproduce:

      1. Build and run the below code on Android.
      2. Tap the "Set Padding" button.
      3. Notice that the text alignment of the 3 fields change to left/center.

      var window = Ti.UI.createWindow({ layout: "vertical" });
       
      var textField1 = Ti.UI.createTextField(
      {
      	value: "Top-Left Aligned Text",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
      	verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_TOP,
      	backgroundColor: "black",
      	width: "90%",
      	height: "20%",
      	top: "5%",
      });
      window.add(textField1);
       
      var textField2 = Ti.UI.createTextField(
      {
      	value: "Centered Text",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
      	verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_CENTER,
      	backgroundColor: "black",
      	width: "90%",
      	height: "20%",
      	top: "5%",
      });
      window.add(textField2);
       
      var textField3 = Ti.UI.createTextField(
      {
      	value: "Bottom-Right Aligned Text",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_RIGHT,
      	verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM,
      	backgroundColor: "black",
      	width: "90%",
      	height: "20%",
      	top: "5%",
      });
      window.add(textField3);
       
      var button = Ti.UI.createButton(
      {
      	title: "Set Padding",
      	top: "5%",
      });
      button.addEventListener("click", function(e)
      {
      	var padding = { top: 5, left: 5, bottom: 5, right: 5 };
      	textField1.padding = padding;
      	textField2.padding = padding;
      	textField3.padding = padding;
      });
      window.add(button);
       
      window.open();
      

      Expected Result:
      Configured alignment should not change.

      Work-Around:
      Developers can work-around this issue by setting the "textAlignment" and "verticalAlignment" properties after setting the "padding" property.

      Cause:
      The Java TiUIText.setTextPadding() method is resetting the field's gravity to CENTER_VERTICAL when it shouldn't.
      https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIText.java#L233

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                jquick Joshua Quick
                Tester:
                Samir Mohammed
              • Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-10812
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code