alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
2.04k stars 212 forks source link

convert the delegate design to support closure #191

Open av-feaster opened 1 year ago

av-feaster commented 1 year 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 9 months ago

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

abbassabeti commented 4 months ago

@alexiscreuzot Please have a look at This PR.