<commit_before>//
//  NavigationNotice.swift
//  NavigationNotice
//
//  Created by <NAME> on 2015/02/06.
//  Copyright (c) 2015年 kyohei_ito. All rights reserved.
//

import UIKit

open class NavigationNotice {
    class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
        class HitView: UIView {
            override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                if let superView = super.hitTest(point, with: event) {
                    if superView != self {
                        return superView
                    }
                }
                return nil
            }
        }
        
        class HitScrollView: UIScrollView {
            override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                if let superView = super.hitTest(point, with: event) {
                    if superView != self {
                        return superView
                    }
                }
                return nil
            }
        }
        
        fileprivate var position: NoticePosition = .top
        fileprivate lazy var panGesture: UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(ViewController.panGestureAction(_:)))
        fileprivate var scrollPanGesture: UIPanGestureRecognizer? {
            return noticeView.gestureRecognizers?.filter({ $0 as? UIPanGestureRecognizer != nil }).first as? UIPanGestureRecognizer
        }
        fileprivate lazy var noticeView: HitScrollView = HitScrollView(frame: self.view.bounds)
        fileprivate weak var targetView: UIView? {
            didSet { targerWindow = targetView?.window }
        }
        fileprivate weak var targerWindow: UIWindow?
        fileprivate var targetController: UIViewController? {
            return targerWindow?.rootViewController
        }
        fileprivate var childController: UIViewController? {
            return targetController?.presentedViewController ?? targetController
        }
        fileprivate var contentView: UIView?
        fileprivate var autoHidden: Bool = false
        fileprivate var hiddenTimeInterval: TimeInterval = 0
        fileprivate var contentHeight: CGFloat {
            return noticeView.bounds.height
        }
        fileprivate var contentOffsetY: CGFloat {
            set { noticeView.contentOffset.y = newValue }
            get { return noticeView.contentOffset.y }
        }
        fileprivate var hiddenTimer: Timer? {
            didSet {
                oldValue?.invalidate()
            }
        }
        
        var showAnimations: ((@escaping () -> Void, @escaping (Bool) -> Void) -> Void)?
        var hideAnimations: ((@escaping () -> Void, @escaping (Bool) -> Void) -> Void)?
        var hideCompletionHandler: (() -> Void)?
        
        override var shouldAutorotate : Bool {
            return childController?.shouldAutorotate
                ?? super.shouldAutorotate
        }
        
        override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
            return childController?.supportedInterfaceOrientations
                ?? super.supportedInterfaceOrientations
        }
        
        override var preferredInterfaceOrientationForPresentation : UIInterfaceOrientation {
            return childController?.preferredInterfaceOrientationForPresentation
                ?? super.preferredInterfaceOrientationForPresentation
        }
        
        override var childViewControllerForStatusBarStyle : UIViewController? {
            return childController
        }
        
        override var childViewControllerForStatusBarHidden : UIViewController? {
            return childController
        }
        
        override func loadView() {
            super.loadView()
            view = HitView(frame: view.bounds)
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            panGesture.delegate = self
            
            noticeView.clipsToBounds = false
            noticeView.showsVerticalScrollIndicator = false
            noticeView.isPagingEnabled = true
            noticeView.bounces = false
            noticeView.delegate = self
            switch position {
            case .top:
                noticeView.autoresizingMask = .flexibleWidth
            case .bottom:
                noticeView.autoresizingMask = [.flexibleWidth, .flexibleTopMargin, .flexibleBottomMargin]
            }
            view.addSubview(noticeView)
        }
        
        func setInterval(_ interval: TimeInterval) {
            hiddenTimeInterval = interval
            
            if interval >= 0 {
                autoHidden = true
                
                if panGesture.view != nil {
                    timer(interval)
                }
            } else {
                autoHidden = false
            }
        }
        
        func setContent(_ view: UIView) {
            contentView = view
        }
        
        func removeContent() {<commit_msg>Lay out content size width in viewDidLayoutSubviews<commit_after>//
//  NavigationNotice.swift
//  NavigationNotice
//
//  Created by <NAME> on 2015/02/06.
//  Copyright (c) 2015年 kyohei_ito. All rights reserved.
//

import UIKit

open class NavigationNotice {
    class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
        class HitView: UIView {
            override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                if let superView = super.hitTest(point, with: event) {
                    if superView != self {
                        return superView
                    }
                }
                return nil
            }
        }
        
        class HitScrollView: UIScrollView {
            override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                if let superView = super.hitTest(point, with: event) {
                    if superView != self {
                        return superView
                    }
                }
                return nil
            }
        }
        
        fileprivate var position: NoticePosition = .top
        fileprivate lazy var panGesture: UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(ViewController.panGestureAction(_:)))
        fileprivate var scrollPanGesture: UIPanGestureRecognizer? {
            return noticeView.gestureRecognizers?.filter({ $0 as? UIPanGestureRecognizer != nil }).first as? UIPanGestureRecognizer
        }
        fileprivate lazy var noticeView: HitScrollView = HitScrollView(frame: self.view.bounds)
        fileprivate weak var targetView: UIView? {
            didSet { targerWindow = targetView?.window }
        }
        fileprivate weak var targerWindow: UIWindow?
        fileprivate var targetController: UIViewController? {
            return targerWindow?.rootViewController
        }
        fileprivate var childController: UIViewController? {
            return targetController?.presentedViewController ?? targetController
        }
        fileprivate var contentView: UIView?
        fileprivate var autoHidden: Bool = false
        fileprivate var hiddenTimeInterval: TimeInterval = 0
        fileprivate var contentHeight: CGFloat {
            return noticeView.bounds.height
        }
        fileprivate var contentOffsetY: CGFloat {
            set { noticeView.contentOffset.y = newValue }
            get { return noticeView.contentOffset.y }
        }
        fileprivate var hiddenTimer: Timer? {
            didSet {
                oldValue?.invalidate()
            }
        }
        
        var showAnimations: ((@escaping () -> Void, @escaping (Bool) -> Void) -> Void)?
        var hideAnimations: ((@escaping () -> Void, @escaping (Bool) -> Void) -> Void)?
        var hideCompletionHandler: (() -> Void)?
        
        override var shouldAutorotate : Bool {
            return childController?.shouldAutorotate
                ?? super.shouldAutorotate
        }
        
        override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
            return childController?.supportedInterfaceOrientations
                ?? super.supportedInterfaceOrientations
        }
        
        override var preferredInterfaceOrientationForPresentation : UIInterfaceOrientation {
            return childController?.preferredInterfaceOrientationForPresentation
                ?? super.preferredInterfaceOrientationForPresentation
        }
        
        override var childViewControllerForStatusBarStyle : UIViewController? {
            return childController
        }
        
        override var childViewControllerForStatusBarHidden : UIViewController? {
            return childController
        }
        
        override func loadView() {
            super.loadView()
            view = HitView(frame: view.bounds)
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            panGesture.delegate = self
            
            noticeView.clipsToBounds = false
            noticeView.showsVerticalScrollIndicator = false
            noticeView.isPagingEnabled = true
            noticeView.bounces = false
            noticeView.delegate = self
            switch position {
            case .top:
                noticeView.autoresizingMask = .flexibleWidth
            case .bottom:
                noticeView.autoresizingMask = [.flexibleWidth, .flexibleTopMargin, .flexibleBottomMargin]
            }
            view.addSubview(noticeView)
        }
        
        override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            noticeView.contentSize.width = view.bounds.width
        }
        
        func setInterval(_ interval: TimeInterval) {
            hiddenTimeInterval = interval
            
            if interval >= 0 {
                autoHidden = true
                
                if panGesture.view != nil {
                    timer(interval)
                }
            } else {
                autoHidden = false
            }
        }
        
        func setContent(_ view: UIView) {
            contentView = view
        }
        
        func removeContent() {
{'fraction_non_alphanumeric': 0.06732253086419752, 'fraction_numerical': 0.0028935185185185184, 'mean_word_length': 1.7002604166666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4725143', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2400, 'n_words': 582}