<commit_before>//  BSD 2-Clause License
//
//  Copyright (c) 2016 ~ 2020, <NAME>
//  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//  * Redistributions of source code must retain the above copyright notice, this
//  list of conditions and the following disclaimer.
//
//  * Redistributions in binary form must reproduce the above copyright notice,
//  this list of conditions and the following disclaimer in the documentation
//  and/or other materials provided with the distribution.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
//  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
//  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//  ZoomTransitioning.swift
//  UIViewControllerTransitions
//
//  Created by <NAME> on 2020/12/10.
//

import Foundation

final class ZoomTransitioning: AnimatedTransitioning {
    
    // MARK: Internal
    
    override func animateTransition(forDismission transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = fromViewController,
              let toVC = toViewController,
              let id = findId(in: fromVC.view),
              let fromView = findView(withId: id, in: fromVC.view),
              let toView = findView(withId: id, in: toVC.view),
              let snapshotView = fromView.snapshotView(afterScreenUpdates: true) else { return }
        
        let transform = CGAffineTransform(
            scaleX: toView.bounds.size.width / fromView.bounds.size.width,
            y: toView.bounds.size.height / fromView.bounds.size.height)
        
        snapshotView.center = fromView.center
        fromVC.view.alpha = 1
        fromView.isHidden = true
        toView.isHidden = true
        
        transitionContext.containerView.addSubview(snapshotView)
        
        self.snapshotView = snapshotView
        self.fromView = fromView
        self.toView = toView
        self.transform = transform
        
        if transitionContext.isInteractive { return }
        
        animate({
            fromVC.view.alpha = 0
            toVC.view.tintAdjustmentMode = .normal
            snapshotView.center = toView.center
            snapshotView.transform = transform
        },
        completion: { [weak self] in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
            fromVC.view.removeFromSuperview()
            toVC.endAppearanceTransition()
            self?.removeSnapshotView()
            fromView.isHidden = false
            toView.isHidden = false
        })
    }
    
    override func animateTransition(forPresenting transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = fromViewController,
              let toVC = toViewController,
              let id = findId(in: fromVC.view) else { return }
        
        let toVisibleVC = (toVC as? UINavigationController)?.visibleViewController ?? toVC
        
        guard let fromView = findView(withId: id, in: fromVC.view),
              let snapshotView = fromView.snapshotView(afterScreenUpdates: true),
              let toView = findView(withId: id, in: toVisibleVC.view) else { return }
        
        transitionContext.containerView.addSubview(toVC.view)
        transitionContext.containerView.addSubview(snapshotView)
        toVC.view.layoutIfNeeded()
        
        let transform = CGAffineTransform(
            scaleX: toView.bounds.size.width / fromView.bounds.size.width,
            y: toView.bounds.size.height / fromView.bounds.size.height)
        
        snapshotView.center = fromView.center
        toVC.view.alpha = 0
        fromView.isHidden = true
        toView.isHidden = true
        
        self.snapshotView = snapshotView
        self.fromView = fromView
        self.toView = toView
        self.transform = transform
        
        if transitionContext.isInteractive { return }
        
        animate({
            toVC.view.alpha = 1
            fromVC.view.tintAdjustmentMode = .dimmed
            snapshotView.center = toView.center
            snapshotView.transform = transform
        },
        completion: { [weak self] in
            fromView.isHidden = false
            toView.isHidden = false
            fromVC.endAppearanceTransition()
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
            self?.removeSnapshotView()
        })
    }
    
    override func interactionBegan(_ interactor: AbstractInteractiveTransition, transitionContext: UIViewControllerContextTransitioning) {
        super.interactionBegan(interactor, transitionContext: transitionContext)
        belowViewController?.beginAppearanceTransition(!isPresenting, animated: transitionContext.isAnimated)
    }
    
    override func interactionCancelled(_ interactor: AbstractInteractiveTransition, completion: (() -> Void)? = nil) {<commit_msg>Fix incorrect position issue by incorrect coordinates<commit_after>//  BSD 2-Clause License
//
//  Copyright (c) 2016 ~ 2020, <NAME>
//  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//  * Redistributions of source code must retain the above copyright notice, this
//  list of conditions and the following disclaimer.
//
//  * Redistributions in binary form must reproduce the above copyright notice,
//  this list of conditions and the following disclaimer in the documentation
//  and/or other materials provided with the distribution.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
//  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
//  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//  ZoomTransitioning.swift
//  UIViewControllerTransitions
//
//  Created by <NAME> on 2020/12/10.
//

import Foundation

final class ZoomTransitioning: AnimatedTransitioning {
    
    // MARK: Internal
    
    override func animateTransition(forDismission transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = fromViewController,
              let toVC = toViewController,
              let id = findId(in: fromVC.view),
              let fromView = findView(withId: id, in: fromVC.view),
              let toView = findView(withId: id, in: toVC.view),
              let snapshotView = fromView.snapshotView(afterScreenUpdates: true) else { return }
        
        let center = toView.superview?.convert(
            toView.center,
            to: transitionContext.containerView) ?? .zero
        let transform = CGAffineTransform(
            scaleX: toView.bounds.size.width / fromView.bounds.size.width,
            y: toView.bounds.size.height / fromView.bounds.size.height)
        
        snapshotView.center = fromView.center
        fromVC.view.alpha = 1
        fromView.isHidden = true
        toView.isHidden = true
        
        transitionContext.containerView.addSubview(snapshotView)
        
        self.transform = transform
        self.fromView = fromView
        self.snapshotView = snapshotView
        self.toView = toView
        
        if transitionContext.isInteractive { return }
        
        animate({
            fromVC.view.alpha = 0
            toVC.view.tintAdjustmentMode = .normal
            snapshotView.center = center
            snapshotView.transform = transform
        },
        completion: { [weak self] in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
            fromVC.view.removeFromSuperview()
            toVC.endAppearanceTransition()
            self?.removeSnapshotView()
            fromView.isHidden = false
            toView.isHidden = false
        })
    }
    
    override func animateTransition(forPresenting transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = fromViewController,
              let toVC = toViewController,
              let id = findId(in: fromVC.view) else { return }
        
        let toVisibleVC = (toVC as? UINavigationController)?.visibleViewController ?? toVC
        
        guard let fromView = findView(withId: id, in: fromVC.view),
              let snapshotView = fromView.snapshotView(afterScreenUpdates: true),
              let toView = findView(withId: id, in: toVisibleVC.view) else { return }
        
        transitionContext.containerView.addSubview(toVC.view)
        transitionContext.containerView.addSubview(snapshotView)
        toVC.view.layoutIfNeeded()
        
        let center = toView.superview?.convert(
            toView.center,
            to: transitionContext.containerView) ?? .zero
        let transform = CGAffineTransform(
            scaleX: toView.bounds.size.width / fromView.bounds.size.width,
            y: toView.bounds.size.height / fromView.bounds.size.height)
        
        snapshotView.center = fromView.superview?.convert(fromView.center, to: transitionContext.containerView) ?? .zero
        toVC.view.alpha = 0
        fromView.isHidden = true
        toView.isHidden = true
        
        self.transform = transform
        self.fromView = fromView
        self.snapshotView = snapshotView
        self.toView = toView
        
        if transitionContext.isInteractive { return }
        
        animate({
            toVC.view.alpha = 1
            fromVC.view.tintAdjustmentMode = .dimmed
            snapshotView.center = center
            snapshotView.transform = transform
        },
        completion: { [weak self] in
            fromView.isHidden = false
            toView.isHidden = false
            fromVC.endAppearanceTransition()
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
            self?.removeSnapshotView()
        })
    }
    
    override func interactionBegan(_ interactor: AbstractInteractiveTransition, transitionContext: UIViewControllerContextTransitioning) {
        super.interactionBegan(interactor, transitionContext: transitionContext)
        belowViewController?.beginAppearanceTransition(!isPresenting, animated: transitionContext.isAnimated)
    }
    
    override func interactionCancelled(_ interactor: AbstractInteractiveTransition, completion: (() -> Void)? = nil) {
{'fraction_non_alphanumeric': 0.0747703665550691, 'fraction_numerical': 0.0036054596961112542, 'mean_word_length': 2.507979524239687, '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': '1696897', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2908, 'n_words': 841}