Skip to content

Commit

Permalink
Merge pull request #7062 from cheekiatng/timob-19357
Browse files Browse the repository at this point in the history
[TIMOB-19357] iOS: Add Ellipsize support for AttributedString
  • Loading branch information
hansemannn committed Aug 25, 2015
2 parents 0b44a22 + e9f4620 commit 066ebd1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apidoc/Titanium/UI/Attribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ properties:
Titanium.UI.ATTRIBUTE_STROKE_WIDTH, Titanium.UI.ATTRIBUTE_SHADOW,
Titanium.UI.ATTRIBUTE_WRITING_DIRECTION, Titanium.UI.ATTRIBUTE_TEXT_EFFECT,
Titanium.UI.ATTRIBUTE_BASELINE_OFFSET, Titanium.UI.ATTRIBUTE_STRIKETHROUGH_COLOR,
Titanium.UI.ATTRIBUTE_OBLIQUENESS, Titanium.UI.ATTRIBUTE_EXPANSION]
Titanium.UI.ATTRIBUTE_OBLIQUENESS, Titanium.UI.ATTRIBUTE_EXPANSION, Titanium.UI.ATTRIBUTE_LINE_BREAK]
optional: false
- name: value
summary: Attribute value.
Expand Down Expand Up @@ -93,6 +93,17 @@ properties:
On IOS, if you use the <Titanium.UI.ATTRIBUTE_TEXT_EFFECT>, you must use the only supported iOS 7 constant
<Titanium.UI.ATTRIBUTE_LETTERPRESS_STYLE>.
On IOS, if you use the <Titanium.UI.ATTRIBUTE_LINE_BREAK>, you must use one of
these constants:
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_WORD_WRAPPING>
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_CHAR_WRAPPING>
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_CLIPPING>
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_HEAD>
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_TAIL>
* <Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_MIDDLE>
These can also be combined the same way as the underline styles.
type: Number
constants: [ Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_*,
Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_*,
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/TiUIAttributedStringProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ typedef enum {
AttributeNameUnderlineColor,
AttributeNameStrikethroughColor,
AttributeNameObliqueness,
AttributeNameExpansion
AttributeNameExpansion,
AttributeNameLineBreak
} AttributeName;

#pragma mark - Not exposed to JS. Internal Use Only.
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUIAttributedStringProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ -(void)addAttribute:(id)args
attrName = NSExpansionAttributeName;
attrValue = [TiUtils numberFromObject:value];
break;

case AttributeNameLineBreak:
attrName = NSParagraphStyleAttributeName;
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
NSNumber * num = [TiUtils numberFromObject:value];
[paragraphStyle setLineBreakMode:[num unsignedIntegerValue]];
attrValue = paragraphStyle;
break;
}
if(errorMessage != nil) {
DebugLog(@"[WARN] Ti.UI.%@", errorMessage);
Expand Down
7 changes: 7 additions & 0 deletions iphone/Classes/UIModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_WRITING_DIRECTION_LEFT_TO_RIGHT;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_WRITING_DIRECTION_RIGHT_TO_LEFT;

@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_WORD_WRAPPING;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_CHAR_WRAPPING;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_CLIPPING;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_HEAD;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_TAIL;
@property (nonatomic,readonly) NSNumber* ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_MIDDLE;

@property (nonatomic,readonly) NSString * ATTRIBUTE_LETTERPRESS_STYLE;
#endif

Expand Down
26 changes: 25 additions & 1 deletion iphone/Classes/UIModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ -(NSNumber*)convertUnits:(id)args
MAKE_SYSTEM_PROP(ATTRIBUTE_STRIKETHROUGH_COLOR, AttributeNameStrikethroughColor);
MAKE_SYSTEM_PROP(ATTRIBUTE_OBLIQUENESS, AttributeNameObliqueness);
MAKE_SYSTEM_PROP(ATTRIBUTE_EXPANSION, AttributeNameExpansion);
MAKE_SYSTEM_PROP(ATTRIBUTE_LINE_BREAK, AttributeNameLineBreak);

-(NSNumber*)ATTRIBUTE_UNDERLINE_STYLE_NONE
{
Expand Down Expand Up @@ -605,7 +606,30 @@ -(NSString *)ATTRIBUTE_LETTERPRESS_STYLE
{
return NSTextEffectLetterpressStyle;
}

-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_WORD_WRAPPING
{
return NUMINTEGER(NSLineBreakByWordWrapping);
}
-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_CHAR_WRAPPING
{
return NUMINTEGER(NSLineBreakByCharWrapping);
}
-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_CLIPPING
{
return NUMINTEGER(NSLineBreakByClipping);
}
-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_HEAD
{
return NUMINTEGER(NSLineBreakByTruncatingHead);
}
-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_TAIL
{
return NUMINTEGER(NSLineBreakByTruncatingTail);
}
-(NSNumber*)ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_MIDDLE
{
return NUMINTEGER(NSLineBreakByTruncatingMiddle);
}
#endif

@end
Expand Down

0 comments on commit 066ebd1

Please sign in to comment.