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

Create FluentUI_common module, part 1 #2094

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ class NotificationViewDemoController: DemoController {
return UIColor(light: GlobalTokens.sharedColor(.orange, .primary))
},
.shadow: .shadowInfo {
return ShadowInfo(keyColor: GlobalTokens.sharedColor(.hotPink, .primary),
return ShadowInfo(keyColor: GlobalTokens.sharedSwiftUIColor(.hotPink, .primary),
keyBlur: 10.0,
xKey: 10.0,
yKey: 10.0,
ambientColor: GlobalTokens.sharedColor(.teal, .primary),
ambientColor: GlobalTokens.sharedSwiftUIColor(.teal, .primary),
ambientBlur: 100.0,
xAmbient: -10.0,
yAmbient: -10.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ struct NotificationDemoView: View {
return GlobalTokens.sharedColor(.orange, .primary)
},
.shadow: .shadowInfo {
return ShadowInfo(keyColor: GlobalTokens.sharedColor(.hotPink, .primary),
return ShadowInfo(keyColor: GlobalTokens.sharedSwiftUIColor(.hotPink, .primary),
keyBlur: 10.0,
xKey: 10.0,
yKey: 10.0,
ambientColor: GlobalTokens.sharedColor(.teal, .primary),
ambientColor: GlobalTokens.sharedSwiftUIColor(.teal, .primary),
ambientBlur: 100.0,
xAmbient: -10.0,
yAmbient: -10.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public protocol BadgeFieldDelegate: AnyObject {
* voiceover and dynamic text sizing
*/
@objc(MSFBadgeField)
open class BadgeField: UIView, TokenizedControlInternal {
open class BadgeField: UIView, TokenizedControl {
private struct Constants {
static let emptyTextFieldString: String = ""
static let dragAndDropMinimumPressDuration: TimeInterval = 0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public protocol BadgeViewDelegate {
`BadgeView` can be selected with a tap gesture and tapped again after entering a selected state for the purpose of displaying more details about the entity represented by the selected badge.
*/
@objc(MSFBadgeView)
open class BadgeView: UIView, TokenizedControlInternal {
open class BadgeView: UIView, TokenizedControl {
@objc open var dataSource: BadgeViewDataSource? {
didSet {
reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public protocol BottomCommandingControllerDelegate: AnyObject {
/// Items from the `expandedListSections` are either presented in an expanded sheet or a popover, depending on the current style.
///
@objc(MSFBottomCommandingController)
open class BottomCommandingController: UIViewController, TokenizedControlInternal {
open class BottomCommandingController: UIViewController, TokenizedControl {

/// View controller that will be displayed below the bottom commanding UI.
@objc public var contentViewController: UIViewController? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public protocol BottomSheetControllerDelegate: AnyObject {
}

@objc(MSFBottomSheetController)
public class BottomSheetController: UIViewController, Shadowable, TokenizedControlInternal {
public class BottomSheetController: UIViewController, Shadowable, TokenizedControl {

/// Initializes the bottom sheet controller
/// - Parameters:
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Button/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
/// By default, `titleLabel`'s `adjustsFontForContentSizeCategory` is set to true for non-floating buttons to automatically update its font when device's content size category changes
@IBDesignable
@objc(MSFButton)
open class Button: UIButton, Shadowable, TokenizedControlInternal {
open class Button: UIButton, Shadowable, TokenizedControl {
@objc open var style: ButtonStyle = .outlineAccent {
didSet {
if style != oldValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let calendarViewDayCellVisualStateTransitionDuration: TimeInterval = 0.3

// MARK: - CalendarViewDayCell

class CalendarViewDayCell: UICollectionViewCell, TokenizedControlInternal {
class CalendarViewDayCell: UICollectionViewCell, TokenizedControl {
struct Constants {
static let borderWidth: CGFloat = 0.5
static let dotDiameter: CGFloat = 6.0
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Card/CardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public enum CardSize: Int, CaseIterable {
Conform to the `CardDelegate` in order to provide a handler for the card tap event
*/
@objc(MSFCardView)
open class CardView: UIView, Shadowable, TokenizedControlInternal {
open class CardView: UIView, Shadowable, TokenizedControl {

/// Delegate to handle user interaction with the CardView
@objc public weak var delegate: CardDelegate?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol CommandBarDelegate: AnyObject {
Provide `itemGroups` in `init` to set the buttons in the CommandBar. Optional `leadingItemGroups` and `trailingItemGroups` add buttons in leading and trailing positions. Each `CommandBarItem` will be represented as a button.
*/
@objc(MSFCommandBar)
public class CommandBar: UIView, TokenizedControlInternal {
public class CommandBar: UIView, TokenizedControl {
// Hierarchy:
//
// isScrollable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
// MARK: - DateTimePickerViewComponentCell

/// TableViewCell representing the cell of component view (should be used only by DateTimePickerViewComponent and not instantiated on its own)
class DateTimePickerViewComponentCell: UITableViewCell, TokenizedControlInternal {
class DateTimePickerViewComponentCell: UITableViewCell, TokenizedControl {
private struct Constants {
static let baseHeight: CGFloat = 45
static let verticalPadding: CGFloat = 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public protocol DrawerControllerDelegate: AnyObject {
*/

@objc(MSFDrawerController)
open class DrawerController: UIViewController, TokenizedControlInternal {
open class DrawerController: UIViewController, TokenizedControl {
/// DrawerController colors with obj-c support
@objc public static func drawerBackgroundColor(fluentTheme: FluentTheme?) -> UIColor {
let theme = fluentTheme ?? .shared
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Label/BadgeLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit

// MARK: BadgeLabel

class BadgeLabel: UILabel, TokenizedControlInternal {
class BadgeLabel: UILabel, TokenizedControl {
var style: BadgeLabelStyle = .system {
didSet {
updateColors()
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Label/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

/// By default, `adjustsFontForContentSizeCategory` is set to true to automatically update its font when device's content size category changes
@objc(MSFLabel)
open class Label: UILabel, TokenizedControlInternal {
open class Label: UILabel, TokenizedControl {
private static let defaultColorForTheme: (FluentTheme) -> UIColor = TextColorStyle.regular.uiColor

@objc open var colorStyle: TextColorStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protocol NavigationBarBackButtonDelegate {
/// Contains the MSNavigationTitleView class and handles passing animatable progress through
/// Custom UI can be hidden if desired
@objc(MSFNavigationBar)
open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitleViewDelegate {
open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDelegate {
/// If the style is `.custom`, UINavigationItem's `navigationBarColor` is used for all the subviews' backgroundColor
@objc(MSFNavigationBarStyle)
public enum Style: Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public protocol SearchBarDelegate: AnyObject {

/// Drop-in replacement for UISearchBar that allows for more customization
@objc(MSFSearchBar)
open class SearchBar: UIView, TokenizedControlInternal {
open class SearchBar: UIView, TokenizedControl {
@objc open var hidesNavigationBarDuringSearch: Bool = true {
didSet {
if oldValue != hidesNavigationBarDuringSearch && isActive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
/// Used to contain an accessory provided by the VC contained by the NavigatableShyContainerVC
/// This class in itself is fairly straightforward, defining a height and a containment layout
/// The animation around showing/hiding this view progressively is handled by its superview/superVC, an instance of ShyHeaderController
class ShyHeaderView: UIView, TokenizedControlInternal {
class ShyHeaderView: UIView, TokenizedControl {
typealias TokenSetKeyType = EmptyTokenSet.Tokens
public var tokenSet: EmptyTokenSet = .init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
// MARK: AvatarTitleView

/// A helper view used by `NavigationBar` capable of displaying a large title and an avatar.
class AvatarTitleView: UIView, TokenizedControlInternal, TwoLineTitleViewDelegate {
class AvatarTitleView: UIView, TokenizedControl, TwoLineTitleViewDelegate {
enum Style: Int {
case primary
case system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import UIKit
`topSeparatorType` and `bottomSeparatorType` can be used to show custom horizontal separators. Make sure to remove the `UITableViewCell` built-in separator by setting `separatorStyle = .none` on your table view.
*/
@objc(MSFActionsCell)
open class ActionsCell: UITableViewCell, TokenizedControlInternal {
open class ActionsCell: UITableViewCell, TokenizedControl {
@objc(MSFActionsCellActionType)
public enum ActionType: Int {
case regular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
// MARK: ActivityIndicatorCell

@objc(MSFActivityIndicatorCell)
open class ActivityIndicatorCell: UITableViewCell, TokenizedControlInternal {
open class ActivityIndicatorCell: UITableViewCell, TokenizedControl {
public static let identifier: String = "ActivityIndicatorCell"

@objc public var backgroundStyleType: TableViewCellBackgroundStyleType = .plain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
// MARK: CenteredLabelCell

@objc(MSFCenteredLabelCell)
open class CenteredLabelCell: UITableViewCell, TokenizedControlInternal {
open class CenteredLabelCell: UITableViewCell, TokenizedControl {
public static let identifier: String = "CenteredLabelCell"

public typealias TokenSetKeyType = TableViewCellTokenSet.Tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

/// A `PillButton` is a button in the shape of a pill that can have two states: on (Selected) and off (not selected)
@objc(MSFPillButton)
open class PillButton: UIButton, TokenizedControlInternal {
open class PillButton: UIButton, TokenizedControl {

open override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
guard self == context.nextFocusedView || self == context.previouslyFocusedView else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ open class PopupMenuItem: NSObject, PopupMenuTemplateItem, FluentThemeable {
self.init(image: image, selectedImage: selectedImage, title: title, subtitle: subtitle, isEnabled: isEnabled, isSelected: isSelected, executes: executionMode, onSelected: onSelected, isAccessoryCheckmarkVisible: isAccessoryCheckmarkVisible)
}

public func isApplicableThemeChange(_ notification: Notification) -> Bool {
return true
}

lazy var tokenSet: PopupMenuItemTokenSet = {
PopupMenuItemTokenSet(customViewSize: { self.image != nil ? .small : .zero })
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
// MARK: - ResizingHandleView

@objc(MSFResizingHandleView)
open class ResizingHandleView: UIView, TokenizedControlInternal {
open class ResizingHandleView: UIView, TokenizedControl {
@objc public static let height: CGFloat = 20

private lazy var markLayer: CALayer = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit
// MARK: SegmentedControl
/// A styled segmented control that should be used instead of UISegmentedControl. It is designed to flex the button width proportionally to the control's width.
@objc(MSFSegmentedControl)
open class SegmentedControl: UIView, TokenizedControlInternal {
open class SegmentedControl: UIView, TokenizedControl {
private struct Constants {
static let iPadMinimumWidth: CGFloat = 375
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum SeparatorOrientation: Int {
// MARK: - Separator

@objc(MSFSeparator)
open class Separator: UIView, TokenizedControlInternal {
open class Separator: UIView, TokenizedControl {
public typealias TokenSetKeyType = SeparatorTokenSet.Tokens
lazy public var tokenSet: SeparatorTokenSet = .init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit

/// View that converts the subviews of a container view into a loading state with the "shimmering" effect.
@objc(MSFShimmerView)
open class ShimmerView: UIView, TokenizedControlInternal {
open class ShimmerView: UIView, TokenizedControl {

/// Optional synchronizer to sync multiple shimmer views.
@objc open weak var animationSynchronizer: AnimationSynchronizerProtocol?
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Tab Bar/SideTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol SideTabBarDelegate {
/// View for a vertical side tab bar that can be used for app navigation.
/// Optimized for horizontal regular + vertical regular size class configuration. Prefer using TabBarView for other size class configurations.
@objc(MSFSideTabBar)
open class SideTabBar: UIView, TokenizedControlInternal {
open class SideTabBar: UIView, TokenizedControl {
/// Delegate to handle user interactions in the side tab bar.
@objc public weak var delegate: SideTabBarDelegate? {
didSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import UIKit

class TabBarItemView: UIControl, TokenizedControlInternal {
class TabBarItemView: UIControl, TokenizedControl {
let item: TabBarItem

typealias TokenSetKeyType = TabBarItemTokenSet.Tokens
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Tab Bar/TabBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol TabBarViewDelegate {
/// Set up `items` array to determine the order of `TabBarItems` to show.
/// Use `selectedItem` property to change the selected tab bar item.
@objc(MSFTabBarView)
open class TabBarView: UIView, TokenizedControlInternal {
open class TabBarView: UIView, TokenizedControl {
/// List of TabBarItems in the TabBarView. Order of the array is the order of the subviews.
@objc open var items: [TabBarItem] = [] {
willSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Specify `accessoryType` on setup to show either a disclosure indicator or a `det
NOTE: This cell implements its own custom separator. Make sure to remove the UITableViewCell built-in separator by setting `separatorStyle = .none` on your table view. To remove the cell's custom separator set `bottomSeparatorType` to `.none`.
*/
@objc(MSFTableViewCell)
open class TableViewCell: UITableViewCell, TokenizedControlInternal {
open class TableViewCell: UITableViewCell, TokenizedControl {
@objc(MSFTableViewCellSeparatorType)
public enum SeparatorType: Int {
case none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public protocol TableViewHeaderFooterViewDelegate: AnyObject {
/// The optional accessory button should only be used with `default` style headers with the `title` as a single line of text.
/// Use `titleNumberOfLines` to configure the number of lines for the `title`. Headers generally use the default number of lines of 1 while footers may use a multiple number of lines.
@objc(MSFTableViewHeaderFooterView)
open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedControlInternal {
open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedControl {
@objc public static var identifier: String { return String(describing: self) }

/// The height of the view based on the height of its content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import UIKit

@objc(MSFTextField)
public final class FluentTextField: UIView, UITextFieldDelegate, TokenizedControlInternal {
public final class FluentTextField: UIView, UITextFieldDelegate, TokenizedControl {
public override func willMove(toWindow newWindow: UIWindow?) {
super.willMove(toWindow: newWindow)
guard let newWindow else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentUI_iOS/Components/Tooltip/Tooltip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import UIKit
// |--|--layer (ambient and key shadows added as sublayers)
/// A styled tooltip that is presented anchored to a view.
@objc(MSFTooltip)
open class Tooltip: NSObject, TokenizedControlInternal {
open class Tooltip: NSObject, TokenizedControl {

/// Displays a tooltip based on the current settings, pointing to the supplied anchorView.
/// If another tooltip view is already showing, it will be dismissed and the new tooltip will be shown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public protocol TwoLineTitleViewDelegate: AnyObject {
// MARK: - TwoLineTitleView

@objc(MSFTwoLineTitleView)
open class TwoLineTitleView: UIView, TokenizedControlInternal {
open class TwoLineTitleView: UIView, TokenizedControl {
@objc(MSFTwoLineTitleViewStyle)
public enum Style: Int {
case primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,4 @@ extension Color {
self.init(uiColor: UIColor(dynamicColor: dynamicColor))
}
}

init(dynamicColor: DynamicColor) {
if #available(iOS 17, *) {
self.init(dynamicColor)
} else {
self.init(uiColor: UIColor(dynamicColor: dynamicColor))
}
}
}

/// A container that stores a dynamic set of `Color` values.
struct DynamicColor: Hashable {

/// Creates a custom `ShapeStyle` that stores a dynamic set of `Color` values.
///
/// - Parameter light: The default `Color` for a light context. Required.
/// - Parameter dark: The override `Color` for a dark context. Optional.
/// - Parameter darkElevated: The override `Color` for a dark elevated context. Optional.
init(light: Color,
dark: Color? = nil,
darkElevated: Color? = nil) {
self.light = light
self.dark = dark
self.darkElevated = darkElevated
}

init(uiColor: UIColor) {
self.init(light: Color(uiColor.light),
dark: Color(uiColor.dark),
darkElevated: Color(uiColor.darkElevated))
}

let light: Color
let dark: Color?
let darkElevated: Color?
}

@available(iOS 17, *)
extension DynamicColor: ShapeStyle {
/// Evaluate to a resolved `Color` (in the form of a `ShapeStyle`) given the current `environment`.
func resolve(in environment: EnvironmentValues) -> Color.Resolved {
if environment.colorScheme == .dark {
if environment.isPresented, let darkElevated = darkElevated {
return darkElevated.resolve(in: environment)
} else if let dark = dark {
return dark.resolve(in: environment)
}
}

// default
return light.resolve(in: environment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ struct ShadowModifier: ViewModifier {

func body(content: Content) -> some View {
content
.shadow(color: Color(shadowInfo.ambientColor),
.shadow(color: shadowInfo.ambientColor,
radius: shadowInfo.ambientBlur,
x: shadowInfo.xAmbient,
y: shadowInfo.yAmbient)
.shadow(color: Color(shadowInfo.keyColor),
.shadow(color: shadowInfo.keyColor,
radius: shadowInfo.keyBlur,
x: shadowInfo.xKey,
y: shadowInfo.yKey)
Expand Down
Loading
Loading