<commit_before>//
//  ZoomingImageView.swift
//  Pods
//
//  Created by <NAME> on 5/21/17.
//
//

import UIKit
import FLAnimatedImage

fileprivate let ZoomScaleEpsilon: CGFloat = 0.01

@objc(AXZoomingImageView) class ZoomingImageView: UIScrollView, UIScrollViewDelegate {
    
    var image: UIImage? {
        set(value) {
            self.updateImageView(image: value, animatedImage: nil)
        }
        get {
            return self.imageView.image
        }
    }
    
    var animatedImage: FLAnimatedImage? {
        set(value) {
            self.updateImageView(image: nil, animatedImage: value)
        }
        get {
            return self.imageView.animatedImage
        }
    }
    
    public override var frame: CGRect {
        didSet {
            self.updateZoomScale()
        }
    }
    
    fileprivate(set) var doubleTapGestureRecognizer = UITapGestureRecognizer()
    fileprivate(set) var imageView = FLAnimatedImageView()
    
    fileprivate var needsUpdateImageView = false

    public init() {
        super.init(frame: .zero)
        
        self.doubleTapGestureRecognizer.numberOfTapsRequired = 2
        self.doubleTapGestureRecognizer.addTarget(self, action: #selector(doubleTapAction(_:)))
        self.doubleTapGestureRecognizer.isEnabled = false
        self.addGestureRecognizer(self.doubleTapGestureRecognizer)
        
        self.imageView.layer.masksToBounds = true
        self.imageView.contentMode = .scaleAspectFit
        self.addSubview(self.imageView)
        
        self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.showsVerticalScrollIndicator = false
        self.showsHorizontalScrollIndicator = false
        self.bouncesZoom = true
        self.decelerationRate = UIScrollViewDecelerationRateFast;
        self.delegate = self
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func updateImageView(image: UIImage?, animatedImage: FLAnimatedImage?) {
        self.imageView.transform = .identity
        var imageSize: CGSize = .zero
        
        if let image = image {
            if self.imageView.image != image {
                self.imageView.image = image
            }
            imageSize = image.size
        } else if let animatedImage = animatedImage {
            if self.imageView.animatedImage != animatedImage {
                self.imageView.animatedImage = animatedImage
            }
            imageSize = animatedImage.size
        }
        
        self.imageView.frame = CGRect(origin: .zero, size: imageSize)
        self.contentSize = imageSize
        self.updateZoomScale()
        
        self.doubleTapGestureRecognizer.isEnabled = (image != nil || animatedImage != nil)
        
        self.needsUpdateImageView = false
    }
    
    override func willRemoveSubview(_ subview: UIView) {
        super.willRemoveSubview(subview)
        
        if subview === self.imageView {
            self.needsUpdateImageView = true
        }
    }
    
    override func didAddSubview(_ subview: UIView) {<commit_msg>- ZoomingView scroll disabled by default - Fixed imageView non-nil value when updateImageView is called with nil   values<commit_after>//
//  ZoomingImageView.swift
//  Pods
//
//  Created by <NAME> on 5/21/17.
//
//

import UIKit
import FLAnimatedImage

fileprivate let ZoomScaleEpsilon: CGFloat = 0.01

@objc(AXZoomingImageView) class ZoomingImageView: UIScrollView, UIScrollViewDelegate {
    
    var image: UIImage? {
        set(value) {
            self.updateImageView(image: value, animatedImage: nil)
        }
        get {
            return self.imageView.image
        }
    }
    
    var animatedImage: FLAnimatedImage? {
        set(value) {
            self.updateImageView(image: nil, animatedImage: value)
        }
        get {
            return self.imageView.animatedImage
        }
    }
    
    public override var frame: CGRect {
        didSet {
            self.updateZoomScale()
        }
    }
    
    fileprivate(set) var doubleTapGestureRecognizer = UITapGestureRecognizer()
    fileprivate(set) var imageView = FLAnimatedImageView()
    
    fileprivate var needsUpdateImageView = false

    public init() {
        super.init(frame: .zero)
        
        self.doubleTapGestureRecognizer.numberOfTapsRequired = 2
        self.doubleTapGestureRecognizer.addTarget(self, action: #selector(doubleTapAction(_:)))
        self.doubleTapGestureRecognizer.isEnabled = false
        self.addGestureRecognizer(self.doubleTapGestureRecognizer)
        
        self.imageView.layer.masksToBounds = true
        self.imageView.contentMode = .scaleAspectFit
        self.addSubview(self.imageView)
        
        self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.showsVerticalScrollIndicator = false
        self.showsHorizontalScrollIndicator = false
        self.isScrollEnabled = false
        self.bouncesZoom = true
        self.decelerationRate = UIScrollViewDecelerationRateFast;
        self.delegate = self
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func updateImageView(image: UIImage?, animatedImage: FLAnimatedImage?) {
        self.imageView.transform = .identity
        var imageSize: CGSize = .zero
        
        if let animatedImage = animatedImage {
            if self.imageView.animatedImage != animatedImage {
                self.imageView.animatedImage = animatedImage
            }
            imageSize = animatedImage.size
        } else if let image = image {
            if self.imageView.image != image {
                self.imageView.image = image
            }
            imageSize = image.size
        } else {
            self.imageView.animatedImage = nil
            self.imageView.image = nil
        }
        
        self.imageView.frame = CGRect(origin: .zero, size: imageSize)
        self.contentSize = imageSize
        self.updateZoomScale()
        
        self.doubleTapGestureRecognizer.isEnabled = (image != nil || animatedImage != nil)
        
        self.needsUpdateImageView = false
    }
    
    override func willRemoveSubview(_ subview: UIView) {
        super.willRemoveSubview(subview)
        
        if subview === self.imageView {
            self.needsUpdateImageView = true
        }
    }
    
    override func didAddSubview(_ subview: UIView) {
{'fraction_non_alphanumeric': 0.07948954489544896, 'fraction_numerical': 0.0027675276752767526, 'mean_word_length': 2.1394787644787643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3502575', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1808, 'n_words': 361}