Skip to content

Commit fd0e159

Browse files
committed
Cleaned up dot code in tabbar VC
1 parent 88dfca3 commit fd0e159

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

WooCommerce/Classes/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8686

8787
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
8888

89-
tabBarController?.showDotOnTab(index: 1)
89+
tabBarController?.showDotOn(.notifications)
9090

9191
return true
9292
}

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,38 @@ extension MainTabBarController {
132132
//
133133
extension MainTabBarController {
134134

135-
func showDotOnTab(index: Int, radius: CGFloat = 5, color: UIColor = StyleManager.wooAccent, xOffset: CGFloat = 0, yOffset: CGFloat = 0) {
136-
let tag = index + 42
137-
138-
hideDotOnTab(index: index)
139-
let dotDiameter = radius * 2
140-
let xOffsetBase = CGFloat(21)
141-
let yOffsetBase = CGFloat(3)
142-
143-
let dot = UIView(frame: CGRect(x: xOffsetBase + xOffset, y: yOffsetBase + yOffset, width: dotDiameter, height: dotDiameter))
135+
func showDotOn(_ tab: WooTab) {
136+
hideDotOn(tab)
137+
let tag = tab.rawValue + DotConstants.tagOffset
138+
let dot = UIView(frame: CGRect(x: DotConstants.xOffset,
139+
y: DotConstants.yOffset,
140+
width: DotConstants.diameter,
141+
height: DotConstants.diameter))
144142
dot.tag = tag
145-
dot.backgroundColor = color
146-
dot.layer.cornerRadius = radius
147-
tabBar.subviews[index + 1].subviews.first?.insertSubview(dot, at: 1)
143+
dot.backgroundColor = StyleManager.wooAccent
144+
dot.layer.cornerRadius = (DotConstants.diameter / 2)
145+
tabBar.subviews[tab.rawValue].subviews.first?.insertSubview(dot, at: 1)
148146
}
149147

150-
func hideDotOnTab(index: Int) {
151-
let tag = index + 42
152-
if let subviews = tabBar.subviews[index + 1].subviews.first?.subviews {
148+
func hideDotOn(_ tab: WooTab) {
149+
let tag = tab.rawValue + DotConstants.tagOffset
150+
if let subviews = tabBar.subviews[tab.rawValue].subviews.first?.subviews {
153151
for subview in subviews where subview.tag == tag {
154152
subview.removeFromSuperview()
155153
}
156154
}
157155
}
158156
}
157+
158+
159+
// MARK: - Constants!
160+
//
161+
private extension MainTabBarController {
162+
163+
enum DotConstants {
164+
static let diameter = CGFloat(9)
165+
static let xOffset = CGFloat(3)
166+
static let yOffset = CGFloat(1)
167+
static let tagOffset = 999
168+
}
169+
}

0 commit comments

Comments
 (0)