Skip to content

Commit

Permalink
[TIMOB-8613] Resize titleControl on rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalduggal committed Apr 30, 2012
1 parent 50b81e1 commit bc452e2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
13 changes: 13 additions & 0 deletions iphone/Classes/TiUIWindow.m
Expand Up @@ -5,6 +5,7 @@
* Please see the LICENSE included with this distribution for details.
*/
#import "TiUIWindow.h"
#import "TiUIWindowProxy.h"

@implementation TiUIWindow

Expand All @@ -27,5 +28,17 @@ -(UIView *)gradientWrapperView
return gradientWrapperView;
}

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
[super frameSizeChanged:frame bounds:bounds];
//If we have a titleControl it needs to be resized for new navbar bounds
id titleControlProxy = [[self proxy] valueForKey:@"titleControl"];
if ([titleControlProxy isKindOfClass:[TiViewProxy class]]) {
//Need the delay so that we get the right navbar bounds
[(TiUIWindowProxy*)[self proxy] performSelector:@selector(_updateTitleView) withObject:nil afterDelay:[[UIApplication sharedApplication] statusBarOrientationAnimationDuration] ];
}
}


@end

1 change: 1 addition & 0 deletions iphone/Classes/TiUIWindowProxy.h
Expand Up @@ -26,6 +26,7 @@
}

-(void)_refreshBackButton;
-(void)_updateTitleView;
-(void)boot:(BOOL)timeout args:(id)args;

@end
Expand Down
53 changes: 38 additions & 15 deletions iphone/Classes/TiUIWindowProxy.m
Expand Up @@ -521,6 +521,15 @@ -(void)setBackButtonTitleImage:(id)proxy
}
}

-(void)_updateTitleView
{
//Called from the view when the screen rotates.
//Resize titleControl based on navbar bounds
TiThreadPerformOnMainThread(^{
[self updateTitleView];
}, NO);
}

-(void)updateTitleView
{
UIView * newTitleView = nil;
Expand All @@ -529,24 +538,38 @@ -(void)updateTitleView
return; // No need to update the title if not in a nav controller
}

UINavigationItem * ourNavItem = [controller navigationItem];

TiViewProxy * titleControl = [self valueForKey:@"titleControl"];

UIView * oldView = [ourNavItem titleView];
if ([oldView isKindOfClass:[TiUIView class]])
{
TiViewProxy * oldProxy = (TiViewProxy *)[(TiUIView *)oldView proxy];
if (oldProxy == titleControl)
{
return; //No need to update?
}
[oldProxy removeBarButtonView];
}
UINavigationItem * ourNavItem = [controller navigationItem];
UINavigationBar * ourNB = [[controller navigationController] navigationBar];
CGRect barFrame = [ourNB bounds];
CGSize availableTitleSize = CGSizeZero;
availableTitleSize.width = barFrame.size.width - (2*TI_NAVBAR_BUTTON_WIDTH);
availableTitleSize.height = barFrame.size.height;

TiViewProxy * titleControl = [self valueForKey:@"titleControl"];

UIView * oldView = [ourNavItem titleView];
if ([oldView isKindOfClass:[TiUIView class]]) {
TiViewProxy * oldProxy = (TiViewProxy *)[(TiUIView *)oldView proxy];
if (oldProxy == titleControl) {
//relayout titleControl
CGRect barBounds;
barBounds.origin = CGPointZero;
barBounds.size = SizeConstraintViewWithSizeAddingResizing(titleControl.layoutProperties, titleControl, availableTitleSize, NULL);

[TiUtils setView:oldView positionRect:barBounds];
[oldView setAutoresizingMask:UIViewAutoresizingNone];

//layout the titleControl children
[titleControl layoutChildren:NO];

return;
}
[oldProxy removeBarButtonView];
}

if ([titleControl isKindOfClass:[TiViewProxy class]])
{
newTitleView = [titleControl barButtonViewForSize:[TiUtils navBarTitleViewSize]];
newTitleView = [titleControl barButtonViewForSize:availableTitleSize];
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiViewProxy.m
Expand Up @@ -893,7 +893,7 @@ - (TiUIView *)barButtonViewForSize:(CGSize)bounds
//Ensure all the child views are laid out as well
[self windowWillOpen];
[self setParentVisible:YES];
[self layoutChildren:NO];
[self willShow];

return barButtonView;
}
Expand Down

0 comments on commit bc452e2

Please sign in to comment.