mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
71f634bec4
commit_hash:89fe30647b25dbbfb4349af0173ca6023d3a2e29
38 lines
1016 B
Swift
38 lines
1016 B
Swift
import DivKit
|
|
import Foundation
|
|
import UIKit
|
|
|
|
final class SampleDivActionHandler: DivUrlHandler {
|
|
weak var hostViewController: UIViewController?
|
|
|
|
init(hostViewController: UIViewController) {
|
|
self.hostViewController = hostViewController
|
|
}
|
|
|
|
func handle(_ url: URL, info _: DivActionInfo, sender _: AnyObject?) {
|
|
guard let components = url.components, components.scheme == scheme else {
|
|
return
|
|
}
|
|
|
|
switch components.host {
|
|
case "toast":
|
|
if let text = components.queryItems?.first?.name, let hostViewController {
|
|
showAlert(on: hostViewController, message: text)
|
|
}
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
private let scheme = "sample-action"
|
|
|
|
private func showAlert(
|
|
on viewController: UIViewController,
|
|
message: String
|
|
) {
|
|
let alert = UIAlertController(title: "Sample alert", message: message, preferredStyle: .alert)
|
|
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
|
|
viewController.present(alert, animated: true, completion: nil)
|
|
}
|