//
//  InfiniteScrollActivityView.swift
//  MockTumblrFeed
//
//  Created by Ashwin Gupta on 2/10/17.
//  Copyright © 2017 Ashwin Gupta. All rights reserved.
//

import UIKit

class InfiniteScrollActivityView: UIView {
    var activityIndicatorView: UIActivityIndicatorView = UIActivityIndicatorView()
    static let defaultHeight: CGFloat = 60.0
    
    required init?(coder aDecoder: NSCoder){
        super.init(coder: aDecoder)
        setupActivityIndicator()
    }
    
    override init(frame aRect: CGRect){
        super.init(frame: aRect)
        setupActivityIndicator()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        activityIndicatorView.center = CGPoint(x: self.bounds.width/2, y:self.bounds.height/2)
    }
    
    func setupActivityIndicator(){
        activityIndicatorView.activityIndicatorViewStyle = .gray
        activityIndicatorView.hidesWhenStopped = true
        self.addSubview(activityIndicatorView)
    }
    
    func stopAnimating(){
        self.activityIndicatorView.stopAnimating()
        self.isHidden = true
    }
    
    func startAnimating(){
        self.isHidden = false
        self.activityIndicatorView.startAnimating()
    }

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
