Commit 3879aac8 by Dmitry Stepanets

Added custom show/hide gestures

parent 58cd9ddb
...@@ -73,7 +73,15 @@ class TodayViewController: UIViewController { ...@@ -73,7 +73,15 @@ class TodayViewController: UIViewController {
} }
@objc private func handleNotificationButton() { @objc private func handleNotificationButton() {
self.coordinator.openNotificationsScreen() #if DEBUG
if #available(iOS 14, *) {
let promo = WidgetPromotionController(coordinator: WidgetPromotionCoordinator(parentViewController: self))
present(promo, animated: true)
}
#else
fatalError("Remove in release")
#endif
// self.coordinator.openNotificationsScreen()
} }
} }
......
...@@ -26,7 +26,7 @@ class PromotionPresentationAnimator: NSObject, UIViewControllerAnimatedTransitio ...@@ -26,7 +26,7 @@ class PromotionPresentationAnimator: NSObject, UIViewControllerAnimatedTransitio
height: contentHeight) height: contentHeight)
container.addSubview(toViewController.view) container.addSubview(toViewController.view)
UIView.animate(withDuration: transitionDuration(using: transitionContext)) { UIView.animate(withDuration: transitionDuration(using: transitionContext)) {
toViewController.view.frame.origin.y = container.frame.height - contentHeight toViewController.view.frame.origin.y = container.bounds.height * 0.46
} completion: { finished in } completion: { finished in
transitionContext.completeTransition(finished) transitionContext.completeTransition(finished)
} }
......
...@@ -20,12 +20,8 @@ class WidgetPromotionController: UIViewController { ...@@ -20,12 +20,8 @@ class WidgetPromotionController: UIViewController {
private let stackView = UIStackView() private let stackView = UIStackView()
private let footerView = UIView() private let footerView = UIView()
private let learnButton = UIButton() private let learnButton = UIButton()
private var initialTouchPoint = CGPoint(x: 0,y: 0) private let fullView: CGFloat = UIScreen.main.bounds.height - UIScreen.main.bounds.height * 0.9
private lazy var panGesture: UIPanGestureRecognizer = { private let partialView: CGFloat = UIScreen.main.bounds.height * 0.46
let gesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(sender:)))
gesture.delegate = self
return gesture
}()
//Public //Public
var controllerContentHeight: CGFloat { var controllerContentHeight: CGFloat {
...@@ -99,26 +95,32 @@ class WidgetPromotionController: UIViewController { ...@@ -99,26 +95,32 @@ class WidgetPromotionController: UIViewController {
} }
} }
@objc private func handlePanGesture(sender: UIPanGestureRecognizer) { @objc private func handlePanGesture(recognizer: UIPanGestureRecognizer) {
let touchPoint = sender.location(in: self.view?.window) let translation = recognizer.translation(in: self.view)
let originalOffsetY = UIScreen.main.bounds.height - self.view.bounds.height let velocity = recognizer.velocity(in: self.view)
let y = self.view.frame.minY
switch sender.state {
case .began: switch recognizer.state {
initialTouchPoint = touchPoint
case .changed: case .changed:
if touchPoint.y - initialTouchPoint.y > 0 { self.view.frame = CGRect(x: 0, y: y + translation.y, width: view.frame.width, height: view.frame.height)
view.frame.origin.y = originalOffsetY + (touchPoint.y - initialTouchPoint.y) recognizer.setTranslation(CGPoint.zero, in: self.view)
case .ended:
var duration = velocity.y < 0 ? Double((y - fullView) / -velocity.y) : Double((partialView - y) / velocity.y )
duration = duration > 0.3 ? 0.3 : duration
if velocity.y >= 0 {
self.dismiss(animated: true)
} }
case .cancelled, .ended: else {
if touchPoint.y - initialTouchPoint.y > 80 { UIView.animate(withDuration: duration) {
close() self.view.frame = CGRect(x: 0, y: self.fullView, width: self.view.frame.width, height: self.view.frame.height)
} else { } completion: {[weak self] _ in
UIView.animate(withDuration: 0.25, animations: { if ( velocity.y < 0 ) {
self.view.frame.origin.y = originalOffsetY self?.scrollView.isScrollEnabled = true
}) }
}
} }
break
default: default:
break break
} }
...@@ -141,7 +143,9 @@ class WidgetPromotionController: UIViewController { ...@@ -141,7 +143,9 @@ class WidgetPromotionController: UIViewController {
@available(iOS 14, *) @available(iOS 14, *)
private extension WidgetPromotionController { private extension WidgetPromotionController {
func prepareView() { func prepareView() {
// view.addGestureRecognizer(panGesture) let gesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(recognizer:)))
gesture.delegate = self
view.addGestureRecognizer(gesture)
view.clipsToBounds = true view.clipsToBounds = true
view.layer.cornerRadius = 24 view.layer.cornerRadius = 24
...@@ -260,11 +264,6 @@ extension WidgetPromotionController: UIScrollViewDelegate { ...@@ -260,11 +264,6 @@ extension WidgetPromotionController: UIScrollViewDelegate {
if scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.frame.height { if scrollView.contentOffset.y == scrollView.contentSize.height - scrollView.frame.height {
AppAnalytics.shared.log(event: .ANALYTICS_WIDGET_BOTTOM_SCROLLED) AppAnalytics.shared.log(event: .ANALYTICS_WIDGET_BOTTOM_SCROLLED)
} }
// if scrollView.contentOffset.y < 0 {
// let originalOffsetY = UIScreen.main.bounds.height - self.view.bounds.height
// view.frame.origin.y = originalOffsetY - (scrollView.contentOffset.y - initialTouchPoint.y)
// return
// }
} }
} }
...@@ -272,27 +271,17 @@ extension WidgetPromotionController: UIScrollViewDelegate { ...@@ -272,27 +271,17 @@ extension WidgetPromotionController: UIScrollViewDelegate {
//MARK:- UIGesture Delegate //MARK:- UIGesture Delegate
@available(iOS 14, *) @available(iOS 14, *)
extension WidgetPromotionController: UIGestureRecognizerDelegate { extension WidgetPromotionController: UIGestureRecognizerDelegate {
// func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// if scrollView.contentOffset.y > 0 { let gesture = (gestureRecognizer as! UIPanGestureRecognizer)
// return false let direction = gesture.velocity(in: view).y
// }
// let y = view.frame.minY
// scrollView.contentOffset.y = 0 if (y == fullView && scrollView.contentOffset.y == 0 && direction > 0) || (y == partialView) {
// return true scrollView.isScrollEnabled = false
// } } else {
scrollView.isScrollEnabled = true
// func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, }
// shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// // Do not begin the pan until the swipe fails. return false
// if otherGestureRecognizer != self.panGesture { }
// print("ScrollView Offset \(scrollView.contentOffset.y)")
// if scrollView.contentOffset.y >= 0 {
// return false
// }
//
// return true
// }
//
// return false
// }
} }
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