Skip to content

Commit

Permalink
Merge pull request #2909 from vishalduggal/timob-10802
Browse files Browse the repository at this point in the history
[TIMOB-10802] NavGroup - Cleanup windowStack Management
  • Loading branch information
Max Stepanov committed Sep 19, 2012
2 parents 93a50be + 7ef8ac4 commit 57e7494
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions iphone/Classes/TiUIiPhoneNavigationGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TiWindowProxy *root;
TiWindowProxy *visibleProxy;
TiWindowProxy *closingProxy;
NSMutableArray* closingProxyArray;
BOOL opening;
}

Expand Down
64 changes: 54 additions & 10 deletions iphone/Classes/TiUIiPhoneNavigationGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ -(void)setVisibleProxy:(TiWindowProxy *) newVisibleProxy
-(void)dealloc
{
RELEASE_TO_NIL(controller);
RELEASE_TO_NIL(closingProxyArray)
[self setVisibleProxy:nil];
//This is done this way so that proper methods are called as well.
[super dealloc];
Expand Down Expand Up @@ -101,6 +101,7 @@ -(void)close
RELEASE_TO_NIL(controller);
[visibleProxy autorelease];
visibleProxy = nil; // close/release handled by view removal
RELEASE_TO_NIL(closingProxyArray)
}
[self release];
}
Expand All @@ -114,16 +115,59 @@ -(void)open:(TiWindowProxy*)window withObject:(NSDictionary*)properties
[controller pushViewController:viewController animated:animated];
}

-(void)delayedClose:(id)unused
{
if ([closingProxyArray count] > 0) {
if ( closingProxy == nil) {
NSArray* args = [closingProxyArray objectAtIndex:0];
[self removeWindowFromControllerStack:[args objectAtIndex:0] withObject:[args objectAtIndex:1]];
[closingProxyArray removeObjectAtIndex:0];
}
else {
[self performSelector:@selector(delayedClose:) withObject:nil afterDelay:UINavigationControllerHideShowBarDuration];
}
}
}

-(void)close:(TiWindowProxy*)window withObject:(NSDictionary*)properties
{
UIViewController* windowController = [window controller];
NSMutableArray* newControllers = [NSMutableArray arrayWithArray:controller.viewControllers];
BOOL animated = [TiUtils boolValue:@"animated" properties:properties def:(windowController == [newControllers lastObject])];
[newControllers removeObject:windowController];
[closingProxy autorelease];
closingProxy = [window retain];
[controller setViewControllers:newControllers animated:animated];

//TIMOB-10802. If a window is being popped off the stack wait until the
//animation is complete before trying to pop another window
if ( (closingProxy != nil) || ([closingProxyArray count] >0) ) {
DebugLog(@"NavController is closing a proxy. Delaying this close call")
if (closingProxyArray == nil) {
closingProxyArray = [[NSMutableArray alloc] init];
}
[closingProxyArray addObject:[NSArray arrayWithObjects:window,properties,nil]];
[self performSelector:@selector(delayedClose:) withObject:nil afterDelay:UINavigationControllerHideShowBarDuration];
}
else {
[self removeWindowFromControllerStack:window withObject:properties];
}
}

-(void)removeWindowFromControllerStack:(TiWindowProxy*)window withObject:(NSDictionary*)properties
{
UIViewController* windowController = [window controller];
NSMutableArray* newControllers = [NSMutableArray arrayWithArray:controller.viewControllers];
BOOL lastObject = (windowController == [newControllers lastObject]);
BOOL animated = [TiUtils boolValue:@"animated" properties:properties def:lastObject];
//Ignore animated if the view being popped is not the top view controller.
if (!lastObject) {
animated = NO;
}
[newControllers removeObject:windowController];
[closingProxy autorelease];
closingProxy = [window retain];
[controller setViewControllers:newControllers animated:animated];

//TIMOB-10802.If it is not the top view controller, delegate methods will
//not be called. So call close on the proxy here.
if (!lastObject) {
[closingProxy close:nil];
[closingProxy release];
closingProxy = nil;
}
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Expand Down Expand Up @@ -154,7 +198,7 @@ - (void)navigationController:(UINavigationController *)navigationController didS
BOOL visibleProxyDidChange = NO;
if (newWindow!=visibleProxy)
{
if (visibleProxy != nil && visibleProxy!=root && opening==NO)
if (visibleProxy != nil && visibleProxy!=root && opening==NO && visibleProxy != closingProxy)
{
//TODO: This is an expedient fix, but NavGroup needs rewriting anyways
[(TiUIiPhoneNavigationGroupProxy*)[self proxy] close:[NSArray arrayWithObject:visibleProxy]];
Expand Down

0 comments on commit 57e7494

Please sign in to comment.