import SwiftUI
import ImagePlayground

struct ContentView: View {
   @State private var openPlayground: Bool = false
   @State private var image = UIImage(named: "nopicture")!
   
   var body: some View {
      VStack {
         Image(uiImage: image)
            .resizable()
            .frame(width: 300, height: 300)
         Button("Create Image") {
            openPlayground = true
         }
         .padding()
         .buttonStyle(.borderedProminent)
         .disabled(openPlayground)
         Spacer()
      }
      .imagePlaygroundSheet(isPresented: $openPlayground, onCompletion: { url in
         if let newImage = UIImage(contentsOfFile: url.path) {
            self.image = newImage
         }
      })
   }
}