<commit_before>//
//  YJUIViewControllerTransitioning.swift
//  YJCocoa
//
//  HomePage:https://github.com/937447974/YJCocoa
//  YJ技术支持群:557445088
//
//  Created by 阳君 on 2019/6/19.
//  Copyright © 2016-现在 YJCocoa. All rights reserved.
//

import UIKit

/// UIViewController Present Dismiss 转场动画
@objcMembers
open class YJUIViewControllerTransitioning: NSObject {
    
    /// push 动画
    public var pushAT: YJUIViewControllerAnimatedTransitioning?
    /// pop 动画
    public var popAT: YJUIViewControllerAnimatedTransitioning?
    /// pop 的视图
    public weak var popVC: UIViewController? {
        willSet {
            newValue?.view.addGestureRecognizer(self.popGesture)
        }
    }
    /// pop 的手势
    public private(set) lazy var popGesture: UIPanGestureRecognizer = {
        let gesture = UIPanGestureRecognizer()
        gesture.addTarget(self, action: #selector(YJUIViewControllerTransitioning.panGestureRecognizerAction(pan:)))
        return gesture
    }()
    var popIT: UIPercentDrivenInteractiveTransition?
    
    /// 属性设置
    /// - parameter pushAT: push 动画
    /// - parameter popAT: pop 动画
    /// - parameter popVC: pop 的视图
    open func setPushAT(_ pushAT: YJUIViewControllerAnimatedTransitioning, popAT: YJUIViewControllerAnimatedTransitioning, popVC: UIViewController) {
        self.pushAT = pushAT
        self.popAT = popAT
        self.popVC = popVC
    }
    
    @objc
    func panGestureRecognizerAction(pan: UIPanGestureRecognizer) {
        var process = pan.translation(in: self.popVC!.view).x / self.popVC!.view.frameWidth
        process = min(1.0, max(0, process))
        switch pan.state {
        case .began:
            self.popIT = UIPercentDrivenInteractiveTransition()
            if let nc = self.popVC?.navigationController, nc.viewControllers.count > 1 {
                nc.popViewController(animated: true)
            } else {
                self.popVC?.dismiss(animated: true, completion: nil)
            }
        case.changed:
            self.popIT?.update(process)
        case .ended, .cancelled:
            if (process > 0.5) {
                self.popIT?.finish()
            } else {
                self.popIT?.cancel()
            }
            self.popIT = nil
        default:
            break
        }
    }
    
}

extension YJUIViewControllerTransitioning: UIViewControllerTransitioningDelegate {
    
    public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return self.pushAT
    }
    
    public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return self.popAT
    }
    
    public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return self.popIT
    }
    
}

extension YJUIViewControllerTransitioning: UINavigationControllerDelegate {
    
    public func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return animationController.isEqual(self.popAT) ? self.popIT : nil;
    }
    
    
    public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        switch operation {
        case .push: return self.pushAT
        case .pop:  return self.popAT<commit_msg>feat: 跳转动画增加自定义设置<commit_after>//
//  YJUIViewControllerTransitioning.swift
//  YJCocoa
//
//  HomePage:https://github.com/937447974/YJCocoa
//  YJ技术支持群:557445088
//
//  Created by 阳君 on 2019/6/19.
//  Copyright © 2016-现在 YJCocoa. All rights reserved.
//

import UIKit

/// UIViewController Present Dismiss 转场动画
@objcMembers
open class YJUIViewControllerTransitioning: NSObject {
    
    /// push 动画
    public var pushAT: YJUIViewControllerAnimatedTransitioning?
    /// pop 动画
    public var popAT: YJUIViewControllerAnimatedTransitioning?
    /// 自定义 UIPresentationController 管理动画
    public var presentationControllerClass: UIPresentationController.Type?
    /// pop 的视图
    public weak var popVC: UIViewController? {
        willSet {
            newValue?.view.addGestureRecognizer(self.popGesture)
        }
    }
    /// pop 的手势
    public private(set) lazy var popGesture: UIPanGestureRecognizer = {
        let gesture = UIPanGestureRecognizer()
        gesture.addTarget(self, action: #selector(YJUIViewControllerTransitioning.panGestureRecognizerAction(pan:)))
        return gesture
    }()
    var popIT: UIPercentDrivenInteractiveTransition?
    
    public init(popVC: UIViewController? = nil) {
        super.init()
        self.popVC = popVC
    }
    
    /// 属性设置
    /// - parameter pushAT: push 动画
    /// - parameter popAT: pop 动画
    open func setPushAT(_ pushAT: YJUIViewControllerAnimatedTransitioning, popAT: YJUIViewControllerAnimatedTransitioning) {
        self.pushAT = pushAT
        self.popAT = popAT
    }
    
    @objc
    func panGestureRecognizerAction(pan: UIPanGestureRecognizer) {
        var process = pan.translation(in: self.popVC!.view).x / self.popVC!.view.frameWidth
        process = min(1.0, max(0, process))
        switch pan.state {
        case .began:
            self.popIT = UIPercentDrivenInteractiveTransition()
            if let nc = self.popVC?.navigationController, nc.viewControllers.count > 1 {
                nc.popViewController(animated: true)
            } else {
                self.popVC?.dismiss(animated: true, completion: nil)
            }
        case.changed:
            self.popIT?.update(process)
        case .ended, .cancelled:
            if (process > 0.5) {
                self.popIT?.finish()
            } else {
                self.popIT?.cancel()
            }
            self.popIT = nil
        default:
            break
        }
    }
    
}

extension YJUIViewControllerTransitioning: UIViewControllerTransitioningDelegate {
    
    public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return self.pushAT
    }
    
    public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return self.popAT
    }
    
    public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return self.popIT
    }
    
    public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        return self.presentationControllerClass?.init(presentedViewController: presented, presenting: presenting)
    }
    
}

extension YJUIViewControllerTransitioning: UINavigationControllerDelegate {
    
    public func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return animationController.isEqual(self.popAT) ? self.popIT : nil;
    }
    
    
    public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        switch operation {
        case .push: return self.pushAT
        case .pop:  return self.popAT
{'fraction_non_alphanumeric': 0.08047442928197934, 'fraction_numerical': 0.008927432725417676, 'mean_word_length': 2.893743793445879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '988673', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2184, 'n_words': 451}