Skip to content

Commit

Permalink
Handle root being a navigation controller
Browse files Browse the repository at this point in the history
The automatic screen event code did not handle the case where the root view controller was a UINavigationController.

The code would often just report the top level Nav as it would not always have a presented VC.

This proposed change checks for a top level nav controller, and steps into either it's presented controller or it's last in the list of view controllers as appropriate.

Move into the recursive func

Refactor the navigation controller handling into the recursive function to handle (hopefully) any combination of nav/view/nav/nav/view whatnot =)

Code Style Matching

Fixed up some coding style to match the prevailing things ('*' hugging, == ordering)

patch
  • Loading branch information
voidref authored and f2prateek committed Jun 30, 2016
1 parent 7306f8d commit 66fdd8c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Pod/Classes/Internal/UIViewController+SEGScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ + (UIViewController *)seg_topViewController

+ (UIViewController *)seg_topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
UIViewController *presentedViewController = rootViewController.presentedViewController;
if (presentedViewController != nil) {
return [self seg_topViewController:presentedViewController];
}

if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UIViewController *lastViewController = [[(UINavigationController *)rootViewController viewControllers] lastObject];
return [self seg_topViewController:lastViewController];
}

UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [self seg_topViewController:presentedViewController];
return rootViewController;
}

- (void)seg_viewDidAppear:(BOOL)animated
{
UIViewController *top = [UIViewController seg_topViewController];
if (!top) {
SEGLog(@"Could not infer screen.");
return;
}

Expand Down

0 comments on commit 66fdd8c

Please sign in to comment.