Commit fd4d8871 by Daniel Dahan

SideNavigationViewController now passes SideNavigationPosition enum in delegation methods

parent fe847bfb
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
import UIKit import UIKit
@objc
public enum SideNavigationPosition : NSInteger {
case Left
case Right
}
public extension UIViewController { public extension UIViewController {
/** /**
A convenience property that provides access to the SideNavigationViewController. A convenience property that provides access to the SideNavigationViewController.
...@@ -54,49 +60,49 @@ public protocol SideNavigationViewControllerDelegate { ...@@ -54,49 +60,49 @@ public protocol SideNavigationViewControllerDelegate {
An optional delegation method that is fired before the An optional delegation method that is fired before the
SideNavigationViewController opens. SideNavigationViewController opens.
*/ */
optional func sideNavigationViewWillOpen(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewWillOpen(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired after the An optional delegation method that is fired after the
SideNavigationViewController opened. SideNavigationViewController opened.
*/ */
optional func sideNavigationViewDidOpen(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewDidOpen(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired before the An optional delegation method that is fired before the
SideNavigationViewController closes. SideNavigationViewController closes.
*/ */
optional func sideNavigationViewWillClose(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewWillClose(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired after the An optional delegation method that is fired after the
SideNavigationViewController closed. SideNavigationViewController closed.
*/ */
optional func sideNavigationViewDidClose(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewDidClose(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired when the An optional delegation method that is fired when the
SideNavigationViewController pan gesture begins. SideNavigationViewController pan gesture begins.
*/ */
optional func sideNavigationViewPanDidBegin(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidBegin(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired when the An optional delegation method that is fired when the
SideNavigationViewController pan gesture changes position. SideNavigationViewController pan gesture changes position.
*/ */
optional func sideNavigationViewPanDidChange(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidChange(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired when the An optional delegation method that is fired when the
SideNavigationViewController pan gesture ends. SideNavigationViewController pan gesture ends.
*/ */
optional func sideNavigationViewPanDidEnd(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidEnd(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition)
/** /**
An optional delegation method that is fired when the An optional delegation method that is fired when the
SideNavigationViewController tap gesture begins. SideNavigationViewController tap gesture begins.
*/ */
optional func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition)
} }
@objc(SideNavigationViewController) @objc(SideNavigationViewController)
...@@ -548,14 +554,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -548,14 +554,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
backdropLayer.hidden = false backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self) delegate?.sideNavigationViewWillOpen?(self, position: .Left)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position = CGPointMake(v.width / 2, v.height / 2) v.position = CGPointMake(v.width / 2, v.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showDepth(v) self.showDepth(v)
self.delegate?.sideNavigationViewDidOpen?(self) self.delegate?.sideNavigationViewDidOpen?(self, position: .Left)
} }
} }
} }
...@@ -573,14 +579,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -573,14 +579,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
backdropLayer.hidden = false backdropLayer.hidden = false
delegate?.sideNavigationViewWillOpen?(self) delegate?.sideNavigationViewWillOpen?(self, position: .Right)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showDepth(v) self.showDepth(v)
self.delegate?.sideNavigationViewDidOpen?(self) self.delegate?.sideNavigationViewDidOpen?(self, position: .Right)
} }
} }
} }
...@@ -598,14 +604,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -598,14 +604,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = true backdropLayer.hidden = true
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
delegate?.sideNavigationViewWillClose?(self) delegate?.sideNavigationViewWillClose?(self, position: .Left)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position = CGPointMake(-v.width / 2, v.height / 2) v.position = CGPointMake(-v.width / 2, v.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = true self.userInteractionEnabled = true
self.hideDepth(v) self.hideDepth(v)
self.delegate?.sideNavigationViewDidClose?(self) self.delegate?.sideNavigationViewDidClose?(self, position: .Left)
} }
} }
} }
...@@ -623,14 +629,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -623,14 +629,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = true backdropLayer.hidden = true
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
delegate?.sideNavigationViewWillClose?(self) delegate?.sideNavigationViewWillClose?(self, position: .Right)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2) v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = true self.userInteractionEnabled = true
self.hideDepth(v) self.hideDepth(v)
self.delegate?.sideNavigationViewDidClose?(self) self.delegate?.sideNavigationViewDidClose?(self, position: .Right)
} }
} }
} }
...@@ -641,7 +647,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -641,7 +647,6 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
return opened || isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(touch.locationInView(view)) return opened || isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(touch.locationInView(view))
} }
if opened && gestureRecognizer == tapGesture { if opened && gestureRecognizer == tapGesture {
delegate?.sideNavigationViewDidTap?(self, point: touch.locationInView(view))
return true return true
} }
return false return false
...@@ -667,20 +672,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -667,20 +672,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
showDepth(v) showDepth(v)
delegate?.sideNavigationViewPanDidBegin?(self, point: point) delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Right)
case .Changed: case .Changed:
let w: CGFloat = v.width let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
v.position.x = self.originalX + translationX < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : self.originalX + translationX v.position.x = self.originalX + translationX < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : self.originalX + translationX
self.delegate?.sideNavigationViewPanDidChange?(self, point: point) self.delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Right)
} }
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: point) delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Right)
if v.x >= rightViewThreshold { if v.x >= rightViewThreshold {
closeRightView(x) closeRightView(x)
...@@ -702,20 +707,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -702,20 +707,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
toggleStatusBar(true) toggleStatusBar(true)
showDepth(v) showDepth(v)
delegate?.sideNavigationViewPanDidBegin?(self, point: point) delegate?.sideNavigationViewPanDidBegin?(self, point: point, position: .Left)
case .Changed: case .Changed:
let w: CGFloat = v.width let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
v.position.x = self.originalX + translationX > (w / 2) ? (w / 2) : self.originalX + translationX v.position.x = self.originalX + translationX > (w / 2) ? (w / 2) : self.originalX + translationX
self.delegate?.sideNavigationViewPanDidChange?(self, point: point) self.delegate?.sideNavigationViewPanDidChange?(self, point: point, position: .Left)
} }
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: point) delegate?.sideNavigationViewPanDidEnd?(self, point: point, position: .Left)
if v.x <= -leftViewWidth + leftViewThreshold { if v.x <= -leftViewWidth + leftViewThreshold {
closeLeftView(x) closeLeftView(x)
...@@ -736,11 +741,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -736,11 +741,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
internal func handleTapGesture(recognizer: UITapGestureRecognizer) { internal func handleTapGesture(recognizer: UITapGestureRecognizer) {
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Left)
if enabledLeftView && openedLeftView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) { if enabledLeftView && openedLeftView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeLeftView() closeLeftView()
} }
} }
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Right)
if enabledRightView && openedRightView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) { if enabledRightView && openedRightView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeRightView() closeRightView()
} }
......
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