Commit 5cbdd8f2 by Orkhan Alikhanov

Made TabsController themeable

parent 656c5e23
......@@ -39,6 +39,12 @@ public enum TabBarAlignment: Int {
case bottom
}
public enum TabBarThemingStyle {
case auto
case primary
case secondary
}
extension UIViewController {
/// TabItem reference.
@objc
......@@ -165,6 +171,9 @@ open class TabsController: TransitionController {
}
}
/// The tabBar theming style.
open var tabBarThemingStyle = TabBarThemingStyle.auto
/**
A UIPanGestureRecognizer property internally used for the interactive
swipe.
......@@ -218,11 +227,55 @@ open class TabsController: TransitionController {
prepareTabBar()
prepareTabItems()
prepareSelectedIndexViewController()
applyCurrentTheme()
}
open override func transition(to viewController: UIViewController, completion: ((Bool) -> Void)?) {
transition(to: viewController, isTriggeredByUserInteraction: false, completion: completion)
}
open override func apply(theme: Theme) {
super.apply(theme: theme)
switch tabBarThemingStyle {
case .auto where parent is NavigationController && tabBarAlignment == .top:
fallthrough
case .primary:
applyPrimary(theme: theme)
default:
applySecondary(theme: theme)
}
}
}
private extension TabsController {
/**
Applies theming taking primary color as base.
- Parameter theme: A Theme
*/
func applyPrimary(theme: Theme) {
tabBar.lineColor = theme.onPrimary.withAlphaComponent(0.68)
tabBar.backgroundColor = theme.primary
tabBar.setTabItemsColor(theme.onPrimary, for: .normal)
tabBar.setTabItemsColor(theme.onPrimary, for: .selected)
tabBar.setTabItemsColor(theme.onPrimary, for: .highlighted)
tabBar.isDividerHidden = true
}
/**
Applies theming taking secondary color as base.
- Parameter theme: A Theme
*/
func applySecondary(theme: Theme) {
tabBar.lineColor = theme.secondary
tabBar.backgroundColor = theme.background
tabBar.setTabItemsColor(theme.onSurface.withAlphaComponent(0.60), for: .normal)
tabBar.setTabItemsColor(theme.secondary, for: .selected)
tabBar.setTabItemsColor(theme.secondary, for: .highlighted)
tabBar.dividerColor = theme.onSurface.withAlphaComponent(0.12)
}
}
fileprivate extension TabsController {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment