-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring fluent2-tokens Segmented Control to main (#1363)
* Bring in fluent2-token control * Add token set to project * Update dependent controls * Add colored background for demo * Update demos * Update demo order * Fix whitespace error
- Loading branch information
Showing
13 changed files
with
779 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ios/FluentUI.Demo/FluentUI.Demo/ColoredPillBackgroundView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import FluentUI | ||
import UIKit | ||
|
||
enum ColoredPillBackgroundStyle: Int { | ||
case neutral | ||
case brand | ||
} | ||
|
||
class ColoredPillBackgroundView: UIView { | ||
init(style: ColoredPillBackgroundStyle) { | ||
self.style = style | ||
super.init(frame: .zero) | ||
updateBackgroundColor() | ||
|
||
NotificationCenter.default.addObserver(self, | ||
selector: #selector(themeDidChange), | ||
name: .didChangeTheme, | ||
object: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
preconditionFailure("init(coder:) has not been implemented") | ||
} | ||
|
||
override func didMoveToWindow() { | ||
super.didMoveToWindow() | ||
updateBackgroundColor() | ||
} | ||
|
||
@objc func themeDidChange() { | ||
updateBackgroundColor() | ||
} | ||
|
||
func updateBackgroundColor() { | ||
let lightColor: UIColor | ||
let darkColor: UIColor | ||
switch style { | ||
case .neutral: | ||
if let fluentTheme = window?.fluentTheme { | ||
lightColor = UIColor(dynamicColor: fluentTheme.aliasTokens.backgroundColors[.neutral1]) | ||
darkColor = UIColor(dynamicColor: fluentTheme.aliasTokens.backgroundColors[.neutral4]) | ||
} else { | ||
lightColor = Colors.navigationBarBackground | ||
darkColor = Colors.navigationBarBackground | ||
} | ||
case .brand: | ||
if let fluentTheme = window?.fluentTheme { | ||
lightColor = UIColor(dynamicColor: fluentTheme.aliasTokens.backgroundColors[.brandRest]) | ||
darkColor = UIColor(dynamicColor: fluentTheme.aliasTokens.backgroundColors[.neutral4]) | ||
} else { | ||
lightColor = Colors.communicationBlue | ||
darkColor = Colors.navigationBarBackground | ||
} | ||
} | ||
|
||
backgroundColor = UIColor(light: lightColor, dark: darkColor) | ||
} | ||
|
||
let style: ColoredPillBackgroundStyle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.