Skip to content

Commit

Permalink
fix(ios): allow string-based "verticalAlign" in Ti.UI.Label (#12566)
Browse files Browse the repository at this point in the history
Fixes TIMOB-28391
  • Loading branch information
hansemannn committed Aug 17, 2021
1 parent 4d44a18 commit 9363c42
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/Button.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ properties:
type: [Number,String]
constants: Titanium.UI.TEXT_VERTICAL_ALIGNMENT_*
default: Titanium.UI.TEXT_VERTICAL_ALIGNMENT_CENTER
platforms: [android]
platforms: [android, iphone, ipad, macos]

examples:
- title: Simple Button Example
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/Label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ properties:
behavior when the property is undefined is to center the text vertically.
type: [Number,String]
constants: Titanium.UI.TEXT_VERTICAL_ALIGNMENT_*
default: undefined on Android, iPhone and iPad.
default: undefined
since: { iphone: "3.0.0", ipad: "3.0.0", android: "3.0.0" }

events:
Expand Down
19 changes: 18 additions & 1 deletion iphone/Classes/TiUILabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ - (BOOL)isHighlighted

- (void)setVerticalAlign_:(id)value
{
verticalAlign = [TiUtils intValue:value def:UIControlContentVerticalAlignmentFill];
verticalAlign = [self verticalAlignFromValue:value];
if (verticalAlign < UIControlContentVerticalAlignmentCenter || verticalAlign > UIControlContentVerticalAlignmentBottom) {
verticalAlign = UIControlContentVerticalAlignmentFill;
}
Expand Down Expand Up @@ -535,6 +535,23 @@ - (void)setShadowOffset_:(id)value
[[self label] setShadowOffset:size];
}

- (UIControlContentVerticalAlignment)verticalAlignFromValue:(id)value
{
if ([value isKindOfClass:[NSNumber class]]) {
return [TiUtils intValue:value def:UIControlContentVerticalAlignmentFill];
} else if ([value isKindOfClass:[NSString class]]) {
if ([value isEqualToString:@"top"]) {
return UIControlContentVerticalAlignmentTop;
} else if ([value isEqualToString:@"bottom"]) {
return UIControlContentVerticalAlignmentBottom;
} else if ([value isEqualToString:@"center"]) {
return UIControlContentVerticalAlignmentCenter;
}
}

return UIControlContentVerticalAlignmentFill;
}

@end

#endif
1 change: 1 addition & 0 deletions tests/Resources/ti.ui.label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe('Titanium.UI.Label', function () {
text: 'this is some text',
verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_BOTTOM
});
// The internal structure is managed differently (string vs NSInteger enum)
if (utilities.isAndroid()) {
should(label.verticalAlign).be.a.String();
} else {
Expand Down

0 comments on commit 9363c42

Please sign in to comment.