Commit 94cce7e2 by Daniel Dahan

samples issue-70: added internal delegation for TabBar to be used by TabsController

parent 5c8aa125
...@@ -358,7 +358,7 @@ ...@@ -358,7 +358,7 @@
96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationDrawerController.swift; sourceTree = "<group>"; }; 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationDrawerController.swift; sourceTree = "<group>"; };
96BCB7981CB40DC500C806FE /* Bar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bar.swift; sourceTree = "<group>"; }; 96BCB7981CB40DC500C806FE /* Bar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bar.swift; sourceTree = "<group>"; };
96BCB7991CB40DC500C806FE /* TransitionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionController.swift; sourceTree = "<group>"; }; 96BCB7991CB40DC500C806FE /* TransitionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionController.swift; sourceTree = "<group>"; };
96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; }; 96BCB79A1CB40DC500C806FE /* TabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = TabBar.swift; sourceTree = "<group>"; tabWidth = 4; };
96BCB79C1CB40DC500C806FE /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; }; 96BCB79C1CB40DC500C806FE /* TextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
96BCB79D1CB40DC500C806FE /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; }; 96BCB79D1CB40DC500C806FE /* TextStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextStorage.swift; sourceTree = "<group>"; };
96BCB79E1CB40DC500C806FE /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; }; 96BCB79E1CB40DC500C806FE /* TextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
......
...@@ -39,8 +39,8 @@ open class TabItem: FlatButton { ...@@ -39,8 +39,8 @@ open class TabItem: FlatButton {
@objc(TabBarLineAlignment) @objc(TabBarLineAlignment)
public enum TabBarLineAlignment: Int { public enum TabBarLineAlignment: Int {
case top case top
case bottom case bottom
} }
@objc(TabBarDelegate) @objc(TabBarDelegate)
...@@ -74,6 +74,18 @@ public protocol TabBarDelegate { ...@@ -74,6 +74,18 @@ public protocol TabBarDelegate {
optional func tabBar(tabBar: TabBar, didSelect tabItem: TabItem) optional func tabBar(tabBar: TabBar, didSelect tabItem: TabItem)
} }
@objc(_TabBarDelegate)
internal protocol _TabBarDelegate {
/**
A delegation method that is executed when the tabItem will trigger the
animation to the next tab.
- Parameter tabBar: A TabBar.
- Parameter tabItem: A TabItem.
*/
@objc
optional func _tabBar(tabBar: TabBar, willSelect tabItem: TabItem)
}
@objc(TabBarStyle) @objc(TabBarStyle)
public enum TabBarStyle: Int { public enum TabBarStyle: Int {
case auto case auto
...@@ -124,6 +136,7 @@ open class TabBar: Bar { ...@@ -124,6 +136,7 @@ open class TabBar: Bar {
/// A delegation reference. /// A delegation reference.
open weak var delegate: TabBarDelegate? open weak var delegate: TabBarDelegate?
internal weak var _delegate: _TabBarDelegate?
/// The currently selected tabItem. /// The currently selected tabItem.
open internal(set) var selectedTabItem: TabItem? open internal(set) var selectedTabItem: TabItem?
...@@ -170,17 +183,17 @@ open class TabBar: Bar { ...@@ -170,17 +183,17 @@ open class TabBar: Bar {
} }
} }
/// TabItems. /// TabItems.
open var tabItems = [TabItem]() { open var tabItems = [TabItem]() {
didSet { didSet {
for b in oldValue { for b in oldValue {
b.removeFromSuperview() b.removeFromSuperview()
} }
prepareTabItems() prepareTabItems()
layoutSubviews() layoutSubviews()
} }
} }
/// A reference to the line UIView. /// A reference to the line UIView.
open let line = UIView() open let line = UIView()
...@@ -222,7 +235,7 @@ open class TabBar: Bar { ...@@ -222,7 +235,7 @@ open class TabBar: Bar {
layoutLine() layoutLine()
updateScrollView() updateScrollView()
} }
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
...@@ -402,6 +415,7 @@ fileprivate extension TabBar { ...@@ -402,6 +415,7 @@ fileprivate extension TabBar {
*/ */
func animate(to tabItem: TabItem, isTriggeredByUserInteraction: Bool, completion: ((TabItem) -> Void)? = nil) { func animate(to tabItem: TabItem, isTriggeredByUserInteraction: Bool, completion: ((TabItem) -> Void)? = nil) {
if isTriggeredByUserInteraction { if isTriggeredByUserInteraction {
_delegate?._tabBar?(tabBar: self, willSelect: tabItem)
delegate?.tabBar?(tabBar: self, willSelect: tabItem) delegate?.tabBar?(tabBar: self, willSelect: tabItem)
} }
......
...@@ -284,6 +284,7 @@ fileprivate extension TabsController { ...@@ -284,6 +284,7 @@ fileprivate extension TabsController {
/// Prepares the TabBar. /// Prepares the TabBar.
func prepareTabBar() { func prepareTabBar() {
tabBar.lineAlignment = .bottom == tabBarAlignment ? .top : .bottom tabBar.lineAlignment = .bottom == tabBarAlignment ? .top : .bottom
tabBar._delegate = self
tabBar.delegate = self tabBar.delegate = self
view.addSubview(tabBar) view.addSubview(tabBar)
} }
...@@ -378,9 +379,9 @@ extension TabsController { ...@@ -378,9 +379,9 @@ extension TabsController {
} }
} }
extension TabsController: TabBarDelegate { extension TabsController: _TabBarDelegate {
@objc @objc
open func tabBar(tabBar: TabBar, willSelect tabItem: TabItem) { func _tabBar(tabBar: TabBar, willSelect tabItem: TabItem) {
guard !(false == tabBar.delegate?.tabBar?(tabBar: tabBar, shouldSelect: tabItem)) else { guard !(false == tabBar.delegate?.tabBar?(tabBar: tabBar, shouldSelect: tabItem)) else {
return return
} }
...@@ -406,3 +407,5 @@ extension TabsController: TabBarDelegate { ...@@ -406,3 +407,5 @@ extension TabsController: TabBarDelegate {
} }
} }
} }
extension TabsController: TabBarDelegate {}
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