Skip to content

Commit

Permalink
[TIMOB-18515] Support icon insets in Ti.UI.Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Nov 27, 2015
1 parent a6d7b61 commit e377183
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
33 changes: 33 additions & 0 deletions apidoc/Titanium/UI/Tab.yml
Expand Up @@ -220,6 +220,16 @@ properties:
otherwise.
type: String

- name: iconInsets
summary: The icon inset or outset for each edge.
description: |
Use this property for example to center an icon without providing a title. To do that, set the
insets to `{top:6, bottom:-6, right:0, left:0}`.
since: "5.2.0"
default: All insets are zero.
type: TabIconInsets
platforms: [iphone,ipad]

- name: iconIsMask
summary: Defines if the icon property of the tab must be used as a mask. This property is applicable on iOS 7 and greater.
description: |
Expand Down Expand Up @@ -381,3 +391,26 @@ examples:
</Tab>
</TabGroup>
</Alloy>
---
name: TabIconInsets
summary: Dictionary to specify edge insets for <Titanium.UI.Tab.iconInsets>.
since: "5.2.0"
platforms: [iphone, ipad]
properties:
- name: top
summary: Top inset.
type: Number

- name: left
summary: Left inset.
type: Number

- name: right
summary: Right inset.
type: Number

- name: bottom
summary: Bottom inset.
type: Number

1 change: 1 addition & 0 deletions iphone/Classes/TiUITabProxy.h
Expand Up @@ -43,6 +43,7 @@
-(void)setIcon:(id)title;
-(void)setBadge:(id)title;
-(void)setActive:(id)value;
-(void)setIconInsets:(id)args;

- (void)handleWillBlur;
- (void)handleDidBlur:(NSDictionary *)event;
Expand Down
17 changes: 17 additions & 0 deletions iphone/Classes/TiUITabProxy.m
Expand Up @@ -217,6 +217,7 @@ -(UINavigationController*)controller
[self setTitle:[self valueForKey:@"title"]];
[self setIcon:[self valueForKey:@"icon"]];
[self setBadge:[self valueForKey:@"badge"]];
[self setIconInsets:[self valueForKey:@"iconInsets"]];
controllerStack = [[NSMutableArray alloc] init];
[controllerStack addObject:[self rootController]];
[controller.interactivePopGestureRecognizer addTarget:self action:@selector(popGestureStateHandler:)];
Expand Down Expand Up @@ -486,6 +487,7 @@ -(void)updateTabBarItem

UIViewController* rootController = [rootWindow hostingController];
id badgeValue = [TiUtils stringValue:[self valueForKey:@"badge"]];
id iconInsets = [self valueForKey:@"iconInsets"];
id icon = [self valueForKey:@"icon"];

if ([icon isKindOfClass:[NSNumber class]])
Expand Down Expand Up @@ -555,6 +557,13 @@ -(void)updateTabBarItem
if (activeTitleColor != nil) {
[ourItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[activeTitleColor color], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
}

if (iconInsets != nil) {
if(UIEdgeInsetsEqualToEdgeInsets([TiUtils contentInsets:iconInsets], [ourItem imageInsets]) == NO) {
[ourItem setImageInsets:[TiUtils contentInsets:iconInsets]];
}
}

[ourItem setBadgeValue:badgeValue];
[rootController setTabBarItem:ourItem];
}
Expand Down Expand Up @@ -591,6 +600,14 @@ -(void)setIcon:(id)icon
[self updateTabBarItem];
}

-(void)setIconInsets:(id)args
{
ENSURE_SINGLE_ARG(args, NSDictionary);
[self replaceValue:args forKey:@"iconInsets" notification:NO];

[self updateTabBarItem];
}

-(void)setIconIsMask:(id)value
{
[self replaceValue:value forKey:@"iconIsMask" notification:NO];
Expand Down

1 comment on commit e377183

@Topener
Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

Please sign in to comment.