Files
burstein 71f634bec4 DivKit SwiftUI Sample App
commit_hash:89fe30647b25dbbfb4349af0173ca6023d3a2e29
2025-07-04 00:17:17 +03:00

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)
}