struct ContentView: View {
   @State private var selected: PhotosPickerItem?
   @State private var picture: UIImage?
   @State private var showPicker = true

   var body: some View {
      VStack {
         Image(uiImage: picture ?? UIImage(named: "nopicture")!)
            .resizable()
            .scaledToFit()
            .onTapGesture {
               withAnimation {
                  showPicker.toggle()
               }
            }
         Spacer()
         if showPicker {
            PhotosPicker(selection: $selected, matching: .images, photoLibrary: .shared()) { Text("Select a photo") }
               .buttonStyle(.borderedProminent)
               .photosPickerStyle(.inline)
               .frame(height: 300)
         }
      }.padding()
      .onChange(of: selected, initial: false) { old, item in
         Task {
            if let data = try? await item?.loadTransferable(type: Data.self) {
               picture = UIImage(data: data)
            }
         }
         withAnimation {
            showPicker.toggle()
         }
      }
   }
}