Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe
var showSearchProgressSpinner: Bool = true
var showRainbowRingForAvatar: Bool = false
var showBadgeOnBarButtonItem: Bool = false
var updateBadgeLabelStyle: Bool = false

var allowsCellSelection: Bool = false {
didSet {
Expand Down Expand Up @@ -642,6 +643,20 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe
}

if indexPath.row == 3 {
guard let cell = tableView.dequeueReusableCell(withIdentifier: BooleanCell.identifier, for: indexPath) as? BooleanCell else {
return UITableViewCell()
}
cell.setup(title: "Override Badge Label Style",
isOn: updateBadgeLabelStyle,
isSwitchEnabled: navigationItem.titleStyle == .largeLeading)
cell.titleNumberOfLines = 0
cell.onValueChanged = { [weak self, weak cell] in
self?.updateBadgeStyle(isOn: cell?.isOn ?? false)
}
return cell
}

if indexPath.row == 4 {
guard let cell = tableView.dequeueReusableCell(withIdentifier: ActionsCell.identifier, for: indexPath) as? ActionsCell else {
return UITableViewCell()
}
Expand Down Expand Up @@ -766,6 +781,12 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe
showBadgeOnBarButtonItem = isOn
}

@objc private func updateBadgeStyle(isOn: Bool) {
let navigationBar = msfNavigationController?.msfNavigationBar
navigationBar?.overriddenBadgeLabelStyle = isOn ? NavigationBar.BadgeLabelStyleWrapper(style: .system) : nil
updateBadgeLabelStyle = isOn
}

@objc private func showTooltipButtonPressed() {
let navigationBar = msfNavigationController?.msfNavigationBar
guard let view = navigationBar?.barButtonItemView(with: BarButtonItemTag.threeDay.rawValue) else {
Expand Down
20 changes: 19 additions & 1 deletion Sources/FluentUI_iOS/Components/Navigation/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDel
}
}

@objc public class BadgeLabelStyleWrapper: NSObject {
public var style: BadgeLabelStyle
@objc public init(style: BadgeLabelStyle) {
self.style = style
}
}

@objc public static func navigationBarBackgroundColor(fluentTheme: FluentTheme?) -> UIColor {
return backgroundColor(for: .system, theme: fluentTheme)
}
Expand Down Expand Up @@ -306,6 +313,15 @@ open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDel
// @objc dynamic - so we can do KVO on this
@objc dynamic private(set) var style: Style = defaultStyle

// Override value for BadgeLabel Style. We can set to nil when we don't wanna override.
@objc public var overriddenBadgeLabelStyle: BadgeLabelStyleWrapper? {
didSet {
if let navigationItem = topItem {
updateBarButtonItems(with: navigationItem)
}
}
}

private var systemWantsCompactNavigationBar: Bool {
return traitCollection.horizontalSizeClass == .compact && traitCollection.verticalSizeClass == .compact
}
Expand Down Expand Up @@ -735,7 +751,9 @@ open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDel
private func createBarButtonItemButton(with item: UIBarButtonItem, isLeftItem: Bool) -> UIButton {
let button = BadgeLabelButton(type: .system)
button.item = item
if style == .system {
if let badgeLabelStyle = overriddenBadgeLabelStyle?.style {
button.badgeLabelStyle = badgeLabelStyle
} else if style == .system {
button.badgeLabelStyle = .system
} else if style == .gradient {
button.badgeLabelStyle = .brand
Expand Down
Loading