[themes] [ios] Refactored acquisition of top view controller.
This commit is contained in:
parent
7f4370fdb2
commit
fac8c7e18b
5 changed files with 23 additions and 18 deletions
6
iphone/Maps/Categories/UIViewController+Hierarchy.swift
Normal file
6
iphone/Maps/Categories/UIViewController+Hierarchy.swift
Normal file
|
@ -0,0 +1,6 @@
|
|||
extension UIViewController {
|
||||
static func topViewController() -> UIViewController {
|
||||
let window = UIApplication.shared.delegate!.window!!
|
||||
return (window.rootViewController as! UINavigationController).topViewController!
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
#import "MWMSearchNoResultsAlert.h"
|
||||
#import "MapViewController.h"
|
||||
#import "MapsAppDelegate.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController";
|
||||
|
||||
|
@ -21,7 +22,7 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
|
|||
|
||||
+ (nonnull MWMAlertViewController *)activeAlertController
|
||||
{
|
||||
UIViewController * tvc = topViewController();
|
||||
UIViewController * tvc = [UIViewController topViewController];
|
||||
ASSERT([tvc conformsToProtocol:@protocol(MWMController)], ());
|
||||
UIViewController<MWMController> * mwmController =
|
||||
static_cast<UIViewController<MWMController> *>(tvc);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import "MWMToast.h"
|
||||
#import "MWMCommon.h"
|
||||
#import "SwiftBridge.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -61,7 +62,7 @@ NSUInteger const kWordsPerSecond = 3;
|
|||
UIView * sv = self.rootView;
|
||||
[sv removeFromSuperview];
|
||||
|
||||
UIViewController * tvc = topViewController();
|
||||
auto tvc = [UIViewController topViewController];
|
||||
UIView * ov = tvc.view;
|
||||
if (!tvc.navigationController.navigationBarHidden)
|
||||
ov = tvc.navigationController.navigationBar.superview;
|
||||
|
@ -116,7 +117,7 @@ NSUInteger const kWordsPerSecond = 3;
|
|||
{
|
||||
[self configLayout];
|
||||
|
||||
UIView * ov = topViewController().view;
|
||||
UIView * ov = [UIViewController topViewController].view;
|
||||
runAsyncOnMainQueue(^{
|
||||
[ov layoutIfNeeded];
|
||||
self.bottomOffset.priority = UILayoutPriorityFittingSizeLevel;
|
||||
|
@ -126,7 +127,7 @@ NSUInteger const kWordsPerSecond = 3;
|
|||
}
|
||||
completion:^(BOOL finished) {
|
||||
[self subscribe];
|
||||
[topViewController() setNeedsStatusBarAppearanceUpdate];
|
||||
[[UIViewController topViewController] setNeedsStatusBarAppearanceUpdate];
|
||||
[self scheduleHide];
|
||||
}];
|
||||
});
|
||||
|
@ -136,7 +137,7 @@ NSUInteger const kWordsPerSecond = 3;
|
|||
{
|
||||
[self unsubscribe];
|
||||
|
||||
UIView * ov = topViewController().view;
|
||||
UIView * ov = [UIViewController topViewController].view;
|
||||
[ov layoutIfNeeded];
|
||||
self.bottomOffset.priority = UILayoutPriorityDefaultHigh;
|
||||
[UIView animateWithDuration:kDefaultAnimationDuration
|
||||
|
@ -145,7 +146,7 @@ NSUInteger const kWordsPerSecond = 3;
|
|||
}
|
||||
completion:^(BOOL finished) {
|
||||
[self.rootView removeFromSuperview];
|
||||
[topViewController() setNeedsStatusBarAppearanceUpdate];
|
||||
[[UIViewController topViewController] setNeedsStatusBarAppearanceUpdate];
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
@ -72,17 +72,6 @@ static inline void runAsyncOnMainQueue(dispatch_block_t block)
|
|||
dispatch_async(dispatch_get_main_queue(), block);
|
||||
}
|
||||
|
||||
static inline UIViewController * topViewController()
|
||||
{
|
||||
UIWindow * window = UIApplication.sharedApplication.delegate.window;
|
||||
UIViewController * rootViewController = window.rootViewController;
|
||||
NSCAssert([rootViewController isKindOfClass:[UINavigationController class]],
|
||||
@"Invalid rootViewController class");
|
||||
UINavigationController * navigationController =
|
||||
static_cast<UINavigationController *>(rootViewController);
|
||||
return navigationController.topViewController;
|
||||
}
|
||||
|
||||
static inline void setStatusBarBackgroundColor(UIColor * color)
|
||||
{
|
||||
UIView * statusBar =
|
||||
|
|
|
@ -295,6 +295,9 @@
|
|||
349D1AE01E2E325C004A2006 /* MWMBottomMenuViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349D1ACD1E2E325B004A2006 /* MWMBottomMenuViewController.xib */; };
|
||||
349D1AE11E2E325C004A2006 /* MWMBottomMenuViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349D1ACD1E2E325B004A2006 /* MWMBottomMenuViewController.xib */; };
|
||||
349D1AE21E2E325C004A2006 /* MWMBottomMenuViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349D1ACD1E2E325B004A2006 /* MWMBottomMenuViewController.xib */; };
|
||||
349D1CE31E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */; };
|
||||
349D1CE41E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */; };
|
||||
349D1CE51E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */; };
|
||||
34AB39C11D2BD8310021857D /* MWMStopButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34AB39C01D2BD8310021857D /* MWMStopButton.mm */; };
|
||||
34AB39C21D2BD8310021857D /* MWMStopButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34AB39C01D2BD8310021857D /* MWMStopButton.mm */; };
|
||||
34ABA6161C2D185C00FE1BEC /* MWMAuthorizationOSMLoginViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34ABA6151C2D185B00FE1BEC /* MWMAuthorizationOSMLoginViewController.mm */; };
|
||||
|
@ -1592,6 +1595,7 @@
|
|||
349D1ACB1E2E325B004A2006 /* MWMBottomMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMBottomMenuViewController.h; sourceTree = "<group>"; };
|
||||
349D1ACC1E2E325B004A2006 /* MWMBottomMenuViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; path = MWMBottomMenuViewController.mm; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
349D1ACD1E2E325B004A2006 /* MWMBottomMenuViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMBottomMenuViewController.xib; sourceTree = "<group>"; };
|
||||
349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Hierarchy.swift"; sourceTree = "<group>"; };
|
||||
34AB39BF1D2BD8310021857D /* MWMStopButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMStopButton.h; sourceTree = "<group>"; };
|
||||
34AB39C01D2BD8310021857D /* MWMStopButton.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMStopButton.mm; sourceTree = "<group>"; };
|
||||
34ABA6141C2D185B00FE1BEC /* MWMAuthorizationOSMLoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMAuthorizationOSMLoginViewController.h; sourceTree = "<group>"; };
|
||||
|
@ -1656,8 +1660,8 @@
|
|||
34D3B04D1E38A20C004100F9 /* Bundle+Init.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Init.swift"; sourceTree = "<group>"; };
|
||||
34D4FA611E26572D003F53EF /* FirstLaunchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirstLaunchController.swift; sourceTree = "<group>"; };
|
||||
34D4FA651E265749003F53EF /* WhatsNewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhatsNewController.swift; sourceTree = "<group>"; };
|
||||
34F5E0D21E3F254800B1C415 /* UIView+Hierarchy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Hierarchy.swift"; sourceTree = "<group>"; };
|
||||
34ED29891E3BB9B40054D003 /* RoutePoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutePoint.swift; sourceTree = "<group>"; };
|
||||
34F5E0D21E3F254800B1C415 /* UIView+Hierarchy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Hierarchy.swift"; sourceTree = "<group>"; };
|
||||
34F5E0D61E3F334700B1C415 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
|
||||
34F5E0DA1E3F3ED300B1C415 /* MWMRoutePoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMRoutePoint.h; sourceTree = "<group>"; };
|
||||
34F5E0DC1E3F51AF00B1C415 /* MWMCoreRouterType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMCoreRouterType.h; sourceTree = "<group>"; };
|
||||
|
@ -2724,6 +2728,7 @@
|
|||
34F7422F1E0834F400AC1FD6 /* UIViewController+Navigation.h */,
|
||||
34F742301E0834F400AC1FD6 /* UIViewController+Navigation.mm */,
|
||||
34F5E0D21E3F254800B1C415 /* UIView+Hierarchy.swift */,
|
||||
349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */,
|
||||
);
|
||||
path = Categories;
|
||||
sourceTree = "<group>";
|
||||
|
@ -4777,6 +4782,7 @@
|
|||
F6E2FD701E097BA00083EBEC /* MWMMapDownloaderTableViewCell.mm in Sources */,
|
||||
F6E2FE4E1E097BA00083EBEC /* MWMActionBarButton.mm in Sources */,
|
||||
34BF0CC61C31304A00D097EB /* MWMAuthorizationCommon.mm in Sources */,
|
||||
349D1CE31E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */,
|
||||
340475521E081A4600C92850 /* MWMCustomFacebookEvents.mm in Sources */,
|
||||
F6E2FD761E097BA00083EBEC /* MWMMapDownloaderDataSource.mm in Sources */,
|
||||
F64F4B741B4A45FD0081A24A /* MWMDownloaderDialogHeader.mm in Sources */,
|
||||
|
@ -5036,6 +5042,7 @@
|
|||
F6E2FD711E097BA00083EBEC /* MWMMapDownloaderTableViewCell.mm in Sources */,
|
||||
F6E2FE4F1E097BA00083EBEC /* MWMActionBarButton.mm in Sources */,
|
||||
340475531E081A4600C92850 /* MWMCustomFacebookEvents.mm in Sources */,
|
||||
349D1CE41E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */,
|
||||
34BF0CC71C31304A00D097EB /* MWMAuthorizationCommon.mm in Sources */,
|
||||
F6E2FD771E097BA00083EBEC /* MWMMapDownloaderDataSource.mm in Sources */,
|
||||
6741A9E01BF340DE002C974C /* MWMDownloaderDialogHeader.mm in Sources */,
|
||||
|
@ -5295,6 +5302,7 @@
|
|||
849CF6D81DE842290024A8A5 /* MWMSegue.mm in Sources */,
|
||||
F6E2FD721E097BA00083EBEC /* MWMMapDownloaderTableViewCell.mm in Sources */,
|
||||
F6E2FE501E097BA00083EBEC /* MWMActionBarButton.mm in Sources */,
|
||||
349D1CE51E3F836900A878FD /* UIViewController+Hierarchy.swift in Sources */,
|
||||
849CF6DC1DE842290024A8A5 /* MWMRoutePreview.mm in Sources */,
|
||||
F6E2FD781E097BA00083EBEC /* MWMMapDownloaderDataSource.mm in Sources */,
|
||||
849CF6DE1DE842290024A8A5 /* MWMRoutePointLayout.mm in Sources */,
|
||||
|
|
Reference in a new issue