-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fixes #8782: properly show attribution in modal hierarchies #8837
Conversation
platform/ios/src/MGLMapView.mm
Outdated
} | ||
viewController = [UIViewController getTopViewControllerFrom:viewController]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be conditional or always reassign line:1952?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's always if it's indeed a navigation controller, since a navigation controller with out any view controllers doesn't make any sense. Or am I misunderstanding you @frederoni?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nvm, I was unable to parse this. It looks good. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be wrong but it seems like you can remove the check for topViewController
so maybe this can now be:
UIViewController *viewController = self.window.rootViewController;
[[UIViewController getTopViewControllerFrom:viewController] presentViewController:attributionController
animated:YES
completion:NULL];
The category seems like it'll work out the visibleViewController
(modal or otherwise).
If that works and depending on what you decide to do about https://github.com/mapbox/mapbox-gl-native/pull/8837/files#r113819069, maybe this could end up like:
[[self.window.rootViewController topMostViewController] presentViewController:attributionController
animated:YES
completion:NULL];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@interface UIViewController (MGLAdditions) | ||
|
||
+ (UIViewController *)getTopViewControllerFrom:(UIViewController *)viewController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Prefixed method names in categories on framework classes.
Btw, do we need the viewController arg when we have access to self?
+[UIViewController(MGLAdditions) topViewController]
would conflict with -[UINavigationViewController topViewController]
but how about +[UIViewController(MGLAdditions) mgl_topMostViewController]
?
-edited-
Just noticed 🙈
and this can indeed be a class method since it doesn't depend on any state.
However, get
in method names are only used when returning objects or values indirectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point re: get
. Will fix. This came from the user's suggestion. @jmkiley and I discussed this method name a bit and figured we'd get some more input first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@implementation UIViewController (MGLAdditions) | ||
|
||
+ (UIViewController *)getTopViewControllerFrom:(UIViewController *)viewController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can indeed be a class method since it doesn't depend on any state
That’s true as far as the current implementation goes. However, it would be possible to express this method in a different way, so that a UIViewController knows how to return its topmost containing view controller: -topmostViewController
or perhaps -rootViewController
.
In 4903db6 I get rid of the explicit inline check for
|
|
||
@interface UIViewController (MGLAdditions) | ||
|
||
+ (UIViewController *)mgl_topMostViewControllerInHierarchyWith:(UIViewController *)viewController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Objective-C, a selector piece (mgl_topMostViewControllerInHierarchyWith:
) should always end with a noun, not a preposition.
This should be an instance method or read-only property named mgl_topmostViewController
. The return value is related to viewController
, not the UIViewController class as a whole. One might expect this class method, as written, to be a factory method for creating UIViewControllers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also prefer this to be an instance method to support being able to call it like in #8837 (comment). Otherwise I think this is 👍
@incanus just noticed that this is against |
f718d4d
to
4903db6
Compare
{ | ||
if ([viewController isKindOfClass:[UINavigationController class]]) | ||
{ | ||
return [self mgl_topMostViewControllerInHierarchyWith:[(UINavigationController *)viewController visibleViewController]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing in visibleViewController, call mgl_topMostViewController on visibleViewController. This method doesn't need to take any parameters.
824d269
to
8e17f5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for iterating – this looks great!
} | ||
else if ([self isKindOfClass:[UITabBarController class]]) | ||
{ | ||
return [[((UITabBarController *)self) selectedViewController] mgl_topMostViewController]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extraneous parentheses around self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just fixed.
Incorporates @cmoulton's fix from #8782, which we (@jmkiley and I) tested and debugged. We use three of the four code paths in the
UIViewController
category (all but tab view controller) in the process of finding the true top view controller from which to display the attribution sheet. Even with not using the tab bar controller path, we though it best to leave it in since it makes this method truly complete and generically useful.Despite being one method, we though it best to start a
UIViewController
category here as a template for future use and a way to keepMGLMapView.mm
trim, and this can indeed be a class method since it doesn't depend on any state.Also did a little category import re-alphabetization while in there 😉