Skip to content

Commit

Permalink
Merge pull request #5664 from vishalduggal/timob-15450
Browse files Browse the repository at this point in the history
[TIMOB-15450] iOS: More customizations for the tabGroup
  • Loading branch information
srahim committed May 12, 2014
2 parents cb65dc3 + 51ae3ce commit 941c4ce
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 25 deletions.
25 changes: 25 additions & 0 deletions apidoc/Titanium/UI/TabGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,31 @@ properties:
type: String
platforms: [iphone, ipad]

- name: translucent
summary: Boolean value indicating if the nav bar (typically for the **More** tab), is translucent.
platforms: [iphone, ipad]
default: true on iOS7 and above, false otherwise.
type: Boolean
since: "3.3.0"

- name: titleAttributes
summary: Title text attributes of the window to be applied on the **More** tab.
description: |
Use this property to specify the color, font and shadow attributes of the title.
since: "3.3.0"
platforms: [iphone, ipad]
type: titleAttributesParams

- name: navTintColor
summary: The tintColor to apply to the navigation bar (typically for the **More** tab). This property is applicable on iOS 7 and greater.
description: |
This property is a direct correspondant of the tintColor property of NavigationBar on iOS.
type: [String]
since: "3.3.0"
default: null
osver: {ios: {min: "7.0"}}
platforms: [iphone,ipad]

- name: editButtonTitle
summary: Title for the edit button on the **More** tab.
type: String
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUITabGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
NSString* editTitle;

TiColor *barColor;
TiColor *navTintColor;
NSMutableDictionary *theAttributes;
}

-(UITabBarController*)tabController;
Expand Down
102 changes: 94 additions & 8 deletions iphone/Classes/TiUITabGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ -(void)dealloc
{
RELEASE_TO_NIL(controller);
RELEASE_TO_NIL(focusedTabProxy);
RELEASE_TO_NIL(barColor);
RELEASE_TO_NIL(navTintColor);
RELEASE_TO_NIL(theAttributes)
[super dealloc];
}

Expand All @@ -30,7 +33,6 @@ -(UITabBarController*)tabController
controller.delegate = self;
controller.moreNavigationController.delegate = self;
[TiUtils configureController:controller withObject:self.proxy];
[TiUtils configureController:controller.moreNavigationController withObject:self.proxy];
}
return controller;
}
Expand Down Expand Up @@ -138,12 +140,35 @@ - (void)handleDidShowTab:(TiUITabProxy *)newFocus

-(void)updateMoreBar:(UINavigationController *)moreController
{
if ([[moreController viewControllers] count] != 1)
{
return;
}

[TiUtils applyColor:barColor toNavigationController:moreController];
UIColor * theColor = [TiUtils barColorForColor:barColor];
UIBarStyle navBarStyle = [TiUtils barStyleForColor:barColor];
UIColor * nTintColor = [navTintColor color];
BOOL translucent = [TiUtils boolValue:[self.proxy valueForUndefinedKey:@"translucent"] def:[TiUtils isIOS7OrGreater]];

//Update the UINavigationBar appearance.
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class], nil] setBarStyle:navBarStyle];
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class], nil] setTitleTextAttributes:theAttributes];
if ([TiUtils isIOS7OrGreater]) {
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class], nil] setBarTintColor:theColor];
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class], nil] setTintColor:nTintColor];
} else {
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class], nil] setTintColor:theColor];
}

if ([[moreController viewControllers] count] != 1) {
return;
}
//Update the actual nav bar here in case the windows changed the stuff.
UINavigationBar * navBar = [moreController navigationBar];
[navBar setBarStyle:navBarStyle];
[navBar setTitleTextAttributes:theAttributes];
[navBar setTranslucent:translucent];
if([TiUtils isIOS7OrGreater]) {
[navBar performSelector:@selector(setBarTintColor:) withObject:theColor];
[navBar setTintColor:nTintColor];
} else {
[navBar setTintColor:theColor];
}
}

-(void)setEditButton:(UINavigationController*)moreController
Expand Down Expand Up @@ -227,6 +252,10 @@ - (void)navigationController:(UINavigationController *)navigationController didS
if (focusedTabProxy != nil) {
[self handleDidShowTab:nil];
}
//Ensure that the moreController has only top edge extended
if ([TiUtils isIOS7OrGreater]) {
[TiUtils configureController:viewController withObject:[NSDictionary dictionaryWithObject:NUMINT(1) forKey:@"extendEdges"]];
}
return;
}

Expand Down Expand Up @@ -310,7 +339,6 @@ - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewCon
[self handleDidShowTab:(TiUITabProxy *)[(UINavigationController *)viewController delegate]];
}


- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
if (changed) {
Expand Down Expand Up @@ -395,14 +423,72 @@ -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOr
[controller didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

-(void)setTranslucent_:(id)value
{
[[self proxy] replaceValue:value forKey:@"translucent" notification:NO];
[self updateMoreBar:[controller moreNavigationController]];
}

-(void)setBarColor_:(id)value
{
[barColor release];
barColor = [[TiUtils colorValue:value] retain];
[self.proxy replaceValue:value forKey:@"barColor" notification:NO];
[self updateMoreBar:[controller moreNavigationController]];
}

-(void)setTitleAttributes_:(id)args
{
ENSURE_SINGLE_ARG_OR_NIL(args, NSDictionary);
[self.proxy replaceValue:args forKey:@"titleAttributes" notification:NO];
RELEASE_TO_NIL(theAttributes)
if (args != nil) {
theAttributes = [[NSMutableDictionary dictionary] retain];
if ([args objectForKey:@"color"] != nil) {
UIColor* theColor = [[TiUtils colorValue:@"color" properties:args] _color];
if (theColor != nil) {
[theAttributes setObject:theColor forKey:([TiUtils isIOS7OrGreater] ? NSForegroundColorAttributeName : UITextAttributeTextColor)];
}
}
if ([args objectForKey:@"shadow"] != nil) {
NSShadow* shadow = [TiUtils shadowValue:[args objectForKey:@"shadow"]];
if (shadow != nil) {
if ([TiUtils isIOS7OrGreater]) {
[theAttributes setObject:shadow forKey:NSShadowAttributeName];
} else {
if (shadow.shadowColor != nil) {
[theAttributes setObject:shadow.shadowColor forKey:UITextAttributeTextShadowColor];
}
NSValue *theValue = [NSValue valueWithUIOffset:UIOffsetMake(shadow.shadowOffset.width, shadow.shadowOffset.height)];
[theAttributes setObject:theValue forKey:UITextAttributeTextShadowOffset];
}
}
}

if ([args objectForKey:@"font"] != nil) {
UIFont* theFont = [[TiUtils fontValue:[args objectForKey:@"font"] def:nil] font];
if (theFont != nil) {
[theAttributes setObject:theFont forKey:([TiUtils isIOS7OrGreater] ? NSFontAttributeName : UITextAttributeFont)];
}
}

if ([theAttributes count] == 0) {
RELEASE_TO_NIL(theAttributes)
}
}
[self updateMoreBar:[controller moreNavigationController]];
}


-(void)setNavTintColor_:(id)value
{
[navTintColor release];
navTintColor = [[TiUtils colorValue:value] retain];
[self.proxy replaceValue:value forKey:@"navTintColor" notification:NO];
[self updateMoreBar:[controller moreNavigationController]];
}


-(void)setActiveTab_:(id)value
{
UIViewController *active = nil;
Expand Down
44 changes: 27 additions & 17 deletions iphone/Classes/TiUIWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,25 @@ -(void)hideNavBar:(NSArray*)args

-(void)setNavTintColor:(id)colorString
{
if (![TiUtils isIOS7OrGreater]) {
[self replaceValue:[TiUtils stringValue:colorString] forKey:@"navTintColor" notification:NO];
return;
}
ENSURE_UI_THREAD(setNavTintColor,colorString);
NSString *color = [TiUtils stringValue:colorString];
[self replaceValue:color forKey:@"navTintColor" notification:NO];
if (controller!=nil) {
TiColor * newColor = [TiUtils colorValue:color];
UINavigationBar * navBar = [[controller navigationController] navigationBar];
[navBar setTintColor:[newColor color]];
[self performSelector:@selector(refreshBackButton) withObject:nil afterDelay:0.0];
if (![TiUtils isIOS7OrGreater]) {
return;
}

TiThreadPerformOnMainThread(^{
if(controller != nil) {
TiColor * newColor = [TiUtils colorValue:color];
if (newColor == nil) {
//Get from TabGroup
newColor = [TiUtils colorValue:[[self tabGroup] valueForKey:@"navTintColor"]];
}
UINavigationBar * navBar = [[controller navigationController] navigationBar];
[navBar setTintColor:[newColor color]];
[self performSelector:@selector(refreshBackButton) withObject:nil afterDelay:0.0];
}

}, NO);
}

-(void)setBarColor:(id)colorString
Expand Down Expand Up @@ -388,6 +394,10 @@ -(void)setTitleAttributes:(id)args
ENSURE_UI_THREAD(setTitleAttributes,args);
ENSURE_SINGLE_ARG_OR_NIL(args, NSDictionary);
[self replaceValue:args forKey:@"titleAttributes" notification:NO];

if (args == nil) {
args = [[self tabGroup] valueForUndefinedKey:@"titleAttributes"];
}

NSMutableDictionary* theAttributes = nil;
if (args != nil) {
Expand Down Expand Up @@ -821,13 +831,13 @@ -(void)setTitleImage:(id)image

-(void)setTitle:(NSString*)title_
{
ENSURE_UI_THREAD(setTitle,title_);
NSString *title = [TiUtils stringValue:title_];
[self replaceValue:title forKey:@"title" notification:NO];
if (controller!=nil && [controller navigationController] != nil)
{
controller.navigationItem.title = title;
}
NSString *title = [TiUtils stringValue:title_];
[self replaceValue:title forKey:@"title" notification:NO];
TiThreadPerformOnMainThread(^{
if (shouldUpdateNavBar && controller != nil && [controller navigationController] != nil) {
controller.navigationItem.title = title;
}
}, NO);
}

-(void)setTitlePrompt:(NSString*)title_
Expand Down

0 comments on commit 941c4ce

Please sign in to comment.