Просмотр исходного кода

Update status bar style in dark mode

This commit updates the status bar style to match the current theme that is selected.
The rootViewController has been switched to a UITabBarController from a regular UIViewController.

(fixes #403)
Robert Gordon 6 лет назад
Родитель
Сommit
4f4e003381

+ 2 - 2
Sources/AppearanceManager.swift

@@ -46,7 +46,7 @@ class AppearanceManager: NSObject {
 
 //extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
 extension UINavigationController {
-    override open var childForStatusBarStyle: UIViewController? {
-        return self.topViewController
+    override open var preferredStatusBarStyle: UIStatusBarStyle {
+        return PresentationTheme.current.colors.statusBarStyle
     }
 }

+ 5 - 12
Sources/Coordinators/AppCoordinator.swift

@@ -18,17 +18,15 @@ class Services: NSObject {
 
 @objc class AppCoordinator: NSObject {
     private var childCoordinators: [NSObject] = []
-    private var viewController: UIViewController
     private var playerController: VLCPlayerDisplayController
     private var tabBarController: UITabBarController
     private var services = Services()
     private var migrationViewController = VLCMigrationViewController(nibName: String(describing: VLCMigrationViewController.self),
                                                                      bundle: nil)
 
-    @objc init(viewController: UIViewController) {
-        self.viewController = viewController
+    @objc init(tabBarController: UITabBarController) {
         self.playerController = VLCPlayerDisplayController(services: services)
-        self.tabBarController = UITabBarController()
+        self.tabBarController = tabBarController
         super.init()
         setupChildViewControllers()
 
@@ -39,19 +37,14 @@ class Services: NSObject {
     }
 
     private func setupChildViewControllers() {
-        viewController.addChild(tabBarController)
-        viewController.view.addSubview(tabBarController.view)
-        tabBarController.view.frame = viewController.view.frame
-        tabBarController.didMove(toParent: viewController)
-
-        viewController.addChild(playerController)
-        viewController.view.addSubview(playerController.view)
+        self.tabBarController.addChild(playerController)
+        self.tabBarController.view.addSubview(playerController.view)
         playerController.view.layoutMargins = UIEdgeInsets(top: 0,
                                                            left: 0,
                                                            bottom: tabBarController.tabBar.frame.size.height,
                                                            right: 0)
         playerController.realBottomAnchor = tabBarController.tabBar.topAnchor
-        playerController.didMove(toParent: viewController)
+        playerController.didMove(toParent: self.tabBarController)
     }
 
     @objc func start() {

+ 3 - 3
Sources/VLCAppDelegate.m

@@ -41,7 +41,7 @@
     BOOL _isComingFromHandoff;
     VLCKeychainCoordinator *_keychainCoordinator;
     AppCoordinator *appCoordinator;
-    UIViewController *rootViewController;
+    UITabBarController *rootViewController;
 }
 
 @end
@@ -87,7 +87,7 @@
 - (void)setup
 {
     void (^setupAppCoordinator)(void) = ^{
-        self->appCoordinator = [[AppCoordinator alloc] initWithViewController:self->rootViewController];
+        self->appCoordinator = [[AppCoordinator alloc] initWithTabBarController:self->rootViewController];
         [self->appCoordinator start];
     };
     [self validatePasscodeIfNeededWithCompletion:setupAppCoordinator];
@@ -114,7 +114,7 @@
     [VLCApperanceManager setupAppearanceWithTheme:PresentationTheme.current];
 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-    rootViewController = [UIViewController new];
+    rootViewController = [UITabBarController new];
     self.window.rootViewController = rootViewController;
     [self.window makeKeyAndVisible];
     [self setup];

+ 7 - 0
Sources/VLCTabBarCoordinator.swift

@@ -32,6 +32,7 @@ class VLCTabBarCoordinator: NSObject {
         tabBarController.tabBar.isTranslucent = false
         tabBarController.tabBar.backgroundColor = PresentationTheme.current.colors.tabBarColor
         tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
+        tabBarController.tabBar.itemPositioning = .fill
         tabBarController.viewControllers?.forEach {
             if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
                 navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
@@ -58,3 +59,9 @@ class VLCTabBarCoordinator: NSObject {
         tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
     }
 }
+
+extension UITabBarController {
+    open override var preferredStatusBarStyle: UIStatusBarStyle {
+        return PresentationTheme.current.colors.statusBarStyle
+    }
+}