<commit_before>//
//  IGSnapProgressView.swift
//  InstagramStories
//
//  Created by <NAME> on 9/15/17.
//  Copyright © 2017 Dash. All rights reserved.
//

import UIKit

protocol ViewAnimator:class {
    func start(with duration:TimeInterval,width:CGFloat, completion:@escaping (_ storyIdentifier: String, _ isCancelledAbruptly: Bool) -> Void)
    func resume()
    func pause()
    func stop()
    func reset()
}
extension ViewAnimator where Self:IGSnapProgressView {
    func start(with duration:TimeInterval,width:CGFloat, completion: @escaping (_ storyIdentifier: String, _ isCancelledAbruptly: Bool) -> Void){
        //self.isCancelledAbruptly = false
        UIView.animate(withDuration: duration, delay: 0.0, options: [.curveLinear], animations: {[weak self] in
            self?.frame.size.width = width
        }) { (finished) in
            if finished == true {
                completion(self.story_identifier!, self.isCancelledAbruptly)
            }
        }
    }
    func resume() {
        let pausedTime = layer.timeOffset
        layer.speed = 1.0
        layer.timeOffset = 0.0
        layer.beginTime = 0.0
        let timeSincePause = layer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
        layer.beginTime = timeSincePause
    }
    func pause() {
        let pausedTime = layer.convertTime(CACurrentMediaTime(), from: nil)
        layer.speed = 0.0
        layer.timeOffset = pausedTime
    }
    func stop() {
        resume()
        layer.removeAllAnimations()
    }
    func reset() {
        self.isCancelledAbruptly = true
        self.frame.size.width = 0
    }
}

final class IGSnapProgressView:UIView,ViewAnimator{
    public var story_identifier:String?
    public var isCancelledAbruptly: Bool = false
}
<commit_msg>Fixed progressor doesn't start for some snaps if progress cancelled abruptly<commit_after>//
//  IGSnapProgressView.swift
//  InstagramStories
//
//  Created by <NAME> on 9/15/17.
//  Copyright © 2017 Dash. All rights reserved.
//

import UIKit

protocol ViewAnimator:class {
    func start(with duration:TimeInterval,width:CGFloat, completion:@escaping (_ storyIdentifier: String, _ isCancelledAbruptly: Bool) -> Void)
    func resume()
    func pause()
    func stop()
    func reset()
}
extension ViewAnimator where Self:IGSnapProgressView {
    func start(with duration:TimeInterval,width:CGFloat, completion: @escaping (_ storyIdentifier: String, _ isCancelledAbruptly: Bool) -> Void){
        UIView.animate(withDuration: duration, delay: 0.0, options: [.curveLinear], animations: {[weak self] in
            if let _self = self {
                _self.frame.size.width = width
            }
        }) { [weak self](finished) in
            if finished == true {
                if let _self = self {
                    let cancelledAbruptly = _self.isCancelledAbruptly
                    _self.isCancelledAbruptly = false
                    completion(_self.story_identifier!, cancelledAbruptly)
                }
            }
        }
    }
    func resume() {
        let pausedTime = layer.timeOffset
        layer.speed = 1.0
        layer.timeOffset = 0.0
        layer.beginTime = 0.0
        let timeSincePause = layer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
        layer.beginTime = timeSincePause
    }
    func pause() {
        let pausedTime = layer.convertTime(CACurrentMediaTime(), from: nil)
        layer.speed = 0.0
        layer.timeOffset = pausedTime
    }
    func stop() {
        resume()
        layer.removeAllAnimations()
    }
    func reset() {
        self.isCancelledAbruptly = true
        self.frame.size.width = 0
    }
}

final class IGSnapProgressView:UIView,ViewAnimator{
    public var story_identifier:String?
    public var isCancelledAbruptly: Bool = false
}

{'fraction_non_alphanumeric': 0.09813207050776111, 'fraction_numerical': 0.010523546435148644, 'mean_word_length': 2.4816849816849818, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5039674', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1107, 'n_words': 266}