         return isInteractive ? interactiveTransition : nil
     }
 }
+
+extension ModalTransitionDelegate: UIGestureRecognizerDelegate {
+    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
+        let location = gestureRecognizer.location(in: presentedViewController?.view)
+        if location.y < 0 {
+            return true
+        } else {
+            return false
+        }
+    }
+}


    private func reset() {
        isInteractive = false
        if let gr = gestureRecognizer {
            UIApplication.shared.keyWindow?.removeGestureRecognizer(gr)
        }
    }
}

extension ModalTransitionDelegate: UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        presentedViewController = presenting
        return PresentModalAnimator(completion: {
            let gr = UIPanGestureRecognizer(target: self, action: #selector(ModalTransitionDelegate.didUpdate(gr:)))
            UIApplication.shared.keyWindow?.addGestureRecognizer(gr)
            self.gestureRecognizer = gr
        })
    }


        }
    }

    @objc func didTap(gr: UITapGestureRecognizer) {
        reset()
        presentedViewController?.dismiss(animated: true, completion: {})
    }

    private var transitionShouldFinish: Bool {
        if progress > progressThreshold || yVelocity > velocityThreshold {
            return true
