Browse Source

Actionsheet: Add theme observer (fixes #301)

Mike JS. Choi 6 years ago
parent
commit
f44b4a9c93

+ 16 - 0
Sources/VLCActionSheet/VLCActionSheet.swift

@@ -171,6 +171,8 @@ class VLCActionSheet: UIViewController {
 
     override func viewDidLoad() {
         super.viewDidLoad()
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
 
         view.addSubview(backgroundView)
         view.addSubview(mainStackView)
@@ -230,6 +232,20 @@ class VLCActionSheet: UIViewController {
     @objc func setAction(closure action: @escaping (_ item: Any) -> Void) {
         self.action = action
     }
+    
+    @objc fileprivate func updateTheme() {
+        collectionView.backgroundColor = PresentationTheme.current.colors.background
+        headerView.backgroundColor = PresentationTheme.current.colors.background
+        headerView.title.textColor = PresentationTheme.current.colors.cellTextColor
+        bottomBackgroundView.backgroundColor = PresentationTheme.current.colors.background
+        for cell in collectionView.visibleCells {
+            if let cell = cell as? VLCActionSheetCell {
+                cell.backgroundColor = PresentationTheme.current.colors.background
+                cell.name.textColor = PresentationTheme.current.colors.cellTextColor
+            }
+        }
+        collectionView.layoutIfNeeded()
+    }
 }
 
 // MARK: UICollectionViewDelegateFlowLayout

+ 0 - 15
Sources/VLCRendererDiscovererManager.swift

@@ -39,7 +39,6 @@ class VLCRendererDiscovererManager: NSObject {
     @objc init(presentingViewController: UIViewController?) {
         self.presentingViewController = presentingViewController
         super.init()
-        NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
     }
 
     // Returns renderers of *all* discoverers
@@ -203,20 +202,6 @@ extension VLCRendererDiscovererManager: VLCRendererDiscovererDelegate {
         cell.icon.image = image
         cell.name.textColor = textColor
     }
-
-    @objc fileprivate func updateTheme() {
-        actionSheet.collectionView.backgroundColor = PresentationTheme.current.colors.background
-        actionSheet.headerView.backgroundColor = PresentationTheme.current.colors.background
-        actionSheet.headerView.title.textColor = PresentationTheme.current.colors.cellTextColor
-        actionSheet.bottomBackgroundView.backgroundColor = PresentationTheme.current.colors.background
-        for cell in actionSheet.collectionView.visibleCells {
-            if let cell = cell as? VLCActionSheetCell {
-                cell.backgroundColor = PresentationTheme.current.colors.background
-                cell.name.textColor = PresentationTheme.current.colors.cellTextColor
-            }
-        }
-        actionSheet.collectionView.layoutIfNeeded()
-    }
 }
 
 // MARK: VLCActionSheetDelegate