Skip to content

Commit

Permalink
(6_0_X) timob-24479 Android: fix TiUILabel maxLines not working
Browse files Browse the repository at this point in the history
  • Loading branch information
fmerzadyan committed Mar 14, 2017
1 parent 76c569f commit 30c734d
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TiUILabel extends TiUIView
private float shadowX = 0f;
private float shadowY = 0f;
private int shadowColor = Color.TRANSPARENT;
private int maxLines = -1;

public TiUILabel(final TiViewProxy proxy)
{
Expand Down Expand Up @@ -186,7 +187,8 @@ public void processProperties(KrollDict d)
tv.setLines(TiConvert.toInt(d, TiC.PROPERTY_LINES));
}
if (d.containsKey(TiC.PROPERTY_MAX_LINES)) {
tv.setMaxLines(TiConvert.toInt(d, TiC.PROPERTY_MAX_LINES));
maxLines = TiConvert.toInt(d.get(TiC.PROPERTY_MAX_LINES));
refreshMaxLines();
}
if (d.containsKey(TiC.PROPERTY_LINE_SPACING)) {
Object value = d.get(TiC.PROPERTY_LINE_SPACING);
Expand Down Expand Up @@ -233,6 +235,7 @@ public void processProperties(KrollDict d)
case UIModule.TEXT_ELLIPSIZE_TRUNCATE_MARQUEE:
// marquee effect only works in single line mode
tv.setSingleLine(true);
refreshMaxLines();
tv.setSelected(true);
ellipsize = TruncateAt.MARQUEE; break;
default:
Expand All @@ -245,6 +248,7 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_WORD_WRAP)) {
wordWrap = TiConvert.toBoolean(d, TiC.PROPERTY_WORD_WRAP, true);
tv.setSingleLine(!wordWrap);
refreshMaxLines();
}

if (d.containsKey(TiC.PROPERTY_SHADOW_OFFSET)) {
Expand Down Expand Up @@ -327,6 +331,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
case UIModule.TEXT_ELLIPSIZE_TRUNCATE_MARQUEE:
// marquee effect only works in single line mode
tv.setSingleLine(true);
refreshMaxLines();
tv.setSelected(true);
ellipsize = TruncateAt.MARQUEE; break;
default:
Expand All @@ -337,6 +342,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
} else if (key.equals(TiC.PROPERTY_WORD_WRAP)) {
wordWrap = TiConvert.toBoolean(newValue, true);
tv.setSingleLine(!wordWrap);
refreshMaxLines();
} else if (key.equals(TiC.PROPERTY_AUTO_LINK)) {
Linkify.addLinks(tv, TiConvert.toInt(newValue));
} else if (key.equals(TiC.PROPERTY_SHADOW_OFFSET)) {
Expand All @@ -355,7 +361,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
} else if (key.equals(TiC.PROPERTY_LINES)) {
tv.setLines(TiConvert.toInt(newValue));
} else if (key.equals(TiC.PROPERTY_MAX_LINES)) {
tv.setMaxLines(TiConvert.toInt(newValue));
maxLines = TiConvert.toInt(newValue);
refreshMaxLines();
} else if (key.equals(TiC.PROPERTY_ATTRIBUTED_STRING) && newValue instanceof AttributedStringProxy) {
Spannable spannableText = AttributedStringProxy.toSpannable(((AttributedStringProxy)newValue), TiApplication.getAppCurrentActivity());
if (spannableText != null) {
Expand All @@ -374,4 +381,15 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
public void setClickable(boolean clickable) {
((TextView)getNativeView()).setClickable(clickable);
}

/**
* {@link TextView#setSingleLine} method undoes the {@link TextView#setMaxLines(int)}} changes therefore to counter that problem, call this method after setSingleLine is invoked.
*/
private void refreshMaxLines()
{
TextView tv = (TextView) getNativeView();
if (tv != null && maxLines > 0) {
tv.setMaxLines(maxLines);
}
}
}

0 comments on commit 30c734d

Please sign in to comment.