Skip to content

Commit 57f8e04

Browse files
committed
WIP: Tab dot
1 parent f9b871d commit 57f8e04

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

WooCommerce/Classes/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8686

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

89+
tabBarController?.showDotOnTab(index: 1)
90+
8991
return true
9092
}
9193

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,33 @@ extension MainTabBarController {
126126
return navController.topViewController as? T
127127
}
128128
}
129+
130+
131+
// MARK: - Tab dot madness!
132+
//
133+
extension MainTabBarController {
134+
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))
144+
dot.tag = tag
145+
dot.backgroundColor = color
146+
dot.layer.cornerRadius = radius
147+
tabBar.subviews[index + 1].subviews.first?.insertSubview(dot, at: 1)
148+
}
149+
150+
func hideDotOnTab(index: Int) {
151+
let tag = index + 42
152+
if let subviews = tabBar.subviews[index + 1].subviews.first?.subviews {
153+
for subview in subviews where subview.tag == tag {
154+
subview.removeFromSuperview()
155+
}
156+
}
157+
}
158+
}

0 commit comments

Comments
 (0)