Commit a3df502b by Daniel Dahan

development: updated access rights for RootControllers and animations for Menu

parent 41a518db
...@@ -62,7 +62,7 @@ public enum BottomNavigationTransitionAnimation: Int { ...@@ -62,7 +62,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
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
......
...@@ -102,7 +102,7 @@ open class ContentView: View { ...@@ -102,7 +102,7 @@ open class ContentView: View {
} }
/// ContentView that holds the any desired subviews. /// ContentView that holds the any desired subviews.
open private(set) lazy var contentView = UIView() open private(set) lazy var contentView = View()
/// Left side UIControls. /// Left side UIControls.
open var leftControls = [UIView]() { open var leftControls = [UIView]() {
......
...@@ -40,9 +40,15 @@ public enum MenuDirection: Int { ...@@ -40,9 +40,15 @@ public enum MenuDirection: Int {
@objc(MenuDelegate) @objc(MenuDelegate)
public protocol MenuDelegate { public protocol MenuDelegate {
/// Gets called when the user taps outside menu buttons. /**
Gets called when the user taps while the menu is opened.
- Parameter menu: A Menu.
- Parameter tappedAt point: A CGPoint.
- Parameter isOutside: A boolean indicating whether the tap
was outside the menu button area.
*/
@objc @objc
optional func menu(menu: Menu, tappedAt point: CGPoint) optional func menu(menu: Menu, tappedAt point: CGPoint, isOutside: Bool)
} }
open class Menu: View { open class Menu: View {
...@@ -97,9 +103,43 @@ open class Menu: View { ...@@ -97,9 +103,43 @@ open class Menu: View {
/// Size of views, not including the first view. /// Size of views, not including the first view.
open var itemSize = CGSize(width: 48, height: 48) open var itemSize = CGSize(width: 48, height: 48)
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
we need to look at the subviews to see if we have a hit.
*/
guard !isHidden else {
return nil
}
guard isOpened else {
return super.hitTest(point, with: event)
}
for v in subviews {
let p = v.convert(point, from: self)
if v.bounds.contains(p) {
delegate?.menu?(menu: self, tappedAt: point, isOutside: false)
return v.hitTest(p, with: event)
}
}
delegate?.menu?(menu: self, tappedAt: point, isOutside: true)
return super.hitTest(point, with: event)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
backgroundColor = nil backgroundColor = nil
interimSpacePreset = .interimSpace6
} }
/// Reload the view layout. /// Reload the view layout.
...@@ -184,7 +224,7 @@ open class Menu: View { ...@@ -184,7 +224,7 @@ open class Menu: View {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base] in animations: { [weak self, base = base, v = v] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -193,7 +233,7 @@ open class Menu: View { ...@@ -193,7 +233,7 @@ open class Menu: View {
v.y = base.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace v.y = base.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = v] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -220,25 +260,22 @@ open class Menu: View { ...@@ -220,25 +260,22 @@ open class Menu: View {
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func closeUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func closeUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
guard let base = views.first else {
return
}
for i in 1..<views.count { for i in 1..<views.count {
let v = views[i]
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self] in animations: { [weak self, base = base, v = views[i]] in
guard let s = self else {
return
}
v.alpha = 0 v.alpha = 0
v.y = s.y v.y = base.y
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = views[i]] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -270,17 +307,18 @@ open class Menu: View { ...@@ -270,17 +307,18 @@ open class Menu: View {
return return
} }
let h = baseSize.height
for i in 1..<views.count { for i in 1..<views.count {
let v = views[i] let v = views[i]
v.isHidden = false v.isHidden = false
let h = baseSize.height
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base] in animations: { [weak self, base = base, v = v] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -289,7 +327,7 @@ open class Menu: View { ...@@ -289,7 +327,7 @@ open class Menu: View {
v.y = base.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace v.y = base.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = v] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -316,39 +354,42 @@ open class Menu: View { ...@@ -316,39 +354,42 @@ open class Menu: View {
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func closeDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func closeDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
for i in 1..<views.count { guard let base = views.first else {
let v = views[i] return
}
let h = baseSize.height
UIView.animate(withDuration: Double(i) * duration, let h = baseSize.height
delay: delay,
usingSpringWithDamping: usingSpringWithDamping, for i in 1..<views.count {
initialSpringVelocity: initialSpringVelocity, UIView.animate(withDuration: Double(i) * duration,
options: options, delay: delay,
animations: { [weak self] in usingSpringWithDamping: usingSpringWithDamping,
guard let s = self else { initialSpringVelocity: initialSpringVelocity,
return options: options,
} animations: { [weak self, base = base, v = views[i]] in
v.alpha = 0
v.y = s.y + h
animations?(v)
}) { [weak self] _ in
guard let s = self else { guard let s = self else {
return return
} }
v.isHidden = true v.alpha = 0
s.enable(view: v) v.y = base.y + h
if v == s.views.last {
s.isOpened = false
}
completion?(v) animations?(v)
}) { [weak self, v = views[i]] _ in
guard let s = self else {
return
}
v.isHidden = true
s.enable(view: v)
if v == s.views.last {
s.isOpened = false
} }
completion?(v)
} }
}
} }
/** /**
...@@ -375,7 +416,7 @@ open class Menu: View { ...@@ -375,7 +416,7 @@ open class Menu: View {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base] in animations: { [weak self, base = base, v = v] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -384,7 +425,7 @@ open class Menu: View { ...@@ -384,7 +425,7 @@ open class Menu: View {
v.x = base.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace v.x = base.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = v] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -411,24 +452,22 @@ open class Menu: View { ...@@ -411,24 +452,22 @@ open class Menu: View {
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func closeLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func closeLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
guard let base = views.first else {
return
}
for i in 1..<views.count { for i in 1..<views.count {
let v = views[i]
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self] in animations: { [weak self, v = views[i]] in
guard let s = self else {
return
}
v.alpha = 0 v.alpha = 0
v.x = s.x v.x = base.x
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = views[i]] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -460,17 +499,18 @@ open class Menu: View { ...@@ -460,17 +499,18 @@ open class Menu: View {
return return
} }
let h = baseSize.height
for i in 1..<views.count { for i in 1..<views.count {
let v = views[i] let v = views[i]
v.isHidden = false v.isHidden = false
let h = baseSize.height
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base] in animations: { [weak self, base = base, v = v] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -479,7 +519,7 @@ open class Menu: View { ...@@ -479,7 +519,7 @@ open class Menu: View {
v.x = base.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace v.x = base.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = v] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -506,16 +546,20 @@ open class Menu: View { ...@@ -506,16 +546,20 @@ open class Menu: View {
- Parameter completion: A completion block to execute on each view's animation. - Parameter completion: A completion block to execute on each view's animation.
*/ */
private func closeRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { private func closeRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
guard let base = views.first else {
return
}
let w = baseSize.width
for i in 1..<views.count { for i in 1..<views.count {
let v = views[i]
let w = baseSize.width
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self] in animations: { [weak self, base = base, v = views[i]] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -524,7 +568,7 @@ open class Menu: View { ...@@ -524,7 +568,7 @@ open class Menu: View {
v.x = s.x + w v.x = s.x + w
animations?(v) animations?(v)
}) { [weak self] _ in }) { [weak self, v = views[i]] _ in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -543,19 +587,21 @@ open class Menu: View { ...@@ -543,19 +587,21 @@ open class Menu: View {
/// Layout the views. /// Layout the views.
private func layoutButtons() { private func layoutButtons() {
for i in 0..<views.count { guard let base = views.first else {
return
}
base.frame.size = baseSize
base.zPosition = 10000
for i in 1..<views.count {
let v = views[i] let v = views[i]
if 0 == i { v.alpha = 0
v.frame.size = baseSize v.isHidden = true
v.layer.zPosition = 10000 v.frame.size = itemSize
} else { v.x = base.x + (baseSize.width - itemSize.width) / 2
v.alpha = 0 v.y = base.y + (baseSize.height - itemSize.height) / 2
v.isHidden = true v.zPosition = CGFloat(10000 - views.count - i)
v.frame.size = itemSize
v.x = x + (baseSize.width - itemSize.width) / 2
v.y = y + (baseSize.height - itemSize.height) / 2
v.layer.zPosition = CGFloat(10000 - views.count - i)
}
} }
} }
......
...@@ -51,7 +51,7 @@ extension UIViewController { ...@@ -51,7 +51,7 @@ extension UIViewController {
@IBDesignable @IBDesignable
open class MenuController: RootController { open class MenuController: RootController {
/// Reference to the MenuView. /// Reference to the MenuView.
open internal(set) lazy var menu: Menu = Menu() open private(set) lazy var menu: Menu = Menu()
/** /**
Opens the menu with a callback. Opens the menu with a callback.
...@@ -82,7 +82,7 @@ open class MenuController: RootController { ...@@ -82,7 +82,7 @@ open class MenuController: RootController {
open func closeMenu(completion: (() -> Void)? = nil) { open func closeMenu(completion: (() -> Void)? = nil) {
if false == isUserInteractionEnabled { if false == isUserInteractionEnabled {
rootViewController.view.alpha = 1 rootViewController.view.alpha = 1
menu.open { [weak self] (view) in menu.close { [weak self] (view) in
guard let s = self else { guard let s = self else {
return return
} }
......
...@@ -100,6 +100,9 @@ public protocol PageTabBarControllerDelegate { ...@@ -100,6 +100,9 @@ public protocol PageTabBarControllerDelegate {
@objc(PageTabBarController) @objc(PageTabBarController)
open class PageTabBarController: RootController { open class PageTabBarController: RootController {
/// Reference to the PageTabBar.
open private(set) lazy var pageTabBar: PageTabBar = PageTabBar()
/// Indicates that the tab has been pressed and animating. /// Indicates that the tab has been pressed and animating.
open internal(set) var isTabSelectedAnimation = false open internal(set) var isTabSelectedAnimation = false
...@@ -109,9 +112,6 @@ open class PageTabBarController: RootController { ...@@ -109,9 +112,6 @@ open class PageTabBarController: RootController {
/// PageTabBar alignment setting. /// PageTabBar alignment setting.
open var pageTabBarAlignment = PageTabBarAlignment.bottom open var pageTabBarAlignment = PageTabBarAlignment.bottom
/// Reference to the PageTabBar.
open internal(set) lazy var pageTabBar: PageTabBar = PageTabBar()
/// Delegation handler. /// Delegation handler.
open weak var delegate: PageTabBarControllerDelegate? open weak var delegate: PageTabBarControllerDelegate?
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
open class PhotoLibraryController: UIViewController { open class PhotoLibraryController: UIViewController {
/// A reference to a PhotoLibrary. /// A reference to a PhotoLibrary.
public private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary() open private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary()
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
open class RemindersController: UIViewController { open class RemindersController: UIViewController {
/// A reference to a Reminder. /// A reference to a Reminder.
public private(set) lazy var reminders: Reminders = Reminders() open private(set) lazy var reminders: Reminders = Reminders()
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
......
...@@ -50,7 +50,7 @@ extension UIViewController { ...@@ -50,7 +50,7 @@ extension UIViewController {
open class SearchBarController: RootController { open class SearchBarController: RootController {
/// Reference to the SearchBar. /// Reference to the SearchBar.
open internal(set) lazy var searchBar: SearchBar = SearchBar() open private(set) lazy var searchBar: SearchBar = SearchBar()
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
......
...@@ -86,12 +86,12 @@ extension UIViewController { ...@@ -86,12 +86,12 @@ extension UIViewController {
} }
open class SnackbarController: RootController { open class SnackbarController: RootController {
/// Reference to the Snackbar.
open private(set) lazy var snackbar: Snackbar = Snackbar()
/// A boolean indicating if the Snacbar is animating. /// A boolean indicating if the Snacbar is animating.
open internal(set) var isAnimating = false open internal(set) var isAnimating = false
/// Reference to the Snackbar.
open internal(set) lazy var snackbar: Snackbar = Snackbar()
/// Delegation handler. /// Delegation handler.
open weak var delegate: SnackbarControllerDelegate? open weak var delegate: SnackbarControllerDelegate?
......
...@@ -51,7 +51,7 @@ extension UIViewController { ...@@ -51,7 +51,7 @@ extension UIViewController {
@IBDesignable @IBDesignable
open class StatusBarController: RootController { open class StatusBarController: RootController {
/// A reference to the statusBarView. /// A reference to the statusBarView.
open internal(set) lazy var statusBarView = View() open private(set) lazy var statusBarView = View()
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
......
...@@ -69,12 +69,12 @@ public protocol ToolbarControllerDelegate { ...@@ -69,12 +69,12 @@ public protocol ToolbarControllerDelegate {
@objc(ToolbarController) @objc(ToolbarController)
open class ToolbarController: RootController { open class ToolbarController: RootController {
/// Internal reference to the floatingViewController. /// Reference to the Toolbar.
open private(set) lazy var toolbar: Toolbar = Toolbar()
/// Internal reference to the floatingViewController.
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
/// Reference to the Toolbar.
open internal(set) lazy var toolbar: Toolbar = Toolbar()
/// Delegation handler. /// Delegation handler.
open weak var delegate: ToolbarControllerDelegate? open weak var delegate: ToolbarControllerDelegate?
......
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