Skip to content

Commit

Permalink
Merge pull request #8086 from AngelkPetkov/TIMOB-23501
Browse files Browse the repository at this point in the history
[TIMOB-23501] iOS: Label.ellipsize should not return undefined
  • Loading branch information
hansemannn committed Jun 29, 2016
2 parents d644f61 + a67c5ea commit 54a11a4
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class LabelProxy extends TiViewProxy
public LabelProxy()
{
defaultValues.put(TiC.PROPERTY_TEXT, "");
defaultValues.put(TiC.PROPERTY_ELLIPSIZE, UIModule.TEXT_ELLIPSIZE_TRUNCATE_END);
}

public LabelProxy(TiContext tiContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int TEXT_ELLIPSIZE_TRUNCATE_MIDDLE = 1;
@Kroll.constant public static final int TEXT_ELLIPSIZE_TRUNCATE_END = 2;
@Kroll.constant public static final int TEXT_ELLIPSIZE_TRUNCATE_MARQUEE = 3;
@Kroll.constant public static final int TEXT_ELLIPSIZE_TRUNCATE_NONE = 4;

@Kroll.constant public static final String SIZE = TiC.LAYOUT_SIZE;
@Kroll.constant public static final String FILL = TiC.LAYOUT_FILL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class TiUILabel extends TiUIView

private int defaultColor;
private boolean wordWrap = true;
private TruncateAt ellipsize;
private TruncateAt ellipsize = TruncateAt.END;
private float shadowRadius = DEFAULT_SHADOW_RADIUS;
private float shadowX = 0f;
private float shadowY = 0f;
Expand Down Expand Up @@ -135,6 +135,7 @@ public boolean onTouchEvent(MotionEvent event) {
tv.setKeyListener(null);
tv.setFocusable(false);
tv.setSingleLine(false);
tv.setEllipsize(ellipsize);
TiUIHelper.styleText(tv, null);
defaultColor = tv.getCurrentTextColor();
setNativeView(tv);
Expand Down Expand Up @@ -217,7 +218,6 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_ELLIPSIZE)) {

Object value = d.get(TiC.PROPERTY_ELLIPSIZE);

if (value instanceof Boolean){
ellipsize = (Boolean) value ? TruncateAt.END : null;
}
Expand Down
4 changes: 2 additions & 2 deletions apidoc/Titanium/UI/Label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ properties:
summary: |
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle.
constants: Titanium.UI.TEXT_ELLIPSIZE_TRUNCATE_*
type: [Number, Boolean]
default: false
type: Number
default: Titanium.UI.TEXT_ELLIPSIZE_TRUNCATE_END
platforms: [android, mobileweb, iphone, ipad]

- name: font
Expand Down
36 changes: 36 additions & 0 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,33 @@ properties:
permission: read-only
platforms: [iphone, ipad]

- name: TEXT_ELLIPSIZE_TRUNCATE_WORD_WRAP
summary: Add ellipses at word boundaries, unless the word itself doesn't fit on a single line.
description: |
One of the group of constants for the <Titanium.UI.Label.ellipsize> property.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: TEXT_ELLIPSIZE_TRUNCATE_CHAR_WRAP
summary: Add ellipses before the first character that doesnt fit.
description: |
One of the group of constants for the <Titanium.UI.Label.ellipsize> property.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: TEXT_ELLIPSIZE_TRUNCATE_CLIP
summary: Lines are simply not drawn past the edge of the text container.
description: |
One of the group of constants for the <Titanium.UI.Label.ellipsize> property.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "6.0.0"

- name: TEXT_ELLIPSIZE_TRUNCATE_START
summary: Add ellipses at the beginning of the label if the text is too large to fit.
description: |
Expand Down Expand Up @@ -1283,6 +1310,15 @@ properties:
platforms: [android]
since: "4.1.0"

- name: TEXT_ELLIPSIZE_TRUNCATE_NONE
summary: Disables ellipsizing of the label. The text will be cut off if it is too long.
description: |
One of the group of constants for the <Titanium.UI.Label.ellipsize> property.
type: Number
permission: read-only
platforms: [android]
since: "6.0.0"

- name: EXTEND_EDGE_TOP
summary: Specifies that the top edge of the window can extend.
description: |
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiUILabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ -(void)setColor_:(id)color
-(void)setEllipsize_:(id)value
{
ENSURE_SINGLE_ARG(value, NSNumber);
//for bool case and parity with android
if ([TiUtils intValue:value] == 1) {
if ([[TiUtils stringValue:value] isEqualToString:@"true"]) {
[[self label] setLineBreakMode:NSLineBreakByTruncatingTail];
return;
}
Expand Down
5 changes: 5 additions & 0 deletions iphone/Classes/TiUILabelProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ -(UIView *)parentViewForChild:(TiViewProxy *)child
return [[(TiUILabel*)[self view] label] superview];
}

-(NSNumber*)ellipsize:(id)unused
{
return NUMINTEGER([[(TiUILabel*)[self view] label] lineBreakMode]);
}

@end

#endif
3 changes: 3 additions & 0 deletions iphone/Classes/UIModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_CENTER;
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_RIGHT;

@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_WORD_WRAP;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_CHAR_WRAP;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_CLIP;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_START;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_MIDDLE;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_END;
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/UIModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ -(TiUIActivityIndicatorStyleProxy*)ActivityIndicatorStyle
MAKE_SYSTEM_PROP(TEXT_VERTICAL_ALIGNMENT_CENTER,UIControlContentVerticalAlignmentCenter);
MAKE_SYSTEM_PROP(TEXT_VERTICAL_ALIGNMENT_BOTTOM,UIControlContentVerticalAlignmentBottom);

MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_WORD_WRAP, NSLineBreakByWordWrapping);
MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_CHAR_WRAP, NSLineBreakByCharWrapping);
MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_CLIP, NSLineBreakByClipping);
MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_START, NSLineBreakByTruncatingHead);
MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_MIDDLE, NSLineBreakByTruncatingMiddle);
MAKE_SYSTEM_PROP(TEXT_ELLIPSIZE_TRUNCATE_END, NSLineBreakByTruncatingTail);
Expand Down

0 comments on commit 54a11a4

Please sign in to comment.