Commit 2c261067 by Daniel Dahan

development: updated NavigationDrawerController internals alongside BottomSheetController

parent ffaaea85
......@@ -148,7 +148,7 @@ open class BottomSheetController: RootController {
A CGFloat property that is used internally to track
the original (x) position of the container view when panning.
*/
fileprivate var originalX: CGFloat = 0
fileprivate var originalY: CGFloat = 0
/**
A UIPanGestureRecognizer property internally used for the
......@@ -261,7 +261,7 @@ open class BottomSheetController: RootController {
guard nil != bottomView else {
return false
}
return bottomView!.x != -bottomViewWidth
return bottomView!.x != -bottomViewHeight
}
/**
......@@ -275,7 +275,7 @@ open class BottomSheetController: RootController {
opens up to.
*/
@IBInspectable
open fileprivate(set) var bottomViewWidth: CGFloat!
open fileprivate(set) var bottomViewHeight: CGFloat!
/**
An initializer that initializes the object with a NSCoder object.
......@@ -314,17 +314,17 @@ open class BottomSheetController: RootController {
return
}
v.width = bottomViewWidth
v.height = view.bounds.height
bottomViewThreshold = bottomViewWidth / 2
v.width = view.bounds.width
v.height = bottomViewHeight
bottomViewThreshold = bottomViewHeight / 2
guard let vc = bottomViewController else {
return
}
vc.view.width = v.width
vc.view.height = v.height
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
vc.view.width = v.bounds.width
vc.view.height = v.bounds.height
vc.view.center = CGPoint(x: v.bounds.width / 2, y: v.bounds.height / 2)
}
/**
......@@ -354,14 +354,14 @@ open class BottomSheetController: RootController {
return
}
bottomViewWidth = width
bottomViewHeight = width
if animated {
v.isShadowPathAutoSizing = false
if isHidden {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -369,7 +369,7 @@ open class BottomSheetController: RootController {
v.bounds.size.width = width
v.position.x = -width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -380,7 +380,7 @@ open class BottomSheetController: RootController {
}
} else {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -388,7 +388,7 @@ open class BottomSheetController: RootController {
v.bounds.size.width = width
v.position.x = width / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -403,7 +403,7 @@ open class BottomSheetController: RootController {
if isHidden {
hideView(container: v)
v.position.x = -v.width / 2
v.position.x = -v.bounds.width / 2
rootViewController.view.alpha = 1
} else {
v.isShadowPathAutoSizing = false
......@@ -456,7 +456,7 @@ open class BottomSheetController: RootController {
return
}
v.position.x = v.width / 2
v.position.y = -v.bounds.height / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
guard let s = self else {
......@@ -487,14 +487,14 @@ open class BottomSheetController: RootController {
delegate?.bottomSheetController?(bottomSheetController: self, willClose: .left)
UIView.animate(withDuration: TimeInterval(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self, v = v] in
guard let s = self else {
return
}
animations: { [weak self, v = v] in
guard let s = self else {
return
}
v.position.x = -v.width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
v.position.y = v.bounds.height / 2
s.rootViewController.view.alpha = 1
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -595,14 +595,14 @@ extension BottomSheetController {
isBottomViewEnabled = true
bottomViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
bottomViewHeight = .phone == Device.userInterfaceIdiom ? 280 : 320
bottomView = UIView()
bottomView!.frame = CGRect(x: 0, y: 0, width: bottomViewWidth, height: view.height)
bottomView!.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: bottomViewHeight)
bottomView!.backgroundColor = nil
view.addSubview(bottomView!)
bottomView!.isHidden = true
bottomView!.position.x = -bottomViewWidth / 2
bottomView!.position.y = -bottomViewHeight / 2
bottomView!.zPosition = 2000
prepareBottomViewController()
}
......@@ -672,30 +672,30 @@ extension BottomSheetController: UIGestureRecognizerDelegate {
// Animate the panel.
switch recognizer.state {
case .began:
originalX = v.position.x
originalY = v.position.y
showView(container: v)
delegate?.bottomSheetController?(bottomSheetController: self, didBeginPanAt: point, position: .left)
case .changed:
let w = v.width
let translationX = recognizer.translation(in: v).x
let y = v.bounds.height
let translationY = recognizer.translation(in: v).y
v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
v.position.y = originalY - translationY > (y / 2) ? (y / 2) : originalY - translationY
let a = 1 - v.position.x / v.width
rootViewController.view.alpha = 0.5 < a && v.position.x <= v.width / 2 ? a : 0.5
let a = 1 - v.position.y / v.bounds.height
rootViewController.view.alpha = 0.5 < a && v.position.y <= v.bounds.height / 2 ? a : 0.5
delegate?.bottomSheetController?(bottomSheetController: self, didChangePanAt: point, position: .left)
case .ended, .cancelled, .failed:
let p = recognizer.velocity(in: recognizer.view)
let x = p.x >= 1000 || p.x <= -1000 ? p.x : 0
let y = p.y >= 1000 || p.y <= -1000 ? p.y : 0
delegate?.bottomSheetController?(bottomSheetController: self, didEndPanAt: point, position: .left)
if v.x <= -bottomViewWidth + bottomViewThreshold || x < -1000 {
closeBottomView(velocity: x)
if v.y <= -bottomViewHeight + bottomViewThreshold || y < -1000 {
closeBottomView(velocity: y)
} else {
openBottomView(velocity: x)
openBottomView(velocity: y)
}
case .possible:break
}
......
......@@ -436,9 +436,9 @@ open class NavigationDrawerController: RootController {
v.height = view.bounds.height
leftViewThreshold = leftViewWidth / 2
if let vc = leftViewController {
vc.view.width = v.width
vc.view.height = v.height
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
vc.view.width = v.bounds.width
vc.view.height = v.bounds.height
vc.view.center = CGPoint(x: v.bounds.width / 2, y: v.bounds.height / 2)
}
}
......@@ -447,9 +447,9 @@ open class NavigationDrawerController: RootController {
v.height = view.bounds.height
rightViewThreshold = view.bounds.width - rightViewWidth / 2
if let vc = rightViewController {
vc.view.width = v.width
vc.view.height = v.height
vc.view.center = CGPoint(x: v.width / 2, y: v.height / 2)
vc.view.width = v.bounds.width
vc.view.height = v.bounds.height
vc.view.center = CGPoint(x: v.bounds.width / 2, y: v.bounds.height / 2)
}
}
}
......@@ -461,7 +461,7 @@ open class NavigationDrawerController: RootController {
return
}
v.position.x = size.width + (isRightViewOpened ? -v.width : v.width) / 2
v.position.x = size.width + (isRightViewOpened ? -v.bounds.width : v.bounds.width) / 2
}
/**
......@@ -506,7 +506,7 @@ open class NavigationDrawerController: RootController {
if hide {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -514,7 +514,7 @@ open class NavigationDrawerController: RootController {
v.bounds.size.width = width
v.position.x = -width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -525,7 +525,7 @@ open class NavigationDrawerController: RootController {
}
} else {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -533,7 +533,7 @@ open class NavigationDrawerController: RootController {
v.bounds.size.width = width
v.position.x = width / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -548,7 +548,7 @@ open class NavigationDrawerController: RootController {
if hide {
hideView(container: v)
v.position.x = -v.width / 2
v.position.x = -v.bounds.width / 2
rootViewController.view.alpha = 1
} else {
v.isShadowPathAutoSizing = false
......@@ -591,7 +591,7 @@ open class NavigationDrawerController: RootController {
if hide {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -599,7 +599,7 @@ open class NavigationDrawerController: RootController {
v.bounds.size.width = width
v.position.x = s.view.bounds.width + width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -610,7 +610,7 @@ open class NavigationDrawerController: RootController {
}
} else {
UIView.animate(withDuration: duration,
animations: { [weak self] in
animations: { [weak self, v = v] in
guard let s = self else {
return
}
......@@ -618,7 +618,7 @@ open class NavigationDrawerController: RootController {
v.bounds.size.width = width
v.position.x = s.view.bounds.width - width / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -633,7 +633,7 @@ open class NavigationDrawerController: RootController {
if hide {
hideView(container: v)
v.position.x = view.bounds.width + v.width / 2
v.position.x = view.bounds.width + v.bounds.width / 2
rootViewController.view.alpha = 1
} else {
v.isShadowPathAutoSizing = false
......@@ -698,7 +698,7 @@ open class NavigationDrawerController: RootController {
return
}
v.position.x = v.width / 2
v.position.x = v.bounds.width / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
guard let s = self else {
......@@ -737,7 +737,7 @@ open class NavigationDrawerController: RootController {
return
}
v.position.x = s.view.bounds.width - v.width / 2
v.position.x = s.view.bounds.width - v.bounds.width / 2
s.rootViewController.view.alpha = 0.5
}) { [weak self] _ in
guard let s = self else {
......@@ -773,9 +773,9 @@ open class NavigationDrawerController: RootController {
return
}
v.position.x = -v.width / 2
v.position.x = -v.bounds.width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -812,9 +812,9 @@ open class NavigationDrawerController: RootController {
return
}
v.position.x = s.view.bounds.width + v.width / 2
v.position.x = s.view.bounds.width + v.bounds.width / 2
s.rootViewController.view.alpha = 1
}) { [weak self] _ in
}) { [weak self, v = v] _ in
guard let s = self else {
return
}
......@@ -1021,7 +1021,7 @@ extension NavigationDrawerController {
leftViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
leftView = UIView()
leftView!.frame = CGRect(x: 0, y: 0, width: leftViewWidth, height: view.height)
leftView!.frame = CGRect(x: 0, y: 0, width: leftViewWidth, height: view.bounds.height)
leftView!.backgroundColor = nil
view.addSubview(leftView!)
......@@ -1041,7 +1041,7 @@ extension NavigationDrawerController {
rightViewWidth = .phone == Device.userInterfaceIdiom ? 280 : 320
rightView = UIView()
rightView!.frame = CGRect(x: view.width, y: 0, width: rightViewWidth, height: view.height)
rightView!.frame = CGRect(x: view.bounds.width, y: 0, width: rightViewWidth, height: view.bounds.height)
rightView!.backgroundColor = nil
view.addSubview(rightView!)
......@@ -1152,13 +1152,13 @@ extension NavigationDrawerController: UIGestureRecognizerDelegate {
delegate?.navigationDrawerController?(navigationDrawerController: self, didBeginPanAt: point, position: .left)
case .changed:
let w = v.width
let w = v.bounds.width
let translationX = recognizer.translation(in: v).x
v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
let a = 1 - v.position.x / v.width
rootViewController.view.alpha = 0.5 < a && v.position.x <= v.width / 2 ? a : 0.5
let a = 1 - v.position.x / v.bounds.width
rootViewController.view.alpha = 0.5 < a && v.position.x <= v.bounds.width / 2 ? a : 0.5
if translationX >= leftThreshold {
hideStatusBar()
......@@ -1206,13 +1206,13 @@ extension NavigationDrawerController: UIGestureRecognizerDelegate {
delegate?.navigationDrawerController?(navigationDrawerController: self, didBeginPanAt: point, position: .right)
case .changed:
let w = v.width
let w = v.bounds.width
let translationX = recognizer.translation(in: v).x
v.position.x = originalX + translationX < view.bounds.width - (w / 2) ? view.bounds.width - (w / 2) : originalX + translationX
let a = 1 - (view.bounds.width - v.position.x) / v.width
rootViewController.view.alpha = 0.5 < a && v.position.x >= v.width / 2 ? a : 0.5
let a = 1 - (view.bounds.width - v.position.x) / v.bounds.width
rootViewController.view.alpha = 0.5 < a && v.position.x >= v.bounds.width / 2 ? a : 0.5
if translationX <= -rightThreshold {
hideStatusBar()
......
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