[TIMOB-24851] Android: Deprecate Label "wordWrap" property (it's not needed)
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-11-28T23:00:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 8.0.0 |
Components | Android |
Labels | android, breaking-change, label, wordwrap |
Reporter | Gary Mathews |
Assignee | Joshua Quick |
Created | 2017-06-19T19:44:58.000+0000 |
Updated | 2018-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
.
master: https://github.com/appcelerator/titanium_mobile/pull/9160
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.
FR Passed. Waiting for merger to get enabled.
[~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, thewordWrap
property is useless._PR (master): https://github.com/appcelerator/titanium_mobile/pull/10480
FR Passed.
PR Merged.
*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