Skip to content

Commit

Permalink
Merge pull request #4607 from vishalduggal/timob-14936
Browse files Browse the repository at this point in the history
[TIMOB-14396] Tab icon/activeIcon Fixes
  • Loading branch information
srahim committed Aug 28, 2013
2 parents 7b23f41 + 54628e7 commit 0a218b5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
7 changes: 1 addition & 6 deletions iphone/Classes/TiUIButtonBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#import "TiUtils.h"
#import "Webcolor.h"

@protocol UIImageIOS7Support <NSObject>
@optional
- (UIImage *)imageWithRenderingMode:(NSInteger)renderingMode;
@end


@implementation TiUIButtonBar

- (id) init
Expand Down Expand Up @@ -188,6 +182,7 @@ -(void)setLabels_:(id)value
if (thisSegmentAccessibilityLabel != nil) {
thisSegmentImage.accessibilityLabel = thisSegmentAccessibilityLabel;
}
//CLEANUP CODE WHEN WE UPGRADE MINIMUM XCODE VERSION TO XCODE5
if ([thisSegmentImage respondsToSelector:@selector(imageWithRenderingMode:)]) {
thisSegmentImage = [(id<UIImageIOS7Support>)thisSegmentImage imageWithRenderingMode:1];//UIImageRenderingModeAlwaysOriginal;
}
Expand Down
9 changes: 9 additions & 0 deletions iphone/Classes/TiUITabGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ -(void)setTabsBackgroundColor_:(id)value
}
}

-(void)setTabsTintColor_:(id)value
{
if ([TiUtils isIOS7OrGreater]) {
TiColor* color = [TiUtils colorValue:value];
UITabBar* tabBar = [controller tabBar];
tabBar.tintColor = [color color];
}
}

-(void)setTabsBackgroundImage_:(id)value
{
controller.tabBar.backgroundImage = [self loadImage:value];
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUITabProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
BOOL systemTab;
BOOL transitionIsAnimating;
BOOL hasFocus;
BOOL iconOriginal;
BOOL activeIconOriginal;

id<TiOrientationController> parentOrientationController;
}
Expand Down
55 changes: 54 additions & 1 deletion iphone/Classes/TiUITabProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ -(void)_configure
[self replaceValue:nil forKey:@"title" notification:NO];
[self replaceValue:nil forKey:@"icon" notification:NO];
[self replaceValue:nil forKey:@"badge" notification:NO];
[self replaceValue:NUMBOOL(YES) forKey:@"iconIsMask" notification:NO];
[self replaceValue:NUMBOOL(YES) forKey:@"activeIconIsMask" notification:NO];
[super _configure];
}

Expand Down Expand Up @@ -425,7 +427,32 @@ -(void)updateTabBarItem

[rootController setTitle:title];
UITabBarItem *ourItem = nil;


BOOL imageIsMask = NO;

if ([TiUtils isIOS7OrGreater]) {

//CLEAN UP CODE WHEN WE UPGRADE MIN XCODE VERSION TO XCODE5
if (image != nil) {
if ([image respondsToSelector:@selector(imageWithRenderingMode:)]) {
NSInteger theMode = iconOriginal ? 1/*UIImageRenderingModeAlwaysOriginal*/ : 2/*UIImageRenderingModeAlwaysTemplate*/;
image = [(id<UIImageIOS7Support>)image imageWithRenderingMode:theMode];
}
}
if (activeImage != nil) {
if ([activeImage respondsToSelector:@selector(imageWithRenderingMode:)]) {
NSInteger theMode = activeIconOriginal ? 1/*UIImageRenderingModeAlwaysOriginal*/ : 2/*UIImageRenderingModeAlwaysTemplate*/;
activeImage = [(id<UIImageIOS7Support>)activeImage imageWithRenderingMode:theMode];
}
}

systemTab = NO;
ourItem = [[[UITabBarItem alloc] initWithTitle:title image:image selectedImage:activeImage] autorelease];
[ourItem setBadgeValue:badgeValue];
[rootController setTabBarItem:ourItem];
return;
}

if (!systemTab)
{
ourItem = [rootController tabBarItem];
Expand Down Expand Up @@ -480,6 +507,32 @@ -(void)setIcon:(id)icon
[self updateTabBarItem];
}

-(void)setIconIsMask:(id)value
{
if (![TiUtils isIOS7OrGreater]) {
return;
}
[self replaceValue:value forKey:@"iconIsMask" notification:NO];
BOOL newValue = ![TiUtils boolValue:value def:YES];
if (newValue != iconOriginal) {
iconOriginal = newValue;
[self updateTabBarItem];
}
}

-(void)setActiveIconIsMask:(id)value
{
if (![TiUtils isIOS7OrGreater]) {
return;
}
[self replaceValue:value forKey:@"activeIconIsMask" notification:NO];
BOOL newValue = ![TiUtils boolValue:value def:YES];
if (newValue != activeIconOriginal) {
activeIconOriginal = newValue;
[self updateTabBarItem];
}
}

-(void)setActiveIcon:(id)icon
{
if (![UITabBarItem instancesRespondToSelector:
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/TiUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ typedef enum
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets; // Defaults to NO
@end

@protocol UIImageIOS7Support <NSObject>
@optional
- (UIImage *)imageWithRenderingMode:(NSInteger)renderingMode;
@end

/**
Utilities class.
Expand Down

0 comments on commit 0a218b5

Please sign in to comment.