From d828d0f3931c538062d162fd4f5a8a7b04a673cd Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Tue, 20 Feb 2024 15:16:59 +0530 Subject: [PATCH 1/6] add property to override badge style in navigation bar --- ios/FluentUI/Navigation/NavigationBar.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ios/FluentUI/Navigation/NavigationBar.swift b/ios/FluentUI/Navigation/NavigationBar.swift index 14a5c1fcb4..316ccf728b 100644 --- a/ios/FluentUI/Navigation/NavigationBar.swift +++ b/ios/FluentUI/Navigation/NavigationBar.swift @@ -302,6 +302,8 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl // @objc dynamic - so we can do KVO on this @objc dynamic private(set) var style: Style = defaultStyle + private(set) var badgeLabelStyle: Style? + private var systemWantsCompactNavigationBar: Bool { return traitCollection.horizontalSizeClass == .compact && traitCollection.verticalSizeClass == .compact } @@ -589,6 +591,12 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl titleView.avatarOverrideStyle = style } + /// Override BadgeLabelStyle for navigation bar + /// - Parameter badgeLabelStyle: updated style to be used + @objc public func overrideBadgeLabelStyle(_ badgeLabelStyle: Style) { + self.badgeLabelStyle = badgeLabelStyle + } + // MARK: Element size handling private var currentAvatarSize: ElementSize { @@ -724,9 +732,10 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl private func createBarButtonItemButton(with item: UIBarButtonItem, isLeftItem: Bool) -> UIButton { let button = BadgeLabelButton(type: .system) button.item = item - if style == .system { + let finalStyle = badgeLabelStyle != nil ? badgeLabelStyle : style + if finalStyle == .system { button.badgeLabelStyle = .system - } else if style == .gradient { + } else if finalStyle == .gradient { button.badgeLabelStyle = .brand } else { button.badgeLabelStyle = .onPrimary From 41f00b267b01a9f0e659b45d0ed3200067fc8ac1 Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Wed, 21 Feb 2024 10:08:00 +0530 Subject: [PATCH 2/6] fix review comment --- ios/FluentUI/Navigation/NavigationBar.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/FluentUI/Navigation/NavigationBar.swift b/ios/FluentUI/Navigation/NavigationBar.swift index 316ccf728b..eb58a70041 100644 --- a/ios/FluentUI/Navigation/NavigationBar.swift +++ b/ios/FluentUI/Navigation/NavigationBar.swift @@ -732,7 +732,7 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl private func createBarButtonItemButton(with item: UIBarButtonItem, isLeftItem: Bool) -> UIButton { let button = BadgeLabelButton(type: .system) button.item = item - let finalStyle = badgeLabelStyle != nil ? badgeLabelStyle : style + let finalStyle = badgeLabelStyle ?? style if finalStyle == .system { button.badgeLabelStyle = .system } else if finalStyle == .gradient { From 3269137bd74abc2252bd726954293777ab5c37ef Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Fri, 1 Mar 2024 09:58:53 +0530 Subject: [PATCH 3/6] add StyleWrapper class to expose property in Objective C --- .../NavigationControllerDemoController.swift | 21 ++++++++++++++++ ios/FluentUI/Navigation/NavigationBar.swift | 24 ++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift index 8a79d2fae9..2fb469eb29 100644 --- a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift +++ b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift @@ -473,6 +473,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 { @@ -624,6 +625,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() } @@ -748,6 +763,12 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe showBadgeOnBarButtonItem = isOn } + @objc private func updateBadgeStyle(isOn: Bool) { + let navigationBar = msfNavigationController?.msfNavigationBar + navigationBar?.overriddenBadgeLabelStyle = isOn ? NavigationBar.StyleWrapper(style: .system) : nil + updateBadgeLabelStyle = isOn + } + @objc private func showTooltipButtonPressed() { let navigationBar = msfNavigationController?.msfNavigationBar guard let view = navigationBar?.barButtonItemView(with: BarButtonItemTag.threeDay.rawValue) else { diff --git a/ios/FluentUI/Navigation/NavigationBar.swift b/ios/FluentUI/Navigation/NavigationBar.swift index eb58a70041..21ab2a6f8f 100644 --- a/ios/FluentUI/Navigation/NavigationBar.swift +++ b/ios/FluentUI/Navigation/NavigationBar.swift @@ -126,6 +126,13 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl } } + @objc public class StyleWrapper: NSObject { + public var style: Style + @objc public init(style: Style) { + self.style = style + } + } + @objc public static func navigationBarBackgroundColor(fluentTheme: FluentTheme?) -> UIColor { return backgroundColor(for: .system, theme: fluentTheme) } @@ -302,7 +309,14 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl // @objc dynamic - so we can do KVO on this @objc dynamic private(set) var style: Style = defaultStyle - private(set) var badgeLabelStyle: Style? + // by default pointing to .default, + @objc public var overriddenBadgeLabelStyle: StyleWrapper? { + didSet { + if let navigationItem = topItem { + updateBarButtonItems(with: navigationItem) + } + } + } private var systemWantsCompactNavigationBar: Bool { return traitCollection.horizontalSizeClass == .compact && traitCollection.verticalSizeClass == .compact @@ -591,12 +605,6 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl titleView.avatarOverrideStyle = style } - /// Override BadgeLabelStyle for navigation bar - /// - Parameter badgeLabelStyle: updated style to be used - @objc public func overrideBadgeLabelStyle(_ badgeLabelStyle: Style) { - self.badgeLabelStyle = badgeLabelStyle - } - // MARK: Element size handling private var currentAvatarSize: ElementSize { @@ -732,7 +740,7 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl private func createBarButtonItemButton(with item: UIBarButtonItem, isLeftItem: Bool) -> UIButton { let button = BadgeLabelButton(type: .system) button.item = item - let finalStyle = badgeLabelStyle ?? style + let finalStyle = overriddenBadgeLabelStyle?.style ?? style if finalStyle == .system { button.badgeLabelStyle = .system } else if finalStyle == .gradient { From 8c4d23b732c3468c2c603d6270fae4f6b528e865 Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Fri, 1 Mar 2024 10:07:41 +0530 Subject: [PATCH 4/6] updated comment --- ios/FluentUI/Navigation/NavigationBar.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/FluentUI/Navigation/NavigationBar.swift b/ios/FluentUI/Navigation/NavigationBar.swift index 21ab2a6f8f..2982de19d9 100644 --- a/ios/FluentUI/Navigation/NavigationBar.swift +++ b/ios/FluentUI/Navigation/NavigationBar.swift @@ -309,7 +309,7 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl // @objc dynamic - so we can do KVO on this @objc dynamic private(set) var style: Style = defaultStyle - // by default pointing to .default, + // Override value for BadgeLabel Style. We can set to nil when we don't wanna override. @objc public var overriddenBadgeLabelStyle: StyleWrapper? { didSet { if let navigationItem = topItem { From 66f575f73f26f95809930979f4b2dc3d44682574 Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Wed, 27 Mar 2024 09:59:45 +0530 Subject: [PATCH 5/6] change wrapper to accept badgelabelstyle instead of style --- .../NavigationControllerDemoController.swift | 4 ++-- ios/FluentUI.xcodeproj/project.pbxproj | 2 +- ios/FluentUI/Navigation/NavigationBar.swift | 15 ++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift index 2fb469eb29..8d6362cdbf 100644 --- a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift +++ b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift @@ -216,7 +216,7 @@ class NavigationControllerDemoController: DemoController { content.navigationItem.titleStyle = titleStyle content.navigationItem.subtitle = subtitle content.navigationItem.backButtonTitle = "99+" - content.navigationItem.navigationBarStyle = style + content.navigationItem.navigationBarStyle = .system content.navigationItem.navigationBarShadow = showShadow ? .automatic : .alwaysHidden content.navigationItem.accessoryView = accessoryView content.navigationItem.topAccessoryViewAttributes = NavigationBarTopSearchBarAttributes() @@ -765,7 +765,7 @@ class RootViewController: UIViewController, UITableViewDataSource, UITableViewDe @objc private func updateBadgeStyle(isOn: Bool) { let navigationBar = msfNavigationController?.msfNavigationBar - navigationBar?.overriddenBadgeLabelStyle = isOn ? NavigationBar.StyleWrapper(style: .system) : nil + navigationBar?.overriddenBadgeLabelStyle = isOn ? NavigationBar.BadgeLabelStyleWrapper(style: .system) : nil updateBadgeLabelStyle = isOn } diff --git a/ios/FluentUI.xcodeproj/project.pbxproj b/ios/FluentUI.xcodeproj/project.pbxproj index ccd3b922fa..94efb3a793 100644 --- a/ios/FluentUI.xcodeproj/project.pbxproj +++ b/ios/FluentUI.xcodeproj/project.pbxproj @@ -457,7 +457,7 @@ FD41C87022DD13230086F899 /* ShyHeaderController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShyHeaderController.swift; sourceTree = ""; }; FD41C87122DD13230086F899 /* ShyHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShyHeaderView.swift; sourceTree = ""; }; FD41C87A22DD13230086F899 /* AvatarTitleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarTitleView.swift; sourceTree = ""; }; - FD41C87B22DD13230086F899 /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = ""; }; + FD41C87B22DD13230086F899 /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = ""; usesTabs = 0; }; FD41C87E22DD13230086F899 /* SearchBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; FD41C87F22DD13230086F899 /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = ""; }; FD41C88022DD13230086F899 /* NavigationAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationAnimator.swift; sourceTree = ""; }; diff --git a/ios/FluentUI/Navigation/NavigationBar.swift b/ios/FluentUI/Navigation/NavigationBar.swift index 2982de19d9..42db92699c 100644 --- a/ios/FluentUI/Navigation/NavigationBar.swift +++ b/ios/FluentUI/Navigation/NavigationBar.swift @@ -126,9 +126,9 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl } } - @objc public class StyleWrapper: NSObject { - public var style: Style - @objc public init(style: Style) { + @objc public class BadgeLabelStyleWrapper: NSObject { + public var style: BadgeLabelStyle + @objc public init(style: BadgeLabelStyle) { self.style = style } } @@ -310,7 +310,7 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl @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: StyleWrapper? { + @objc public var overriddenBadgeLabelStyle: BadgeLabelStyleWrapper? { didSet { if let navigationItem = topItem { updateBarButtonItems(with: navigationItem) @@ -740,10 +740,11 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl private func createBarButtonItemButton(with item: UIBarButtonItem, isLeftItem: Bool) -> UIButton { let button = BadgeLabelButton(type: .system) button.item = item - let finalStyle = overriddenBadgeLabelStyle?.style ?? style - if finalStyle == .system { + if let badgeLabelStyle = overriddenBadgeLabelStyle?.style { + button.badgeLabelStyle = badgeLabelStyle + } else if style == .system { button.badgeLabelStyle = .system - } else if finalStyle == .gradient { + } else if style == .gradient { button.badgeLabelStyle = .brand } else { button.badgeLabelStyle = .onPrimary From e1c7dcfd022193c51a5f950dc46c632d8f9a37da Mon Sep 17 00:00:00 2001 From: kumarmohit5189 Date: Wed, 27 Mar 2024 10:22:29 +0530 Subject: [PATCH 6/6] revert style change in demo app --- .../Demos/NavigationControllerDemoController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift index 8d6362cdbf..277efec819 100644 --- a/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift +++ b/ios/FluentUI.Demo/FluentUI.Demo/Demos/NavigationControllerDemoController.swift @@ -216,7 +216,7 @@ class NavigationControllerDemoController: DemoController { content.navigationItem.titleStyle = titleStyle content.navigationItem.subtitle = subtitle content.navigationItem.backButtonTitle = "99+" - content.navigationItem.navigationBarStyle = .system + content.navigationItem.navigationBarStyle = style content.navigationItem.navigationBarShadow = showShadow ? .automatic : .alwaysHidden content.navigationItem.accessoryView = accessoryView content.navigationItem.topAccessoryViewAttributes = NavigationBarTopSearchBarAttributes()