<commit_before>//
//  ViewController.swift
//  TransitionRouter
//
//  Created by <NAME> on 06/12/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

extension UIButton {
    
    static func custom(with text: String) -> UIButton {
        let button = UIButton(type: .custom)
        button.setTitle(text, for: .normal)
        return button
    }
}

class FirstViewController: UIViewController {
    
    private let topInteractiveRouter = TransitionRouter(type: .top, interactive: true)
    private let leftInteractiveRouter = TransitionRouter(type: .left, interactive: true)
    private let bottomInteractiveRouter = TransitionRouter(type: .bottom, interactive: true)
    private let rightInteractiveRouter = TransitionRouter(type: .right, interactive: true)
    
    private var selectedRouter: TransitionRouter? {
        didSet {
            let vc = ColorViewController(color: .blue)
            vc.transitioningDelegate = selectedRouter
            present(vc, animated: true)
        }
    }
    
    private let topButton: UIButton = .custom(with: "Top")
    private let leftButton: UIButton = .custom(with: "Left")
    private let bottomButton: UIButton = .custom(with: "Bottom")
    private let rightButton: UIButton = .custom(with: "Right")
    
    //MARK: - Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red
        
        topButton.addTarget(self, action: #selector(topAction), for: .touchUpInside)
        view.addSubview(topButton)
        leftButton.addTarget(self, action: #selector(leftAction), for: .touchUpInside)
        view.addSubview(leftButton)
        bottomButton.addTarget(self, action: #selector(bottomAction), for: .touchUpInside)
        view.addSubview(bottomButton)
        rightButton.addTarget(self, action: #selector(rightAction), for: .touchUpInside)
        view.addSubview(rightButton)
        
//        configureTopInteractiveRouter()
        configureLeftInteractiveRouter()
//        configureBottomInteractiveRouter()
        configureRightInteractiveRouter()
    }
    
    override func viewDidLayoutSubviews() {
        let inset: CGFloat = 100
        topButton.center = CGPoint(x: view.center.x, y: view.center.y - inset)
        leftButton.center = CGPoint(x: view.center.x - inset, y: view.center.y)
        bottomButton.center = CGPoint(x: view.center.x, y: view.center.y + inset)
        rightButton.center = CGPoint(x: view.center.x + inset, y: view.center.y)
        
        let buttons = [topButton, leftButton, bottomButton, rightButton]
        
        for button in buttons {
            button.frame.size = CGSize(width: 100, height: 20)
        }
    }
    
    override var prefersStatusBarHidden: Bool {
        return true
    }
    
    //MARK: - Configuration
    
    func configureLeftInteractiveRouter() {
        let leftRecognizer = UIScreenEdgePanGestureRecognizer()
        leftRecognizer.edges = .left
        leftInteractiveRouter
            .add(leftRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .green)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(leftRecognizer)
    }
    
    func configureTopInteractiveRouter() {
        let topRecognizer = UIPanGestureRecognizer()
        topInteractiveRouter
            .add(topRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .yellow)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(topRecognizer)
    }
    
    func configureBottomInteractiveRouter() {
        let bottomRecognizer = UIPanGestureRecognizer()
        bottomInteractiveRouter
            .add(bottomRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .brown)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(bottomRecognizer)
    }
    
    func configureRightInteractiveRouter() {
        let rightRecognizer = UIScreenEdgePanGestureRecognizer()
        rightRecognizer.edges = .right
        rightInteractiveRouter
            .add(rightRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .orange)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(rightRecognizer)<commit_msg>Add one interactive router<commit_after>//
//  ViewController.swift
//  TransitionRouter
//
//  Created by <NAME> on 06/12/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

extension UIButton {
    
    static func custom(with text: String) -> UIButton {
        let button = UIButton(type: .custom)
        button.setTitle(text, for: .normal)
        return button
    }
}

class FirstViewController: UIViewController {
    
    private var selectedRouter: TransitionRouter? {
        didSet {
            let vc = ColorViewController(color: .blue)
            vc.transitioningDelegate = selectedRouter
            present(vc, animated: true)
        }
    }
    private var interactiveRouter: TransitionRouter!
    
    private let topButton: UIButton = .custom(with: "Top")
    private let leftButton: UIButton = .custom(with: "Left")
    private let bottomButton: UIButton = .custom(with: "Bottom")
    private let rightButton: UIButton = .custom(with: "Right")
    
    //MARK: - Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red
        
        topButton.addTarget(self, action: #selector(topAction), for: .touchUpInside)
        view.addSubview(topButton)
        leftButton.addTarget(self, action: #selector(leftAction), for: .touchUpInside)
        view.addSubview(leftButton)
        bottomButton.addTarget(self, action: #selector(bottomAction), for: .touchUpInside)
        view.addSubview(bottomButton)
        rightButton.addTarget(self, action: #selector(rightAction), for: .touchUpInside)
        view.addSubview(rightButton)
        
        //        Uncomment one of configuration for testing
        //        configureTopInteractiveRouter()
        //        configureLeftInteractiveRouter()
        //        configureBottomInteractiveRouter()
        configureRightInteractiveRouter()
    }
    
    override func viewDidLayoutSubviews() {
        let inset: CGFloat = 100
        topButton.center = CGPoint(x: view.center.x, y: view.center.y - inset)
        leftButton.center = CGPoint(x: view.center.x - inset, y: view.center.y)
        bottomButton.center = CGPoint(x: view.center.x, y: view.center.y + inset)
        rightButton.center = CGPoint(x: view.center.x + inset, y: view.center.y)
        
        let buttons = [topButton, leftButton, bottomButton, rightButton]
        
        for button in buttons {
            button.frame.size = CGSize(width: 100, height: 20)
        }
    }
    
    override var prefersStatusBarHidden: Bool {
        return true
    }
    
    //MARK: - Configuration
    
    func configureLeftInteractiveRouter() {
        let leftRecognizer = UIScreenEdgePanGestureRecognizer()
        leftRecognizer.edges = .left
        interactiveRouter = TransitionRouter(type: .left, interactive: true)
        interactiveRouter
            .add(leftRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .green)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(leftRecognizer)
    }
    
    func configureTopInteractiveRouter() {
        let topRecognizer = UIPanGestureRecognizer()
        interactiveRouter = TransitionRouter(type: .top, interactive: true)
        interactiveRouter
            .add(topRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .yellow)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(topRecognizer)
    }
    
    func configureBottomInteractiveRouter() {
        let bottomRecognizer = UIPanGestureRecognizer()
        interactiveRouter = TransitionRouter(type: .bottom, interactive: true)
        interactiveRouter
            .add(bottomRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .brown)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(bottomRecognizer)
    }
    
    func configureRightInteractiveRouter() {
        let rightRecognizer = UIScreenEdgePanGestureRecognizer()
        rightRecognizer.edges = .right
        interactiveRouter = TransitionRouter(type: .right, interactive: true)
        interactiveRouter
            .add(rightRecognizer)
            .transition { [unowned self] router in
                let vc = ColorViewController(color: .orange)
                vc.transitioningDelegate = router
                self.present(vc, animated: true)
        }
        view.addGestureRecognizer(rightRecognizer)
{'fraction_non_alphanumeric': 0.08734177215189873, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 2.3254998246229395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3094586', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2491, 'n_words': 574}