VLCTabBarCoordinator.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*****************************************************************************
  2. * VLCTabBarCoordinator.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # gmail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. class VLCTabBarCoordinator: NSObject {
  13. private var tabBarController: UITabBarController
  14. private var services: Services
  15. init(tabBarController: UITabBarController, services: Services) {
  16. self.tabBarController = tabBarController
  17. self.services = services
  18. super.init()
  19. setup()
  20. NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
  21. }
  22. private func setup() {
  23. setupViewControllers()
  24. updateTheme()
  25. }
  26. @objc func updateTheme() {
  27. //Setting this in appearanceManager doesn't update tabbar and UINavigationbar of the settingsViewController on change hence we do it here
  28. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  29. tabBarController.viewControllers?.forEach {
  30. if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
  31. navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
  32. navController.navigationBar.tintColor = PresentationTheme.current.colors.orangeUI
  33. navController.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  34. if #available(iOS 11.0, *) {
  35. navController.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  36. }
  37. }
  38. }
  39. }
  40. private func setupViewControllers() {
  41. let controllers = [
  42. VLCVideoViewController(services: services),
  43. VLCAudioViewController(services: services),
  44. VLCPlaylistViewController(services: services),
  45. VLCServerListViewController(nibName: nil, bundle: nil),
  46. VLCSettingsController()
  47. ]
  48. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  49. }
  50. }