In the WWDC 2026 sessions it was called out in code that the helper functions would still work, however they don't seem to be working either inside a UIViewRepresentable, nor as a UIKit View as below (also tried as a sheet, to no avail).
Otherwise it works. Is there something else I'm missing?
import SwiftUI
import ImagePlayground
@available(iOS 27.0, *)
final class ImagePlaygroundPopupController: UIViewController {
var sourceImage: UIImage
var prompt: String
var onComplete: (URL) -> Void
var onCancel: () -> Void
private var didPresent = false
private var playgroundVC: ImagePlaygroundViewController?
init(
sourceImage: UIImage,
prompt: String,
onComplete: @escaping (URL) -> Void,
onCancel: @escaping () -> Void
) {
self.sourceImage = sourceImage
self.prompt = prompt
self.onComplete = onComplete
self.onCancel = onCancel
super.init(nibName: nil, bundle: nil)
view.backgroundColor = .clear
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard !didPresent else { return }
didPresent = true
let vc = ImagePlaygroundViewController()
vc.sourceImage = sourceImage
vc.concepts = [.text(prompt)]
vc.delegate = self
playgroundVC = vc
present(vc, animated: true)
}
}
@available(iOS 27.0, *)
extension ImagePlaygroundPopupController: ImagePlaygroundViewController.Delegate {
func imagePlaygroundViewController(
_ imagePlaygroundViewController: ImagePlaygroundViewController,
didCreateImageAt imageURL: URL
) {
imagePlaygroundViewController.dismiss(animated: true) {
self.playgroundVC = nil
self.onComplete(imageURL)
}
}
func imagePlaygroundViewControllerDidCancel(
_ imagePlaygroundViewController: ImagePlaygroundViewController
) {
imagePlaygroundViewController.dismiss(animated: true) {
self.playgroundVC = nil
self.onCancel()
}
}
}
@available(iOS 27.0, *)
struct ImagePlaygroundPopupView: UIViewControllerRepresentable {
let sourceImage: UIImage
let prompt: String
let onComplete: (URL) -> Void
let onCancel: () -> Void
func makeUIViewController(context: Context) -> ImagePlaygroundPopupController {
ImagePlaygroundPopupController(
sourceImage: sourceImage,
prompt: prompt,
onComplete: onComplete,
onCancel: onCancel
)
}
func updateUIViewController(
_ uiViewController: ImagePlaygroundPopupController,
context: Context
) {}
}
0
0
24