Repository navigation
fixes #8782: properly show attribution in modal hierarchies - #8837
Conversation
| viewController = [(UINavigationController *)viewController viewControllers].firstObject; | ||
| viewController = ((UINavigationController *)viewController).topViewController; | ||
| } | ||
| viewController = [UIViewController getTopViewControllerFrom:viewController]; |
There was a problem hiding this comment.
Should this be conditional or always reassign line:1952?
There was a problem hiding this comment.
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.
Oh nvm, I was unable to parse this. It looks good. 👍
There was a problem hiding this comment.
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];|
|
||
| @interface UIViewController (MGLAdditions) | ||
|
|
||
| + (UIViewController *)getTopViewControllerFrom:(UIViewController *)viewController; |
There was a problem hiding this comment.
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.
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.
|
|
||
| @implementation UIViewController (MGLAdditions) | ||
|
|
||
| + (UIViewController *)getTopViewControllerFrom:(UIViewController *)viewController |
There was a problem hiding this comment.
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.
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.
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.
Instead of passing in visibleViewController, call mgl_topMostViewController on visibleViewController. This method doesn't need to take any parameters.
824d269 to
8e17f5a
Compare
1ec5
left a comment
There was a problem hiding this comment.
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.
Nit: extraneous parentheses around self.
Incorporates @cmoulton's fix from #8782, which we (@jmkiley and I) tested and debugged. We use three of the four code paths in the
UIViewControllercategory (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
UIViewControllercategory here as a template for future use and a way to keepMGLMapView.mmtrim, 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 😉