Commit 63301f01 by Daniel Dahan

modified TabsController to use TabBarDelegate rather than button handlers and…

modified TabsController to use TabBarDelegate rather than button handlers and added shouldSelect TabBarDelegate method
parent 112992a8
...@@ -59,6 +59,10 @@ ...@@ -59,6 +59,10 @@
9617B08F1DFCA8CF00410F8F /* CharacterAttribute.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B08F1DFCA8CF00410F8F /* CharacterAttribute.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7A01CB40DC500C806FE /* ToolbarController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7A01CB40DC500C806FE /* ToolbarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9618006D1F4D384200CD77A1 /* Material+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */; };
9618006E1F4D38BC00CD77A1 /* ChipBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961154CB1F32A7B100A78D74 /* ChipBar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9618006F1F4D38BC00CD77A1 /* ChipBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961527B81F3A509900E8B2AC /* ChipBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
961800701F4D38BC00CD77A1 /* Material+UIViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
961E6BDF1DDA2A95004E6C93 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BDE1DDA2A95004E6C93 /* Application.swift */; }; 961E6BDF1DDA2A95004E6C93 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BDE1DDA2A95004E6C93 /* Application.swift */; };
961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BE11DDA2AF3004E6C93 /* Screen.swift */; }; 961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BE11DDA2AF3004E6C93 /* Screen.swift */; };
96328B7A1E020A41009A4C90 /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B791E020A41009A4C90 /* CollectionViewController.swift */; }; 96328B7A1E020A41009A4C90 /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96328B791E020A41009A4C90 /* CollectionViewController.swift */; };
...@@ -285,6 +289,7 @@ ...@@ -285,6 +289,7 @@
9615277C1F393C0E00E8B2AC /* SourcePreprocessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourcePreprocessor.swift; sourceTree = "<group>"; }; 9615277C1F393C0E00E8B2AC /* SourcePreprocessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourcePreprocessor.swift; sourceTree = "<group>"; };
9615277D1F393C0E00E8B2AC /* TransitionPreprocessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionPreprocessor.swift; sourceTree = "<group>"; }; 9615277D1F393C0E00E8B2AC /* TransitionPreprocessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionPreprocessor.swift; sourceTree = "<group>"; };
961527B81F3A509900E8B2AC /* ChipBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipBarController.swift; sourceTree = "<group>"; }; 961527B81F3A509900E8B2AC /* ChipBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipBarController.swift; sourceTree = "<group>"; };
9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIViewController.swift"; sourceTree = "<group>"; };
961E6BDE1DDA2A95004E6C93 /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; }; 961E6BDE1DDA2A95004E6C93 /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
961E6BE11DDA2AF3004E6C93 /* Screen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = "<group>"; }; 961E6BE11DDA2AF3004E6C93 /* Screen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = "<group>"; };
961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; }; 961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; };
...@@ -823,6 +828,7 @@ ...@@ -823,6 +828,7 @@
96C1C8801D42C62800E6608F /* Material+Array.swift */, 96C1C8801D42C62800E6608F /* Material+Array.swift */,
962864591D53FE3E00690B69 /* Material+UIWindow.swift */, 962864591D53FE3E00690B69 /* Material+UIWindow.swift */,
966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */, 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */,
9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */,
); );
name = Extension; name = Extension;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -996,6 +1002,9 @@ ...@@ -996,6 +1002,9 @@
96D994951F4521BB00AFD6E3 /* MotionPreprocessor.swift in Headers */, 96D994951F4521BB00AFD6E3 /* MotionPreprocessor.swift in Headers */,
96D994961F4521BB00AFD6E3 /* SourcePreprocessor.swift in Headers */, 96D994961F4521BB00AFD6E3 /* SourcePreprocessor.swift in Headers */,
96D994971F4521BB00AFD6E3 /* TransitionPreprocessor.swift in Headers */, 96D994971F4521BB00AFD6E3 /* TransitionPreprocessor.swift in Headers */,
9618006E1F4D38BC00CD77A1 /* ChipBar.swift in Headers */,
9618006F1F4D38BC00CD77A1 /* ChipBarController.swift in Headers */,
961800701F4D38BC00CD77A1 /* Material+UIViewController.swift in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -1106,6 +1115,7 @@ ...@@ -1106,6 +1115,7 @@
965E81171DD4D5C800D61E4B /* TransitionController.swift in Sources */, 965E81171DD4D5C800D61E4B /* TransitionController.swift in Sources */,
965E81181DD4D5C800D61E4B /* Snackbar.swift in Sources */, 965E81181DD4D5C800D61E4B /* Snackbar.swift in Sources */,
965E81191DD4D5C800D61E4B /* SnackbarController.swift in Sources */, 965E81191DD4D5C800D61E4B /* SnackbarController.swift in Sources */,
9618006D1F4D384200CD77A1 /* Material+UIViewController.swift in Sources */,
961527811F393C0E00E8B2AC /* MotionAnimatorViewContext.swift in Sources */, 961527811F393C0E00E8B2AC /* MotionAnimatorViewContext.swift in Sources */,
965E811A1DD4D5C800D61E4B /* StatusBarController.swift in Sources */, 965E811A1DD4D5C800D61E4B /* StatusBarController.swift in Sources */,
961527871F393C0E00E8B2AC /* Motion+CALayer.swift in Sources */, 961527871F393C0E00E8B2AC /* Motion+CALayer.swift in Sources */,
......
...@@ -203,9 +203,9 @@ open class Card: PulseView { ...@@ -203,9 +203,9 @@ open class Card: PulseView {
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
depthPreset = .depth1
pulseAnimation = .none pulseAnimation = .none
cornerRadiusPreset = .cornerRadius1 cornerRadiusPreset = .cornerRadius1
prepareContainer() prepareContainer()
} }
......
...@@ -100,7 +100,6 @@ extension CollectionViewController { ...@@ -100,7 +100,6 @@ extension CollectionViewController {
collectionView.delegate = self collectionView.delegate = self
collectionView.dataSource = self collectionView.dataSource = self
view.addSubview(collectionView) view.addSubview(collectionView)
layoutCollectionView()
} }
} }
......
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
internal extension UIViewController {
/**
Finds a view controller with a given type based on
the view controller subclass.
- Returns: An optional of type T.
*/
func traverseViewControllerHierarchyForClassType<T: UIViewController>() -> T? {
var v: UIViewController? = self
while nil != v {
if v is T {
return v as? T
}
v = v?.parent as? TransitionController
}
return Application.rootViewController?.traverseTransitionViewControllerHierarchyForClassType()
}
/**
Traverses the child view controllers to find the correct view controller type T.
- Returns: An optional of type T.
*/
func traverseTransitionViewControllerHierarchyForClassType<T: UIViewController>() -> T? {
if let v = self as? T {
return v
} else if let v = self as? TransitionController {
return v.rootViewController.traverseTransitionViewControllerHierarchyForClassType()
}
return nil
}
}
...@@ -55,6 +55,13 @@ public protocol TabBarDelegate { ...@@ -55,6 +55,13 @@ public protocol TabBarDelegate {
optional func tabBar(tabBar: TabBar, willSelect tabItem: TabItem) optional func tabBar(tabBar: TabBar, willSelect tabItem: TabItem)
/** /**
A delegation method that is executed to determine if the tabItem should
transition to the next tab.
*/
@objc
optional func tabBar(tabBar: TabBar, shouldSelect tabItem: TabItem) -> Bool
/**
A delegation method that is executed when the tabItem did complete the A delegation method that is executed when the tabItem did complete the
animation to the next tab. animation to the next tab.
- Parameter tabBar: A TabBar. - Parameter tabBar: A TabBar.
...@@ -350,6 +357,10 @@ fileprivate extension TabBar { ...@@ -350,6 +357,10 @@ fileprivate extension TabBar {
/// Handles the tabItem touch event. /// Handles the tabItem touch event.
@objc @objc
func handleLineAnimation(tabItem: TabItem) { func handleLineAnimation(tabItem: TabItem) {
guard !(false == delegate?.tabBar?(tabBar: self, shouldSelect: tabItem)) else {
return
}
animate(to: tabItem, isTriggeredByUserInteraction: true) animate(to: tabItem, isTriggeredByUserInteraction: true)
} }
} }
......
...@@ -149,7 +149,7 @@ open class TabsController: TransitionController { ...@@ -149,7 +149,7 @@ open class TabsController: TransitionController {
prepareViewControllers() prepareViewControllers()
prepareTabBar() prepareTabBar()
prepareTabBarItems() prepareTabItems()
} }
} }
...@@ -194,18 +194,16 @@ fileprivate extension TabsController { ...@@ -194,18 +194,16 @@ 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
view.addSubview(tabBar) view.addSubview(tabBar)
} }
/// Prepares the `tabBar.tabItems`. /// Prepares the `tabBar.tabItems`.
func prepareTabBarItems() { func prepareTabItems() {
var tabItems = [TabItem]() var tabItems = [TabItem]()
for v in viewControllers { for v in viewControllers {
let b = v.tabItem tabItems.append(v.tabItem)
b.removeTarget(self, action: #selector(handle(tabItem:)), for: .touchUpInside)
b.addTarget(self, action: #selector(handle(tabItem:)), for: .touchUpInside)
tabItems.append(b)
} }
tabBar.tabItems = tabItems tabBar.tabItems = tabItems
...@@ -261,13 +259,13 @@ fileprivate extension TabsController { ...@@ -261,13 +259,13 @@ fileprivate extension TabsController {
} }
} }
fileprivate extension TabsController { extension TabsController: TabBarDelegate {
/**
Handles the tabItem.
- Parameter tabItem: A TabItem.
*/
@objc @objc
func handle(tabItem: TabItem) { open func tabBar(tabBar: TabBar, didSelect tabItem: TabItem) {
guard !(false == tabBar.delegate?.tabBar?(tabBar: tabBar, shouldSelect: tabItem)) else {
return
}
guard let i = tabBar.tabItems.index(of: tabItem) else { guard let i = tabBar.tabItems.index(of: tabItem) else {
return return
} }
......
...@@ -138,6 +138,7 @@ open class Toolbar: Bar { ...@@ -138,6 +138,7 @@ open class Toolbar: Bar {
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
contentViewAlignment = .center contentViewAlignment = .center
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
} }
......
...@@ -30,39 +30,6 @@ ...@@ -30,39 +30,6 @@
import UIKit import UIKit
internal extension UIViewController {
/**
Finds a view controller with a given type based on
the view controller subclass.
- Returns: An optional of type T.
*/
func traverseViewControllerHierarchyForClassType<T: UIViewController>() -> T? {
var v: UIViewController? = self
while nil != v {
if v is T {
return v as? T
}
v = v?.parent as? TransitionController
}
return Application.rootViewController?.traverseTransitionViewControllerHierarchyForClassType()
}
/**
Traverses the child view controllers to find the correct view controller type T.
- Returns: An optional of type T.
*/
func traverseTransitionViewControllerHierarchyForClassType<T: UIViewController>() -> T? {
if let v = self as? T {
return v
} else if let v = self as? TransitionController {
return v.rootViewController.traverseTransitionViewControllerHierarchyForClassType()
}
return nil
}
}
open class TransitionController: UIViewController { open class TransitionController: UIViewController {
/** /**
A Boolean property used to enable and disable interactivity A Boolean property used to enable and disable interactivity
......
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