Commit 1b1e0712 by Daniel Dahan

development: added Divider to BottomTabBar and BottomTabBarController

parent cbac4b47
...@@ -60,7 +60,7 @@ public enum BottomNavigationTransitionAnimation: Int { ...@@ -60,7 +60,7 @@ public enum BottomNavigationTransitionAnimation: Int {
} }
@IBDesignable @IBDesignable
open class BottomNavigationController : UITabBarController, UITabBarControllerDelegate { open class BottomNavigationController: UITabBarController, UITabBarControllerDelegate {
/// The transition animation to use when selecting a new tab. /// The transition animation to use when selecting a new tab.
open var transitionAnimation: BottomNavigationTransitionAnimation = .fade open var transitionAnimation: BottomNavigationTransitionAnimation = .fade
...@@ -96,7 +96,7 @@ open class BottomNavigationController : UITabBarController, UITabBarControllerDe ...@@ -96,7 +96,7 @@ open class BottomNavigationController : UITabBarController, UITabBarControllerDe
} }
open func layoutSubviews() { open func layoutSubviews() {
if let v: Array<UITabBarItem> = tabBar.items { if let v = tabBar.items {
for item in v { for item in v {
if .phone == Device.userInterfaceIdiom { if .phone == Device.userInterfaceIdiom {
if nil == item.title { if nil == item.title {
...@@ -118,6 +118,8 @@ open class BottomNavigationController : UITabBarController, UITabBarControllerDe ...@@ -118,6 +118,8 @@ open class BottomNavigationController : UITabBarController, UITabBarControllerDe
} }
} }
} }
tabBar.divider.reload()
} }
/** /**
......
...@@ -39,7 +39,7 @@ extension UITabBarItem { ...@@ -39,7 +39,7 @@ extension UITabBarItem {
@IBDesignable @IBDesignable
open class BottomTabBar: UITabBar { open class BottomTabBar: UITabBar {
/// Automatically aligns the BottomNavigationBar to the superview. /// Automatically aligns the BottomNavigationBar to the superview.
open var isAlignedToParentAutomatically = true open var isAlignedToParentAutomatically = true
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
...@@ -81,6 +81,7 @@ open class BottomTabBar: UITabBar { ...@@ -81,6 +81,7 @@ open class BottomTabBar: UITabBar {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShadowPath()
if let v = items { if let v = items {
for item in v { for item in v {
if .phone == Device.userInterfaceIdiom { if .phone == Device.userInterfaceIdiom {
...@@ -101,6 +102,8 @@ open class BottomTabBar: UITabBar { ...@@ -101,6 +102,8 @@ open class BottomTabBar: UITabBar {
} }
} }
} }
divider.reload()
} }
open override func didMoveToSuperview() { open override func didMoveToSuperview() {
...@@ -130,31 +133,19 @@ open class BottomTabBar: UITabBar { ...@@ -130,31 +133,19 @@ open class BottomTabBar: UITabBar {
} }
/// A memory reference to the TabBarItem instance. /// A memory reference to the TabBarItem instance.
private var MaterialAssociatedObjectTabBarKey: UInt8 = 0 private var TabBarKey: UInt8 = 0
public class MaterialAssociatedObjectTabBar {
/**
A property that sets the shadowOffset, shadowOpacity, and shadowRadius
for the backing layer. This is the preferred method of setting depth
in order to maintain consitency across UI objects.
*/
public var depthPreset: DepthPreset
public init(depthPreset: DepthPreset) {
self.depthPreset = depthPreset
}
}
extension UITabBar { extension UITabBar {
/// TabBarItem reference. /// TabBarItem reference.
public internal(set) var item: MaterialAssociatedObjectTabBar { public internal(set) var divider: Divider! {
get { get {
return AssociatedObject(base: self, key: &MaterialAssociatedObjectTabBarKey) { return AssociatedObject(base: self, key: &TabBarKey) {
return MaterialAssociatedObjectTabBar(depthPreset: .none) return Divider(view: self)
} }
} }
set(value) { set(value) {
AssociateObject(base: self, key: &MaterialAssociatedObjectTabBarKey, value: value) AssociateObject(base: self, key: &TabBarKey, value: value)
} }
} }
} }
...@@ -42,12 +42,12 @@ open class Divider { ...@@ -42,12 +42,12 @@ open class Divider {
/// A reference to the UIView. /// A reference to the UIView.
internal weak var view: UIView? internal weak var view: UIView?
/// A reference to the height.
internal var height: CGFloat
/// A reference to the divider UIView. /// A reference to the divider UIView.
internal var line: UIView? internal var line: UIView?
/// A reference to the height.
public var height: CGFloat
/// Divider color. /// Divider color.
open var color: UIColor? { open var color: UIColor? {
get { get {
...@@ -87,19 +87,19 @@ open class Divider { ...@@ -87,19 +87,19 @@ open class Divider {
/// Lays out the divider. /// Lays out the divider.
internal func reload() { internal func reload() {
guard let v = view else { guard let l = line, let v = view else {
return return
} }
switch alignment { switch alignment {
case .top: case .top:
line?.frame = CGRect(x: 0, y: 0, width: v.width, height: height) l.frame = CGRect(x: 0, y: 0, width: v.width, height: height)
case .bottom: case .bottom:
line?.frame = CGRect(x: 0, y: v.height - height, width: v.width, height: height) l.frame = CGRect(x: 0, y: v.height - height, width: v.width, height: height)
case .left: case .left:
line?.frame = CGRect(x: 0, y: 0, width: height, height: v.height) l.frame = CGRect(x: 0, y: 0, width: height, height: v.height)
case .right: case .right:
line?.frame = CGRect(x: v.width - height, y: 0, width: height, height: v.height) l.frame = CGRect(x: v.width - height, y: 0, width: height, height: v.height)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment