VLCTabBarCoordinator.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.isTranslucent = false
  29. tabBarController.tabBar.backgroundColor = PresentationTheme.current.colors.tabBarColor
  30. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  31. tabBarController.tabBar.itemPositioning = .fill
  32. tabBarController.viewControllers?.forEach {
  33. if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
  34. navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
  35. navController.navigationBar.tintColor = PresentationTheme.current.colors.orangeUI
  36. navController.navigationBar.isTranslucent = false
  37. navController.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  38. if #available(iOS 11.0, *) {
  39. navController.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  40. }
  41. }
  42. }
  43. }
  44. private func setupViewControllers() {
  45. let controllers = [
  46. VLCVideoViewController(services: services),
  47. VLCAudioViewController(services: services),
  48. VLCPlaylistViewController(services: services),
  49. VLCServerListViewController(nibName: nil, bundle: nil),
  50. VLCSettingsController()
  51. ]
  52. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  53. }
  54. }
  55. extension UITabBarController {
  56. open override var preferredStatusBarStyle: UIStatusBarStyle {
  57. return PresentationTheme.current.colors.statusBarStyle
  58. }
  59. }