Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-10802] NavGroup - Cleanup windowStack Management #2909

Merged
merged 6 commits into from
Sep 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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