[ios] properly show attribution in modal hierarchies (#8837)

fixes #8782
This commit is contained in:
Justin R. Miller
2017-05-02 14:07:57 -07:00
committed by Jordan Kiley
parent 5c52401d55
commit e5ae80ca96
4 changed files with 53 additions and 10 deletions

View File

@@ -42,12 +42,13 @@
#import "NSBundle+MGLAdditions.h"
#import "NSDate+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
#import "NSProcessInfo+MGLAdditions.h"
#import "NSException+MGLAdditions.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSProcessInfo+MGLAdditions.h"
#import "NSString+MGLAdditions.h"
#import "NSURL+MGLAdditions.h"
#import "UIImage+MGLAdditions.h"
#import "NSPredicate+MGLAdditions.h"
#import "UIViewController+MGLAdditions.h"
#import "MGLFaux3DUserLocationAnnotationView.h"
#import "MGLUserLocationAnnotationView.h"
@@ -1946,10 +1947,7 @@ public:
attributionController.popoverPresentationController.sourceView = self;
attributionController.popoverPresentationController.sourceRect = self.attributionButton.frame;
UIViewController *viewController = self.window.rootViewController;
if ([viewController isKindOfClass:[UINavigationController class]]) {
viewController = [(UINavigationController *)viewController viewControllers].firstObject;
}
UIViewController *viewController = [self.window.rootViewController mgl_topMostViewController];
[viewController presentViewController:attributionController
animated:YES
completion:NULL];

View File

@@ -0,0 +1,11 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (MGLAdditions)
@property (readonly) UIViewController *mgl_topMostViewController;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,22 @@
#import "UIViewController+MGLAdditions.h"
@implementation UIViewController (MGLAdditions)
- (UIViewController *)mgl_topMostViewController
{
if ([self isKindOfClass:[UINavigationController class]])
{
return [[(UINavigationController *)self visibleViewController] mgl_topMostViewController];
}
else if ([self isKindOfClass:[UITabBarController class]])
{
return [[(UITabBarController *)self selectedViewController] mgl_topMostViewController];
}
else if (self.presentedViewController)
{
return [self.presentedViewController mgl_topMostViewController];
}
return self;
}
@end