Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to customize SideTabBar's background and separator color #1943

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ extension SideTabBarDemoController: DemoAppearanceDelegate {

private var perControlOverrideSideTabBarItemTokens: [SideTabBarTokenSet.Tokens: ControlTokenValue] {
return [
.backgroundColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.grape, .tint10),
dark: GlobalTokens.sharedColor(.grape, .tint40))
},
.tabBarItemTitleLabelFontPortrait: .uiFont {
return UIFont(descriptor: .init(name: "Papyrus", size: 20.0), size: 20.0)
},
Expand All @@ -376,6 +380,10 @@ extension SideTabBarDemoController: DemoAppearanceDelegate {
lightHighContrast: GlobalTokens.sharedColor(.teal, .tint40),
dark: GlobalTokens.sharedColor(.pumpkin, .tint40),
darkHighContrast: GlobalTokens.sharedColor(.burgundy, .tint40))
},
.separatorColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.hotPink, .tint10),
dark: GlobalTokens.sharedColor(.hotPink, .tint40))
}
]
}
Expand Down
12 changes: 5 additions & 7 deletions ios/FluentUI/Tab Bar/SideTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ open class SideTabBar: UIView, TokenizedControlInternal {
addSubview(topStackView)
addSubview(bottomStackView)

updateAppearance()

addInteraction(UILargeContentViewerInteraction())

accessibilityTraits = .tabBar
Expand Down Expand Up @@ -160,13 +162,7 @@ open class SideTabBar: UIView, TokenizedControlInternal {

private var layoutConstraints: [NSLayoutConstraint] = []
private let borderLine = Separator(orientation: .vertical)

private let backgroundView: UIVisualEffectView = {
var style = UIBlurEffect.Style.regular
style = .systemChromeMaterial

return UIVisualEffectView(effect: UIBlurEffect(style: style))
}()
private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemChromeMaterial))

private lazy var topStackView: UIStackView = {
return SideTabBar.createStackView(spacing: SideTabBarTokenSet.tabBarItemSpacing)
Expand Down Expand Up @@ -345,8 +341,10 @@ open class SideTabBar: UIView, TokenizedControlInternal {
public var tokenSet: SideTabBarTokenSet = .init()

private func updateAppearance() {
backgroundColor = tokenSet[.backgroundColor].uiColor
updateSideTabBarTokensForSection(in: .top)
updateSideTabBarTokensForSection(in: .bottom)
borderLine.tokenSet[.color] = tokenSet[.separatorColor]
}

private func updateSideTabBarTokensForSection(in section: Section) {
Expand Down
20 changes: 16 additions & 4 deletions ios/FluentUI/Tab Bar/SideTabBarTokenSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@
import UIKit

public enum SideTabBarToken: Int, TokenSetKey {
/// Optionally overrides the default background color of the of the `TabBarItem` when selected.
/// Optionally overrides the default background color of the `SideTabBar`.
case backgroundColor

/// Optionally overrides the default background color of the `TabBarItem` when selected.
case tabBarItemSelectedColor

/// Optionally overrides the default background color of the of the `TabBarItem` when not selected.
/// Optionally overrides the default background color of the `TabBarItem` when not selected.
case tabBarItemUnselectedColor

/// Optionally overrides the default font info for the title label of the `TabBarItem`when in portrait view.
/// Optionally overrides the default font info for the title label `TabBarItem`when in portrait view.
case tabBarItemTitleLabelFontPortrait

/// Optionally overrides the default font info for the title label of the `TabBarItem`when in landscape view.
/// Optionally overrides the default font info for the title label `TabBarItem`when in landscape view.
case tabBarItemTitleLabelFontLandscape

/// Optionally overrides the default color of the separator.
case separatorColor
}

/// Design token set for the `TabBar`.
public class SideTabBarTokenSet: ControlTokenSet<SideTabBarToken> {
init() {
super.init { token, theme in
switch token {
case .backgroundColor:
return .uiColor { .clear }

case .tabBarItemSelectedColor:
return .uiColor {
assertionFailure("TabBarItem tokens are placeholders and should not be read.")
Expand All @@ -47,6 +56,9 @@ public class SideTabBarTokenSet: ControlTokenSet<SideTabBarToken> {
assertionFailure("TabBarItem tokens are placeholders and should not be read.")
return theme.typography(.body1)
}

case .separatorColor:
return .uiColor { theme.color(.stroke2) }
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions ios/FluentUI/Tab Bar/TabBarTokenSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import UIKit

public enum TabBarToken: Int, TokenSetKey {
/// Defines the background color of the of the `TabBarItem` when selected.
/// Defines the background color of the `TabBarItem` when selected.
case tabBarItemSelectedColor

/// Defines the background color of the of the `TabBarItem` when not selected.
/// Defines the background color of the `TabBarItem` when not selected.
case tabBarItemUnselectedColor

/// Font info for the title label when in portrait view.
Expand All @@ -18,9 +18,8 @@ public enum TabBarToken: Int, TokenSetKey {
/// Font info for the title label when in landscape view.
case tabBarItemTitleLabelFontLandscape

/// Defines the color of the top separator.
case separatorColor

/// Defines the color of the top separator.
case separatorColor
}

/// Design token set for the `TabBar`.
Expand Down
Loading