-
Notifications
You must be signed in to change notification settings - Fork 171
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
implement red dot support for UIBarButtonItem #1974
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import UIKit | ||
|
||
@objc public extension UIBarButtonItem { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally do not want to create public extensions to system classes in Fluent, as it forces all downstream consumers to deal with our extension in their namespace. Instead, either use a custom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we are following same styling for Badge value as well. I am just adding one extra functionality on top of badge button by using same mechanism. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existence of technical debt does not automatically justify the addition of more. We should move the badge styling away from this pattern as well; adding more that needs to be changed will only increase future work, especially when it comes to public APIs that downstream partners expect to remain supported. |
||
private struct AssociatedKeys { | ||
static var redDotValue: UInt8 = 0 | ||
} | ||
|
||
static let redDotValueDidChangeNotification = NSNotification.Name(rawValue: "UIBarButtonItemRedDotValueDidChangeNotification") | ||
|
||
/// This Bool indicate if we need to display red dot on top right cornet of button. | ||
/// Red dot will be override by badge value, in case user set for badge value and red dot, it will give preference to badge value. | ||
@objc var shouldShowRedDot: Bool { | ||
get { | ||
return objc_getAssociatedObject(self, &AssociatedKeys.redDotValue) as? Bool ?? false | ||
} | ||
set { | ||
objc_setAssociatedObject(self, &AssociatedKeys.redDotValue, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
NotificationCenter.default.post(name: UIBarButtonItem.redDotValueDidChangeNotification, object: self) | ||
} | ||
} | ||
|
||
/// Use this method on bar button item's instance to set the red to visibility value. | ||
/// - Parameters: | ||
/// - shouldShowRedDot: Bool value indicating if we need to show red dot OR not. | ||
@objc func showRedDot(_ shouldShowRedDot: Bool) { | ||
self.shouldShowRedDot = shouldShowRedDot | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling