@@ -132,27 +132,38 @@ extension MainTabBarController {
132132//
133133extension 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