alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
1.99k stars 210 forks source link

convert the delegate design to support closure #191

Open av-feaster opened 10 months ago

av-feaster commented 10 months ago

delegate doesn't make the function flexible . Should I get the callback when the gif is loaded or couldn't be loaded using the escaping closure just like sd_webimage `

   public enum GifEvent {
    case didStart
    case didLoop
    case didStop
    case didFinish
    case didFail(URL, Error?)
}
public struct GifCallbackData {
    public let sender: UIImageView
    public let event: GifEvent
}

public typealias GifCallback = (GifCallbackData) -> Void

   func setGifFromURL(_ url: URL,
                       manager: SwiftyGifManager = .defaultManager,
                       loopCount: Int = -1,
                       levelOfIntegrity: GifLevelOfIntegrity = .default,
                       session: URLSession = URLSession.shared,
                       showLoader: Bool = true,
                       customLoader: UIView? = nil,
callback:@escaping GifCallback = {_ in }) -> URLSessionDataTask?

`

alexiscreuzot commented 5 months ago

not sure about converting it but we could have it as another usage option. Could you do a PR?

abbassabeti commented 3 weeks ago

@alexiscreuzot Please have a look at This PR.