VLCTabBarCoordinator.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. VLCServerListViewController(nibName: nil, bundle: nil),
  45. VLCSettingsController()
  46. ]
  47. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  48. }
  49. }