Browse Source

Fix dark mode for navbar

Signed-off-by: Philippe Weidmann <philippe.weidmann@infomaniak.com>
Philippe Weidmann 4 years ago
parent
commit
9cc992005c
2 changed files with 20 additions and 6 deletions
  1. 10 4
      iOSClient/Main/AppDelegate+Swift.swift
  2. 10 2
      iOSClient/Main/CCMain+Swift.swift

+ 10 - 4
iOSClient/Main/AppDelegate+Swift.swift

@@ -14,24 +14,30 @@ extension AppDelegate {
         if #available(iOS 13.0, *) {
             var navBarAppearance = UINavigationBarAppearance()
             navBarAppearance.configureWithOpaqueBackground()
+            
+            navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+            navBarAppearance.backgroundColor = NCBrandColor.sharedInstance.backgroundView
+            
             navBarAppearance.shadowColor = .clear
             navBarAppearance.shadowImage = UIImage()
+            
             viewController.navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
 
             navBarAppearance = UINavigationBarAppearance()
             navBarAppearance.configureWithOpaqueBackground()
-            navBarAppearance.backgroundColor = .systemBackground
+            
+            navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+            navBarAppearance.backgroundColor = NCBrandColor.sharedInstance.backgroundView
 
             viewController.navigationController?.navigationBar.standardAppearance = navBarAppearance
         } else {
             viewController.navigationController?.navigationBar.barStyle = .default
             viewController.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.backgroundView
             viewController.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:NCBrandColor.sharedInstance.textView]
-            if #available(iOS 11.0, *) {
-                viewController.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor:NCBrandColor.sharedInstance.textView]
-            }
+            viewController.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor:NCBrandColor.sharedInstance.textView]
         }
         viewController.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brand
+        viewController.navigationController?.navigationBar.setNeedsLayout()
     }
     
 }

+ 10 - 2
iOSClient/Main/CCMain+Swift.swift

@@ -15,11 +15,15 @@ extension CCMain {
             if #available(iOS 13.0, *) {
                 let navBarAppearance = UINavigationBarAppearance()
                 navBarAppearance.configureWithOpaqueBackground()
-                navBarAppearance.backgroundColor = .systemBackground
+                navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                navBarAppearance.backgroundColor = NCBrandColor.sharedInstance.backgroundView
                 self.navigationController?.navigationBar.standardAppearance = navBarAppearance
                 self.navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
             } else {
                 self.navigationController?.navigationBar.barStyle = .default
+                self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
                 self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.backgroundView
                 self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brand
                 self.navigationController?.navigationBar.shadowImage = nil
@@ -31,13 +35,17 @@ extension CCMain {
             if #available(iOS 13.0, *) {
                 let navBarAppearance = UINavigationBarAppearance()
                 navBarAppearance.configureWithOpaqueBackground()
-                navBarAppearance.backgroundColor = .systemBackground
+                navBarAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                navBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                navBarAppearance.backgroundColor = NCBrandColor.sharedInstance.backgroundView
                 navBarAppearance.shadowColor = .clear
                 navBarAppearance.shadowImage = UIImage()
                 self.navigationController?.navigationBar.standardAppearance = navBarAppearance
                 self.navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
             } else {
                 self.navigationController?.navigationBar.barStyle = .default
+                self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
+                self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor : NCBrandColor.sharedInstance.textView]
                 self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.backgroundView
                 self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brand
                 self.navigationController?.navigationBar.shadowImage = UIImage()