Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 4a7cfcf

Browse files
committed
NUXViewControllerBase: Fixed badge/indicator naming
1 parent 14ab345 commit 4a7cfcf

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

WordPressAuthenticator/NUX/NUXCollectionViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
open class NUXCollectionViewController: UICollectionViewController, NUXViewControllerBase, UIViewControllerTransitioningDelegate {
55
// MARK: NUXViewControllerBase properties
66
/// these properties comply with NUXViewControllerBase and are duplicated with NUXTableViewController
7-
public var helpIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
7+
public var helpNotificationIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
88
public var helpBadge: NUXHelpBadgeLabel = NUXHelpBadgeLabel()
99
public var helpButton: UIButton = UIButton(type: .custom)
1010
public var dismissBlock: ((_ cancelled: Bool) -> Void)?

WordPressAuthenticator/NUX/NUXTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
open class NUXTableViewController: UITableViewController, NUXViewControllerBase, UIViewControllerTransitioningDelegate {
55
// MARK: NUXViewControllerBase properties
66
/// these properties comply with NUXViewControllerBase and are duplicated with NUXTableViewController
7-
public var helpIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
7+
public var helpNotificationIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
88
public var helpBadge: NUXHelpBadgeLabel = NUXHelpBadgeLabel()
99
public var helpButton: UIButton = UIButton(type: .custom)
1010
public var dismissBlock: ((_ cancelled: Bool) -> Void)?

WordPressAuthenticator/NUX/NUXViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import WordPressUI
88
open class NUXViewController: UIViewController, NUXViewControllerBase, UIViewControllerTransitioningDelegate, NUXSegueHandler {
99
// MARK: NUXViewControllerBase properties
1010
/// these properties comply with NUXViewControllerBase and are duplicated with NUXTableViewController
11-
public var helpIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
11+
public var helpNotificationIndicator: WPHelpIndicatorView = WPHelpIndicatorView()
1212
public var helpBadge: NUXHelpBadgeLabel = NUXHelpBadgeLabel()
1313
public var helpButton: UIButton = UIButton(type: .custom)
1414
public var dismissBlock: ((_ cancelled: Bool) -> Void)?

WordPressAuthenticator/NUX/NUXViewControllerBase.swift

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ private enum Constants {
88
static let helpButtonItemMarginSpace = CGFloat(-8)
99
static let helpButtonItemMinimumSize = CGSize(width: 44.0, height: 44.0)
1010

11-
static let zendeskBadgeSize = CGSize(width: 10, height: 10)
12-
static let zendeskBadgeCenterOffset = CGPoint(x: 5, y: 12)
13-
static let helpshiftBadgeSize = CGSize(width: 12, height: 12)
11+
static let notificationIndicatorCenterOffset = CGPoint(x: 5, y: 12)
12+
static var notificationIndicatorSize: CGSize {
13+
if WordPressAuthenticator.shared.configuration.supportNotificationIndicatorFeatureFlag == true {
14+
return CGSize(width: 10, height: 10)
15+
} else {
16+
return CGSize(width: 12, height: 12)
17+
}
18+
}
1419
}
1520

1621
/// base protocol for NUX view controllers
1722
public protocol NUXViewControllerBase {
1823
var sourceTag: WordPressSupportSourceTag { get }
1924
var helpBadge: NUXHelpBadgeLabel { get }
20-
var helpIndicator: WPHelpIndicatorView { get }
25+
var helpNotificationIndicator: WPHelpIndicatorView { get }
2126
var helpButton: UIButton { get }
2227
var loginFields: LoginFields { get }
2328
var dismissBlock: ((_ cancelled: Bool) -> Void)? { get }
@@ -118,7 +123,7 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
118123

119124
func refreshSupportNotificationIndicator() {
120125
let showIndicator = WordPressAuthenticator.shared.delegate?.showSupportNotificationIndicator ?? false
121-
helpIndicator.isHidden = !showIndicator
126+
helpNotificationIndicator.isHidden = !showIndicator
122127
}
123128

124129
// MARK: - Actions
@@ -175,13 +180,13 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
175180
public func addHelpButtonToNavController() {
176181
let barButtonView = createBarButtonView()
177182
addHelpButton(to: barButtonView)
178-
addBadgeView(to: barButtonView)
179-
addLeftBarButtonItem(with: barButtonView)
183+
addNotificationIndicatorView(to: barButtonView)
184+
addRightBarButtonItem(with: barButtonView)
180185
}
181186

182187
// MARK: - helpers
183188

184-
private func addLeftBarButtonItem(with customView: UIView) {
189+
private func addRightBarButtonItem(with customView: UIView) {
185190
let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
186191
spacer.width = Constants.helpButtonItemMarginSpace
187192

@@ -198,43 +203,43 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
198203
return customView
199204
}
200205

201-
private func addHelpButton(to wrapperView: UIView) {
206+
private func addHelpButton(to superView: UIView) {
202207
helpButton.setTitle(NSLocalizedString("Help", comment: "Help button"), for: .normal)
203208
helpButton.setTitleColor(Constants.helpButtonTitleColor, for: .highlighted)
204209
helpButton.on(.touchUpInside) { [weak self] control in
205210
self?.handleHelpButtonTapped(control)
206211
}
207212

208-
wrapperView.addSubview(helpButton)
213+
superView.addSubview(helpButton)
209214
helpButton.translatesAutoresizingMaskIntoConstraints = false
210215

211-
helpButton.leadingAnchor.constraint(equalTo: wrapperView.leadingAnchor, constant: Constants.helpButtonInsets.left).isActive = true
212-
helpButton.trailingAnchor.constraint(equalTo: wrapperView.trailingAnchor, constant: -Constants.helpButtonInsets.right).isActive = true
213-
helpButton.topAnchor.constraint(equalTo: wrapperView.topAnchor).isActive = true
214-
helpButton.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor).isActive = true
216+
helpButton.leadingAnchor.constraint(equalTo: superView.leadingAnchor, constant: Constants.helpButtonInsets.left).isActive = true
217+
helpButton.trailingAnchor.constraint(equalTo: superView.trailingAnchor, constant: -Constants.helpButtonInsets.right).isActive = true
218+
helpButton.topAnchor.constraint(equalTo: superView.topAnchor).isActive = true
219+
helpButton.bottomAnchor.constraint(equalTo: superView.bottomAnchor).isActive = true
215220
}
216221

217222
// MARK: Badge settings
218223

219-
private func addBadgeView(to superView: UIView) {
224+
private func addNotificationIndicatorView(to superView: UIView) {
220225
if WordPressAuthenticator.shared.configuration.supportNotificationIndicatorFeatureFlag == true {
221-
setupZendeskBadge()
222-
layoutBadgeView(helpIndicator, to: superView, size: Constants.zendeskBadgeSize)
226+
setupNotificationsIndicator()
227+
layoutNotificationIndicatorView(helpNotificationIndicator, to: superView)
223228
} else {
224-
setupHelpshiftBadge()
225-
layoutBadgeView(helpBadge, to: superView, size: Constants.helpshiftBadgeSize)
229+
setupBadge()
230+
layoutNotificationIndicatorView(helpBadge, to: superView)
226231
}
227232
}
228233

229-
private func setupHelpshiftBadge() {
234+
private func setupBadge() {
230235
helpBadge.isHidden = true
231236
NotificationCenter.default.addObserver(forName: .wordpressSupportBadgeUpdated, object: nil, queue: nil) { [weak self] _ in
232237
self?.refreshSupportBadge()
233238
}
234239
}
235240

236-
private func setupZendeskBadge() {
237-
helpIndicator.isHidden = true
241+
private func setupNotificationsIndicator() {
242+
helpNotificationIndicator.isHidden = true
238243

239244
NotificationCenter.default.addObserver(forName: .wordpressSupportNotificationReceived, object: nil, queue: nil) { [weak self] _ in
240245
self?.refreshSupportNotificationIndicator()
@@ -244,19 +249,19 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
244249
}
245250
}
246251

247-
private func layoutBadgeView(_ view: UIView, to superView: UIView, size: CGSize) {
252+
private func layoutNotificationIndicatorView(_ view: UIView, to superView: UIView) {
248253
superView.addSubview(view)
249-
250254
view.translatesAutoresizingMaskIntoConstraints = false
251255

252-
let xConstant = helpButton.contentEdgeInsets.top + Constants.zendeskBadgeCenterOffset.x
253-
let yConstant = helpButton.contentEdgeInsets.top + Constants.zendeskBadgeCenterOffset.y
256+
let centerOffset = Constants.notificationIndicatorCenterOffset
257+
let xConstant = helpButton.contentEdgeInsets.top + centerOffset.x
258+
let yConstant = helpButton.contentEdgeInsets.top + centerOffset.y
254259

255260
NSLayoutConstraint.activate([
256261
view.centerXAnchor.constraint(equalTo: helpButton.trailingAnchor, constant: xConstant),
257262
view.centerYAnchor.constraint(equalTo: helpButton.topAnchor, constant: yConstant),
258-
view.widthAnchor.constraint(equalToConstant: size.width),
259-
view.heightAnchor.constraint(equalToConstant: size.height)
263+
view.widthAnchor.constraint(equalToConstant: Constants.notificationIndicatorSize.width),
264+
view.heightAnchor.constraint(equalToConstant: Constants.notificationIndicatorSize.height)
260265
])
261266
}
262267

0 commit comments

Comments
 (0)