<commit_before>import Foundation


final class PopupTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate, OriginHandlerHavableTransitionDelegate,  SizeHandlerHavableTransitionDelgate, DimmedColorHavableTransitionDelegate {
    
    // presentationview 의 size 를 정의 합니다.
    var sizeHandler: SizeHandlerFunc?
    var originHandler: OriginHandlerFunc?
    var dimmedColor: UIColor?
    
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        let presentationController = PopupPresentationController(presentedViewController: presented, presenting: presenting, dimmedColor: dimmedColor)
        presentationController.sizeHandler = sizeHandler
        presentationController.originHandler = originHandler
        return presentationController
    }
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let animationController = PopupAnimatedTransitioning()
        animationController.isPresentation = true
        return animationController
    }
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let animationController = PopupAnimatedTransitioning()
        animationController.isPresentation = false
        return animationController
    }
}

final class PopupPresentationController: UIPresentationController, UIAdaptivePresentationControllerDelegate {
    var chromeView: UIView = UIView()   // 배경을 반투명하게 가리는 검정 배경
    var sizeHandler: SizeHandlerFunc?
    var originHandler: OriginHandlerFunc?
    
    private var isShowKeyboard = false
    
    init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, dimmedColor: UIColor?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
        
        chromeView.backgroundColor = dimmedColor ?? UIColor(white: 0.0, alpha: 0.4)
        chromeView.alpha = 0.0
        chromeView.addGestureRecognizer(
            UITapGestureRecognizer(target: self, action: #selector(PopupPresentationController.chromeViewTapped(_:))))
        
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(PopupPresentationController.keyboardWillShow(_:)),
            name: NSNotification.Name.UIKeyboardWillShow,
            object: nil)
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(PopupPresentationController.keyboardWillHide(_:)),
            name: NSNotification.Name.UIKeyboardWillHide,
            object: nil)
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    
    func keyboardWillShow(_ notification: Foundation.Notification) {
        isShowKeyboard = true
        
        if let userInfo = (notification as NSNotification).userInfo,
            let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            
            // 키보드가 노출 여부가 화면사이즈에 영향을 미치게 합니다.
            containerView?.frame.size.height = keyboardEndFrame.origin.y
        }
    }
    func keyboardWillHide(_ notification: Foundation.Notification) {
        isShowKeyboard = false
        
        if let userInfo = (notification as NSNotification).userInfo,
            let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            
            // 키보드가 노출 여부가 화면사이즈에 영향을 미치게 합니다.
            containerView?.frame.size.height = keyboardEndFrame.origin.y
        }
    }
    
    func chromeViewTapped(_ gesture: UIGestureRecognizer) {
        if(gesture.state == UIGestureRecognizerState.ended) {
            presentedViewController.dismiss(animated: true, completion: nil)
        }
    }
    
    override func size(forChildContentContainer container: UIContentContainer, withParentContainerSize parentSize: CGSize) -> CGSize {
        // 기본적으로는 화면의 80% 할당, sizeHandler 지정되면 handler 에서 지정한 size 로 설정
        if let sizeHandler = sizeHandler {
            return sizeHandler(CGRect(origin: CGPoint.zero, size: parentSize))
        }
        let width = parentSize.width * 0.8
        let height = parentSize.height * 0.8
        return CGSize(width: width, height: height)
    }
    
    override var frameOfPresentedViewInContainerView : CGRect {<commit_msg>popup segue , 키보드 show hide 이벤트 감지 로직 수정 (will -> did)<commit_after>import Foundation


final class PopupTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate, OriginHandlerHavableTransitionDelegate,  SizeHandlerHavableTransitionDelgate, DimmedColorHavableTransitionDelegate {
    
    // presentationview 의 size 를 정의 합니다.
    var sizeHandler: SizeHandlerFunc?
    var originHandler: OriginHandlerFunc?
    var dimmedColor: UIColor?
    
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        let presentationController = PopupPresentationController(presentedViewController: presented, presenting: presenting, dimmedColor: dimmedColor)
        presentationController.sizeHandler = sizeHandler
        presentationController.originHandler = originHandler
        return presentationController
    }
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let animationController = PopupAnimatedTransitioning()
        animationController.isPresentation = true
        return animationController
    }
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        let animationController = PopupAnimatedTransitioning()
        animationController.isPresentation = false
        return animationController
    }
}

final class PopupPresentationController: UIPresentationController, UIAdaptivePresentationControllerDelegate {
    var chromeView: UIView = UIView()   // 배경을 반투명하게 가리는 검정 배경
    var sizeHandler: SizeHandlerFunc?
    var originHandler: OriginHandlerFunc?
    
    private var isShowKeyboard = false
    
    init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, dimmedColor: UIColor?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
        
        chromeView.backgroundColor = dimmedColor ?? UIColor(white: 0.0, alpha: 0.4)
        chromeView.alpha = 0.0
        chromeView.addGestureRecognizer(
            UITapGestureRecognizer(target: self, action: #selector(PopupPresentationController.chromeViewTapped(_:))))
        
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(PopupPresentationController.keyboardDidShow(_:)),
            name: NSNotification.Name.UIKeyboardDidShow,
            object: nil)
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(PopupPresentationController.keyboardDidHide(_:)),
            name: NSNotification.Name.UIKeyboardDidHide,
            object: nil)
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    
    func keyboardDidShow(_ notification: Foundation.Notification) {
        isShowKeyboard = true
        
        if let userInfo = (notification as NSNotification).userInfo,
            let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            
            // 키보드가 노출 여부가 화면사이즈에 영향을 미치게 합니다.
            containerView?.frame.size.height = keyboardEndFrame.origin.y
        }
    }
    func keyboardDidHide(_ notification: Foundation.Notification) {
        isShowKeyboard = false
        
        if let userInfo = (notification as NSNotification).userInfo,
            let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            
            // 키보드가 노출 여부가 화면사이즈에 영향을 미치게 합니다.
            containerView?.frame.size.height = keyboardEndFrame.origin.y
        }
    }
    
    func chromeViewTapped(_ gesture: UIGestureRecognizer) {
        if(gesture.state == UIGestureRecognizerState.ended) {
            presentedViewController.dismiss(animated: true, completion: nil)
        }
    }
    
    override func size(forChildContentContainer container: UIContentContainer, withParentContainerSize parentSize: CGSize) -> CGSize {
        // 기본적으로는 화면의 80% 할당, sizeHandler 지정되면 handler 에서 지정한 size 로 설정
        if let sizeHandler = sizeHandler {
            return sizeHandler(CGRect(origin: CGPoint.zero, size: parentSize))
        }
        let width = parentSize.width * 0.8
        let height = parentSize.height * 0.8
        return CGSize(width: width, height: height)
    }
    
    override var frameOfPresentedViewInContainerView : CGRect {
{'fraction_non_alphanumeric': 0.06643241462611178, 'fraction_numerical': 0.002635335456242451, 'mean_word_length': 3.2323420074349443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '6190164', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2540, 'n_words': 512}