Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-3408] iOS: Support justified text-align in Labels, Buttons and TextFields #8562

Merged
merged 2 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions apidoc/Titanium/UI/UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2142,17 +2142,29 @@ properties:
- name: TEXT_ALIGNMENT_CENTER
summary: Center align text.
description: |
Use with the <Titanium.UI.TextField.textAlign> and
Use with the <Titanium.UI.TextField.textAlign>, <Titanium.UI.Button.textAlign> and
<Titanium.UI.TextArea.textAlign> properties.

This constant is a string on Android, and a number on iOS and Mobile Web.
type: [Number, String]
permission: read-only

- name: TEXT_ALIGNMENT_JUSTIFY
summary: Justify align text.
description: |
Use with the <Titanium.UI.TextField.textAlign>, <Titanium.UI.Button.textAlign> and
<Titanium.UI.TextArea.textAlign> properties.

This constant is a number and only available on iOS.
type: [Number, String]
permission: read-only
platforms: [iphone, ipad]
since: "6.1.0"

- name: TEXT_ALIGNMENT_LEFT
summary: Left align text.
description: |
Use with the <Titanium.UI.TextField.textAlign> and
Use with the <Titanium.UI.TextField.textAlign>, <Titanium.UI.Button.textAlign> and
<Titanium.UI.TextArea.textAlign> properties.

This constant is a string on Android, and a number on iOS and Mobile Web.
Expand All @@ -2162,7 +2174,7 @@ properties:
- name: TEXT_ALIGNMENT_RIGHT
summary: Right align text.
description: |
Use with the <Titanium.UI.TextField.textAlign> and
Use with the <Titanium.UI.TextField.textAlign>, <Titanium.UI.Button.textAlign> and
<Titanium.UI.TextArea.textAlign> properties.

This constant is a string on Android, and a number on iOS and Mobile Web.
Expand Down
21 changes: 2 additions & 19 deletions iphone/Classes/TiUIButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -412,26 +412,9 @@ -(void)setVerticalAlign_:(id)align
-(void)setTextAlign_:(id)align
{
button = [self button];
NSTextAlignment alignment = NSTextAlignmentNatural;
NSTextAlignment alignment = [TiUtils textAlignmentValue:align];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this actually does change behavior here. If the user specified null/undefined/ or a bad int value, we'd default to NSTextAlignmentNatural, while we can no longer specify any value to get that setting now. We may want to expose a "natural" constant value as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I'd rather change this constant to NSTextAlignmentNatural though. They look the same, but NSTextAlignmentNatural is the native way to go and default since iOS 6.

UIControlContentHorizontalAlignment horizontalAlignment = UIControlContentHorizontalAlignmentCenter;

if ([align isKindOfClass:[NSString class]]) {
if ([align isEqualToString:@"left"])
{
alignment = NSTextAlignmentLeft;
}
else if ([align isEqualToString:@"right"])
{
alignment = NSTextAlignmentRight;
}
else if ([align isEqualToString:@"center"])
{
alignment = NSTextAlignmentCenter;
}
} else {
alignment = (NSTextAlignment)[TiUtils intValue:align def:(int)NSTextAlignmentNatural];
}

UIEdgeInsets inset = [button contentEdgeInsets];
switch (alignment) {
case NSTextAlignmentLeft:
Expand Down Expand Up @@ -472,4 +455,4 @@ -(CGFloat)contentHeightForWidth:(CGFloat)value

@end

#endif
#endif
6 changes: 5 additions & 1 deletion iphone/Classes/TiUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ +(TiScriptError*) scriptErrorValue:(id)value;

+(NSTextAlignment)textAlignmentValue:(id)alignment
{
NSTextAlignment align = NSTextAlignmentLeft;
NSTextAlignment align = NSTextAlignmentNatural; // Default for iOS 6+

if ([alignment isKindOfClass:[NSString class]])
{
Expand All @@ -1367,6 +1367,10 @@ +(NSTextAlignment)textAlignmentValue:(id)alignment
{
align = NSTextAlignmentRight;
}
else if ([alignment isEqualToString:@"justify"])
{
align = NSTextAlignmentJustified;
}
}
else if ([alignment isKindOfClass:[NSNumber class]])
{
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/UIModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_LEFT;
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_CENTER;
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_RIGHT;
@property(nonatomic,readonly) NSNumber *TEXT_ALIGNMENT_JUSTIFY;

@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_WORD_WRAP;
@property(nonatomic,readonly) NSNumber *TEXT_ELLIPSIZE_TRUNCATE_CHAR_WRAP;
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/UIModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ -(TiUIActivityIndicatorStyleProxy*)ActivityIndicatorStyle
MAKE_SYSTEM_PROP(TEXT_ALIGNMENT_LEFT,NSTextAlignmentLeft);
MAKE_SYSTEM_PROP(TEXT_ALIGNMENT_CENTER,NSTextAlignmentCenter);
MAKE_SYSTEM_PROP(TEXT_ALIGNMENT_RIGHT,NSTextAlignmentRight);
MAKE_SYSTEM_PROP(TEXT_ALIGNMENT_JUSTIFY,NSTextAlignmentJustified);

MAKE_SYSTEM_PROP(RETURNKEY_DEFAULT,UIReturnKeyDefault);
MAKE_SYSTEM_PROP(RETURNKEY_GO,UIReturnKeyGo);
Expand Down