BastiaanJansen / toast-swift

Customizable Swift Toast view built with UIKit. 🍞
MIT License
489 stars 77 forks source link

Add delegate for show and close callbacks. #17

Closed Zandor300 closed 1 year ago

Zandor300 commented 1 year ago

Adds a ToastDelegate per requested in https://github.com/BastiaanJansen/toast-swift/issues/16

Usage

let toast = Toast.text("Safari pasted from Notes", subtitle: "A few seconds ago")
toast.delegate = self
toast.show()

Below delegate functions are optional to implement when implementing ToastDelegate.

extension MyViewController: ToastDelegate {

    func willShowToast(_ toast: Toast) {
        print("Toast will be shown after this")
    }

    func didShowToast(_ toast: Toast) {
        print("Toast was shown")
    }

    func willCloseToast(_ toast: Toast) {
        print("Toast will be closed after this")
    }

    func didCloseToast(_ toast: Toast) {
        print("Toast was closed (either automatically, dismissed by user or programmatically)")
    }

}

Fixes https://github.com/BastiaanJansen/toast-swift/issues/16