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

Update tokens to use UIKit types, part 2 #1655

Merged
merged 13 commits into from
Mar 21, 2023
2 changes: 1 addition & 1 deletion ios/FluentUI.Demo/FluentUI.Demo/DemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class DemoController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background1))
view.backgroundColor = view.fluentTheme.color(.background1)

if allowsContentToScroll {
view.addSubview(scrollingContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DemoListViewController: DemoTableViewController {
if let provider = self.provider {
window.setColorProvider(provider)
let fluentTheme = self.view.fluentTheme
let primaryColor = UIColor(dynamicColor: fluentTheme.color(.brandBackground1))
let primaryColor = fluentTheme.color(.brandBackground1)
FluentUIFramework.initializeAppearance(with: primaryColor, whenContainedInInstancesOf: [type(of: window)])
} else {
FluentUIFramework.initializeAppearance(with: UIColor(light: UIColor(colorValue: GlobalTokens.brandColors(.comm80)), dark: UIColor(colorValue: GlobalTokens.brandColors(.comm90))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ extension ActivityIndicatorDemoController: DemoAppearanceDelegate {

private var themeWideOverrideActivityIndicatorTokens: [ActivityIndicatorTokenSet.Tokens: ControlTokenValue] {
return [
.defaultColor: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.red, .primary)) },
.defaultColor: .uiColor { GlobalTokens.sharedColor(.red, .primary) },
.thickness: .float { 20.0 }
]
}

private var perControlOverrideActivityIndicatorTokens: [ActivityIndicatorTokenSet.Tokens: ControlTokenValue] {
return [
.defaultColor: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.green, .primary)) },
.defaultColor: .uiColor { GlobalTokens.sharedColor(.green, .primary) },
.thickness: .float { 10.0 }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AliasColorTokensDemoController: DemoTableViewController {
let section = AliasColorTokensDemoSection.allCases[indexPath.section]
let row = section.rows[indexPath.row]

cell.backgroundConfiguration?.backgroundColor = UIColor(dynamicColor: fluentTheme.color(row))
cell.backgroundConfiguration?.backgroundColor = fluentTheme.color(row)
cell.selectionStyle = .none

var contentConfiguration = cell.defaultContentConfiguration()
Expand Down Expand Up @@ -81,7 +81,7 @@ class AliasColorTokensDemoController: DemoTableViewController {
.successBackground1,
.warningBackground1,
.severeBackground1:
return UIColor(dynamicColor: fluentTheme.color(.foreground1))
return fluentTheme.color(.foreground1)
case .foreground1,
.foreground2,
.foreground3,
Expand All @@ -103,12 +103,12 @@ class AliasColorTokensDemoController: DemoTableViewController {
.severeBackground2,
.severeForeground1,
.severeForeground2:
return UIColor(dynamicColor: fluentTheme.color(.foregroundOnColor))
return fluentTheme.color(.foregroundOnColor)
case .foregroundLightStatic,
.backgroundLightStatic,
.backgroundLightStaticDisabled,
.warningBackground2:
return UIColor(dynamicColor: fluentTheme.color(.foregroundDarkStatic))
return fluentTheme.color(.foregroundDarkStatic)
case .brandForeground1,
.brandForeground1Selected,
.brandForegroundDisabled1,
Expand All @@ -126,7 +126,7 @@ class AliasColorTokensDemoController: DemoTableViewController {
.presenceDnd,
.presenceAvailable,
.presenceOof:
return UIColor(dynamicColor: fluentTheme.color(.foregroundLightStatic))
return fluentTheme.color(.foregroundLightStatic)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class BottomCommandingDemoController: UIViewController {

private lazy var customPopoverViewController: UIViewController = {
let viewController = UIViewController()
viewController.view.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
viewController.view.backgroundColor = view.fluentTheme.color(.background3)
viewController.preferredContentSize = CGSize(width: 300, height: 300)
viewController.modalPresentationStyle = .popover

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,16 @@ extension BottomSheetDemoController: DemoAppearanceDelegate {
// MARK: - Custom tokens
private var themeWideOverrideBottomSheetTokens: [BottomSheetTokenSet.Tokens: ControlTokenValue] {
return [
.backgroundColor: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.plum, .tint40),
dark: GlobalTokens.sharedColors(.plum, .shade30))
.backgroundColor: .uiColor { UIColor(light: GlobalTokens.sharedColor(.plum, .tint40),
dark: GlobalTokens.sharedColor(.plum, .shade30))
}
]
}

private var perControlOverrideBottomSheetTokens: [BottomSheetTokenSet.Tokens: ControlTokenValue] {
return [
.backgroundColor: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.forest, .tint40),
dark: GlobalTokens.sharedColors(.forest, .shade30))
.backgroundColor: .uiColor { UIColor(light: GlobalTokens.sharedColor(.forest, .tint40),
dark: GlobalTokens.sharedColor(.forest, .shade30))
}
]
}
Expand Down
38 changes: 22 additions & 16 deletions ios/FluentUI.Demo/FluentUI.Demo/Demos/ButtonDemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,36 @@ extension ButtonDemoController: DemoAppearanceDelegate {

private var themeWideOverrideButtonTokens: [ButtonTokenSet.Tokens: ControlTokenValue] {
return [
.titleFont: .fontInfo { FontInfo(name: "Times", size: 20.0, weight: .regular) },
.backgroundColor: .dynamicColor {
return DynamicColor(light: GlobalTokens.sharedColors(.marigold, .shade30),
dark: GlobalTokens.sharedColors(.marigold, .tint40))
.titleFont: .uiFont {
return UIFont(descriptor: .init(name: "Times", size: 20.0),
size: 20.0)
},
.borderColor: .dynamicColor { DynamicColor(light: .clear) },
.foregroundColor: .dynamicColor {
return DynamicColor(light: GlobalTokens.sharedColors(.marigold, .tint40),
dark: GlobalTokens.sharedColors(.marigold, .shade30))
.backgroundColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.marigold, .shade30),
dark: GlobalTokens.sharedColor(.marigold, .tint40))
},
.borderColor: .uiColor { .clear },
.foregroundColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.marigold, .tint40),
dark: GlobalTokens.sharedColor(.marigold, .shade30))
}
]
}

private var perControlOverrideButtonTokens: [ButtonTokenSet.Tokens: ControlTokenValue] {
return [
.titleFont: .fontInfo { FontInfo(name: "Papyrus", size: 20.0, weight: .regular) },
.backgroundColor: .dynamicColor {
return DynamicColor(light: GlobalTokens.sharedColors(.orchid, .shade30),
dark: GlobalTokens.sharedColors(.orchid, .tint40))
.titleFont: .uiFont {
return UIFont(descriptor: .init(name: "Papyrus", size: 20.0),
size: 20.0)
},
.backgroundColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.orchid, .shade30),
dark: GlobalTokens.sharedColor(.orchid, .tint40))
},
.borderColor: .dynamicColor { DynamicColor(light: .clear) },
.foregroundColor: .dynamicColor {
return DynamicColor(light: GlobalTokens.sharedColors(.orchid, .tint40),
dark: GlobalTokens.sharedColors(.orchid, .shade30))
.borderColor: .uiColor { .clear },
.foregroundColor: .uiColor {
return UIColor(light: GlobalTokens.sharedColor(.orchid, .tint40),
dark: GlobalTokens.sharedColor(.orchid, .shade30))
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,25 @@ extension CardNudgeDemoController: DemoAppearanceDelegate {

private var themeWideOverrideCardNudgeTokens: [CardNudgeTokenSet.Tokens: ControlTokenValue] {
return [
.backgroundColor: .dynamicColor {
DynamicColor(light: GlobalTokens.sharedColors(.hotPink, .tint50),
dark: GlobalTokens.sharedColors(.hotPink, .shade40))
.backgroundColor: .uiColor {
UIColor(light: GlobalTokens.sharedColor(.hotPink, .tint50),
dark: GlobalTokens.sharedColor(.hotPink, .shade40))
},
.outlineWidth: .float {
10.0
},
.outlineColor: .dynamicColor {
DynamicColor(light: GlobalTokens.sharedColors(.darkRed, .tint50),
dark: GlobalTokens.sharedColors(.darkRed, .shade40))
.outlineColor: .uiColor {
UIColor(light: GlobalTokens.sharedColor(.darkRed, .tint50),
dark: GlobalTokens.sharedColor(.darkRed, .shade40))
}
]
}

private var perControlOverrideCardNudgeTokens: [CardNudgeTokenSet.Tokens: ControlTokenValue] {
return [
.backgroundColor: .dynamicColor {
DynamicColor(light: GlobalTokens.sharedColors(.seafoam, .tint50),
dark: GlobalTokens.sharedColors(.seafoam, .shade40))
.backgroundColor: .uiColor {
UIColor(light: GlobalTokens.sharedColor(.seafoam, .tint50),
dark: GlobalTokens.sharedColor(.seafoam, .shade40))
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class CommandBarDemoController: DemoController {
lazy var textField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
textField.backgroundColor = view.fluentTheme.color(.background3)
textField.placeholder = "Text Field"

return textField
Expand All @@ -176,21 +176,21 @@ class CommandBarDemoController: DemoController {

container.layoutMargins.right = 0
container.layoutMargins.left = 0
view.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background4))
view.backgroundColor = view.fluentTheme.color(.background4)

container.addArrangedSubview(createLabelWithText("Default"))

let commandBar = CommandBar(itemGroups: createItemGroups(), leadingItemGroups: [[newItem(for: .keyboard)]])
commandBar.delegate = self
commandBar.translatesAutoresizingMaskIntoConstraints = false
commandBar.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
commandBar.backgroundColor = view.fluentTheme.color(.background3)
container.addArrangedSubview(commandBar)
defaultCommandBar = commandBar

let itemCustomizationContainer = UIStackView()
itemCustomizationContainer.spacing = CommandBarDemoController.verticalStackViewSpacing
itemCustomizationContainer.axis = .vertical
itemCustomizationContainer.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
itemCustomizationContainer.backgroundColor = view.fluentTheme.color(.background3)

itemCustomizationContainer.addArrangedSubview(UIView()) //Spacer

Expand Down Expand Up @@ -278,13 +278,13 @@ class CommandBarDemoController: DemoController {

let fixedButtonCommandBar = CommandBar(itemGroups: createItemGroups(), leadingItemGroups: [[newItem(for: .copy)]], trailingItemGroups: [[newItem(for: .keyboard)]])
fixedButtonCommandBar.translatesAutoresizingMaskIntoConstraints = false
fixedButtonCommandBar.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
fixedButtonCommandBar.backgroundColor = view.fluentTheme.color(.background3)
container.addArrangedSubview(fixedButtonCommandBar)

container.addArrangedSubview(createLabelWithText("In Input Accessory View"))

let textFieldContainer = UIView()
textFieldContainer.backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
textFieldContainer.backgroundColor = view.fluentTheme.color(.background3)
textFieldContainer.addSubview(textField)
NSLayoutConstraint.activate([
textField.topAnchor.constraint(equalTo: textFieldContainer.topAnchor, constant: 16.0),
Expand Down Expand Up @@ -376,7 +376,7 @@ class CommandBarDemoController: DemoController {
)

commandBarItem.accentImage = command.accentImage
commandBarItem.accentImageTintColor = UIColor(dynamicColor: view.fluentTheme.color(.brandForeground1))
commandBarItem.accentImageTintColor = view.fluentTheme.color(.brandForeground1)

if command == .customView {
commandBarItem.customControlView = { () -> UIView in
Expand Down Expand Up @@ -517,13 +517,13 @@ extension CommandBarDemoController: DemoAppearanceDelegate {

private var themeWideOverrideCommandBarTokens: [CommandBarTokenSet.Tokens: ControlTokenValue] {
return [
.itemBackgroundColorRest: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.red, .primary)) }
.itemBackgroundColorRest: .uiColor { GlobalTokens.sharedColor(.red, .primary) }
]
}

private var perControlOverrideCommandBarTokens: [CommandBarTokenSet.Tokens: ControlTokenValue] {
return [
.itemBackgroundColorRest: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.grape, .primary)) }
.itemBackgroundColorRest: .uiColor { GlobalTokens.sharedColor(.grape, .primary) }
]
}
}
Expand All @@ -534,7 +534,7 @@ extension CommandBarDemoController: CommandBarDelegate {
let originalBackgroundColor = commandBar.backgroundColor

UIView.animate(withDuration: 1.0, delay: 0.0, options: [.allowUserInteraction]) {
commandBar.backgroundColor = UIColor(dynamicColor: self.view.fluentTheme.color(.brandBackground1))
commandBar.backgroundColor = self.view.fluentTheme.color(.brandBackground1)
} completion: { _ in
commandBar.backgroundColor = originalBackgroundColor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class DividerDemoController: DemoTableViewController {
private func makeDivider(orientation: MSFDividerOrientation = .horizontal, spacing: MSFDividerSpacing, customColor: Bool) -> MSFDivider {
let divider = MSFDivider(orientation: orientation, spacing: spacing)
if customColor, let color = self.view.window?.fluentTheme.brandColors(.primary) {
divider.tokenSet[.color] = .dynamicColor({ color })
divider.tokenSet[.color] = .color({ color })
}

dividers.append(divider)
Expand Down Expand Up @@ -212,13 +212,13 @@ extension DividerDemoController: DemoAppearanceDelegate {

private var themeWideOverrideDividerTokens: [DividerTokenSet.Tokens: ControlTokenValue] {
return [
.color: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.red, .primary)) }
.color: .color { DynamicColor(light: GlobalTokens.sharedColors(.red, .primary)) }
mischreiber marked this conversation as resolved.
Show resolved Hide resolved
]
}

private var perControlOverrideDividerTokens: [DividerTokenSet.Tokens: ControlTokenValue] {
return [
.color: .dynamicColor { DynamicColor(light: GlobalTokens.sharedColors(.green, .primary)) }
.color: .color { DynamicColor(light: GlobalTokens.sharedColors(.green, .primary)) }
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class DrawerDemoController: DemoController {
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
]

let backgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
let backgroundColor = view.fluentTheme.color(.background3)

controller.view.addSubview(content)
content.frame = controller.view.bounds
Expand Down Expand Up @@ -285,7 +285,7 @@ class DrawerDemoController: DemoController {
contentController: contentController,
resizingBehavior: .dismissOrExpand)

drawer.resizingHandleViewBackgroundColor = UIColor(dynamicColor: view.fluentTheme.color(.background3))
drawer.resizingHandleViewBackgroundColor = view.fluentTheme.color(.background3)
drawer.contentScrollView = personaListView
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ extension HUDDemoController: DemoAppearanceDelegate {
private var themeWideOverrideActivityHeadsUpDisplayTokens: [HeadsUpDisplayTokenSet.Tokens: ControlTokenValue] {
let fluentTheme = self.view.fluentTheme
return [
.backgroundColor: .dynamicColor { fluentTheme.color(.brandBackground1) }
.backgroundColor: .uiColor { fluentTheme.color(.brandBackground1) }
]
}

private var perControlOverrideHeadsUpDisplayTokens: [HeadsUpDisplayTokenSet.Tokens: ControlTokenValue] {
let fluentTheme = self.view.fluentTheme
return [
.cornerRadius: .float { GlobalTokens.corner(.radius120) },
.labelColor: .dynamicColor { fluentTheme.color(.brandForeground1) }
.labelColor: .uiColor { fluentTheme.color(.brandForeground1) }
]
}
}
Loading