Explorar el Código

VLCTabBarCoordinator: Handle system wide theme change

Closes #619
Soomin Lee hace 5 años
padre
commit
a1bec63fa5

+ 5 - 0
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -173,6 +173,11 @@ class MediaCategoryViewController: UICollectionViewController, UICollectionViewD
         collectionView?.backgroundColor = PresentationTheme.current.colors.background
         searchBar.backgroundColor = PresentationTheme.current.colors.background
         editController.view.backgroundColor = PresentationTheme.current.colors.background
+
+        if #available(iOS 13.0, *) {
+            navigationController?.navigationBar.standardAppearance = AppearanceManager.navigationbarAppearance()
+            navigationController?.navigationBar.scrollEdgeAppearance = AppearanceManager.navigationbarAppearance()
+        }
         setNeedsStatusBarAppearanceUpdate()
     }
 

+ 16 - 0
Sources/VLCTabBarCoordinator.swift

@@ -91,4 +91,20 @@ extension UITabBarController {
     open override var preferredStatusBarStyle: UIStatusBarStyle {
         return PresentationTheme.current.colors.statusBarStyle
     }
+
+    override open func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        super.traitCollectionDidChange(previousTraitCollection)
+        if #available(iOS 13.0, *) {
+            guard previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle else {
+                // Since traitCollectionDidChange is called in, for example rotations, we make sure that
+                // there was a userInterfaceStyle change.
+                return
+            }
+
+            let isSystemDarkTheme = traitCollection.userInterfaceStyle == .dark
+
+            UserDefaults.standard.set(isSystemDarkTheme, forKey: kVLCSettingAppTheme)
+            PresentationTheme.current = isSystemDarkTheme ? PresentationTheme.darkTheme : PresentationTheme.brightTheme
+        }
+    }
 }