Commit 94cce7e2 by Daniel Dahan

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

parent 5c8aa125
......@@ -358,7 +358,7 @@
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>"; };
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>"; };
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>"; };
......
......@@ -74,6 +74,18 @@ public protocol TabBarDelegate {
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)
public enum TabBarStyle: Int {
case auto
......@@ -124,6 +136,7 @@ open class TabBar: Bar {
/// A delegation reference.
open weak var delegate: TabBarDelegate?
internal weak var _delegate: _TabBarDelegate?
/// The currently selected tabItem.
open internal(set) var selectedTabItem: TabItem?
......@@ -402,6 +415,7 @@ fileprivate extension TabBar {
*/
func animate(to tabItem: TabItem, isTriggeredByUserInteraction: Bool, completion: ((TabItem) -> Void)? = nil) {
if isTriggeredByUserInteraction {
_delegate?._tabBar?(tabBar: self, willSelect: tabItem)
delegate?.tabBar?(tabBar: self, willSelect: tabItem)
}
......
......@@ -284,6 +284,7 @@ fileprivate extension TabsController {
/// Prepares the TabBar.
func prepareTabBar() {
tabBar.lineAlignment = .bottom == tabBarAlignment ? .top : .bottom
tabBar._delegate = self
tabBar.delegate = self
view.addSubview(tabBar)
}
......@@ -378,9 +379,9 @@ extension TabsController {
}
}
extension TabsController: TabBarDelegate {
extension TabsController: _TabBarDelegate {
@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 {
return
}
......@@ -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