<commit_before>//
//  QHNavigationController.swift
//  QHAwemeDemo
//
//  Created by <NAME> on 2017/10/23.
//  Copyright © 2017年 AnakinChen Network Technology. All rights reserved.
//

import UIKit

@objc protocol QHNavigationControllerProtocol : NSObjectProtocol {
    //页面是否有push的Action
    @objc optional func navigationControllerShouldPush(_ vc: QHNavigationController) -> Bool
    
    //页面执行push的Action，返回true，会在End触发rootView的End回调事件（暂时为了业务需求，后期寻找优化方案）
    @objc optional func navigationControllerDidPushBegin(_ vc: QHNavigationController) -> Bool
    //只执行rootView
    @objc optional func navigationControllerDidPushEnd(_ vc: QHNavigationController)
    
    //页面是否支持手势push
    func doNavigationControllerGesturePush(_ vc: QHNavigationController) -> Bool
    
    @objc optional func doNavigationControllerGesturePop(_ vc: QHNavigationController) -> Bool
}

class QHNavigationController: UINavigationController, UINavigationControllerDelegate, UIGestureRecognizerDelegate {
    
    var currentShowVC: UIViewController?
    
    var edgePan: UIScreenEdgePanGestureRecognizer?
    
    var transition = QHNavigationControllerTransition()
    var pan: UIPanGestureRecognizer?
    
    var bResetScrollEable = false
    
    //TODO: 暂时使用其他push动画时，禁止手势pop
    var otherTransition: QHNavigationOtherTransition?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.interactivePopGestureRecognizer?.delegate = self as UIGestureRecognizerDelegate;
        self.delegate = self;
        
//        edgePan = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(QHNavigationController.gestureDidPushed(_:)))
//        edgePan?.edges = .right
//        edgePan?.delegate = self
//        self.view.addGestureRecognizer(edgePan!)
        
        pan = UIPanGestureRecognizer(target: self, action: #selector(QHNavigationController.gestureDidPushed(_:)))
        pan?.delegate = self
        self.view.addGestureRecognizer(pan!)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK: Public
    
    func changeTransition(_ bChange: Bool) {
        if bChange == true {
            if otherTransition == nil {
                otherTransition = QHNavigationOtherTransition()
            }
            self.delegate = otherTransition
        }
        else {
            self.delegate = self;
        }
    }
    
    //MARK: UINavigationControllerDelegate
    
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        if navigationController.viewControllers.count == 1 {
            self.currentShowVC = nil
        }
        else if animated {
            self.currentShowVC = viewController
        }
        else {
            self.currentShowVC = nil
        }<commit_msg>【Fix】旋转控制<commit_after>//
//  QHNavigationController.swift
//  QHAwemeDemo
//
//  Created by <NAME> on 2017/10/23.
//  Copyright © 2017年 AnakinChen Network Technology. All rights reserved.
//

import UIKit

@objc protocol QHNavigationControllerProtocol : NSObjectProtocol {
    //页面是否有push的Action
    @objc optional func navigationControllerShouldPush(_ vc: QHNavigationController) -> Bool
    
    //页面执行push的Action，返回true，会在End触发rootView的End回调事件（暂时为了业务需求，后期寻找优化方案）
    @objc optional func navigationControllerDidPushBegin(_ vc: QHNavigationController) -> Bool
    //只执行rootView
    @objc optional func navigationControllerDidPushEnd(_ vc: QHNavigationController)
    
    //页面是否支持手势push
    func doNavigationControllerGesturePush(_ vc: QHNavigationController) -> Bool
    
    @objc optional func doNavigationControllerGesturePop(_ vc: QHNavigationController) -> Bool
}

class QHNavigationController: UINavigationController, UINavigationControllerDelegate, UIGestureRecognizerDelegate {
    
    var currentShowVC: UIViewController?
    
    var edgePan: UIScreenEdgePanGestureRecognizer?
    
    var transition = QHNavigationControllerTransition()
    var pan: UIPanGestureRecognizer?
    
    var bResetScrollEable = false
    
    //TODO: 暂时使用其他push动画时，禁止手势pop
    var otherTransition: QHNavigationOtherTransition?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.interactivePopGestureRecognizer?.delegate = self as UIGestureRecognizerDelegate;
        self.delegate = self;
        
//        edgePan = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(QHNavigationController.gestureDidPushed(_:)))
//        edgePan?.edges = .right
//        edgePan?.delegate = self
//        self.view.addGestureRecognizer(edgePan!)
        
        pan = UIPanGestureRecognizer(target: self, action: #selector(QHNavigationController.gestureDidPushed(_:)))
        pan?.delegate = self
        self.view.addGestureRecognizer(pan!)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override open var shouldAutorotate: Bool {
        if let b = viewControllers.last?.shouldAutorotate {
            return b
        }
        return true
    }
    
    override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return (viewControllers.last?.supportedInterfaceOrientations)!
    }
    
    override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return (viewControllers.last?.preferredInterfaceOrientationForPresentation)!
    }
    
    override open var childViewControllerForStatusBarStyle: UIViewController? {
        return topViewController
    }
    
    //MARK: Public
    
    func changeTransition(_ bChange: Bool) {
        if bChange == true {
            if otherTransition == nil {
                otherTransition = QHNavigationOtherTransition()
            }
            self.delegate = otherTransition
        }
        else {
            self.delegate = self;
        }
    }
    
    //MARK: UINavigationControllerDelegate
    
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        if navigationController.viewControllers.count == 1 {
            self.currentShowVC = nil
        }
        else if animated {
            self.currentShowVC = viewController
        }
        else {
            self.currentShowVC = nil
        }
{'fraction_non_alphanumeric': 0.07344110854503465, 'fraction_numerical': 0.004003079291762895, 'mean_word_length': 2.834710743801653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '5031344', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1850, 'n_words': 368}