Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24851] Android: Deprecate Label "wordWrap" property (it's not needed)

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-11-28T23:00:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.0.0
ComponentsAndroid
Labelsandroid, breaking-change, label, wordwrap
ReporterGary Mathews
AssigneeJoshua Quick
Created2017-06-19T19:44:58.000+0000
Updated2018-11-29T15:10:14.000+0000

Description

*Summary:* The Ti.UI.Label "wordWrap" property is Android only (ie: not portable). When set false, newline '\n' characters are ignored and the label is put into single-line mode. This property is unnecessary and should be ignored/deprecated. *Reason 1:* If you want newline '\n' characters to be ignored, then you should remove them from the string yourself before applying them to the label. For example:
var myString = "Test1\nTest2\nTest3";
var label = Ti.UI.createLabel({
	text: myString.replace(/\n/g, ""),
});
*Reason 2:* If you want to limit a label's text to 1 line, then you should set the "maxLines" property to 1. This property is supported on all platforms and will show ellipsis (enabled by default) if the text does not fit within the label. It also honors newlines characters too and would show ellipsis where the line break occurs.
var label = Ti.UI.createLabel({
	text: "This is line 1.\nLine 2 cannot be seen.",
	maxLines: 1,
});
*Reason 3:* Setting a width on a label implies a wrapping width already, making the "wordWrap" property redundant. And if you don't want to word wrap (and honor newlines), then you can set the label's width to Ti.UI.SIZE (the default setting) and put it into a horizontal ScrollView.

Comments

  1. Gary Mathews 2017-06-19

    master: https://github.com/appcelerator/titanium_mobile/pull/9160
  2. Joshua Quick 2018-03-09

    Reference to our discussion about this issue here: https://github.com/appcelerator/titanium_mobile/pull/9161#pullrequestreview-45374947 We may want to re-evaluate the usefulness of this property. Especially since iOS does not support it. (Windows does. We should double check that platform's behavior.) In my opinion, setting the label's width already implies that the developer wants it to word/line-wrap the text at that position. So, I think the "wordWrap" property is useless. If the developer wants the label to be single-line, then setting the "maxLines" property to 1 will do the job. And if developers wants the newline '\n' characters ignored, then they can string replace or remove the characters themselves.
  3. Lokesh Choudhary 2018-05-09

    FR Passed. Waiting for merger to get enabled.
  4. Joshua Quick 2018-05-10

    [~lchoudhary], this is a breaking change. Especially since I've seen customer code use this property. I think this should be pushed out to Titanium 8.0.0. _Note:_ _I would go a step further and deprecate the wordWrap property and have it log a warning. The width assigned to the label implies the word wrapping width. So, the wordWrap property is useless._
  5. Joshua Quick 2018-11-17

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10480
  6. Lokesh Choudhary 2018-11-21

    FR Passed.
  7. Lokesh Choudhary 2018-11-28

    PR Merged.
  8. Samir Mohammed 2018-11-29

    *Closing ticket*. Verified fix in SDK version 8.0.0.v20181128164557. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/10480

JSON Source