I would like to make an ActionSheet, where user could choose if he want to select image from Gallery or take a picture.
However, implementing this I was not able to find a way how PhotosPicker could be called in such context. The code below doesn't work: the item "Choose from gallery" displayed, but no reaction on tapping.
I will highly appreciate any advises.
Thank you!
Button {
displayImageActionSheet = true
} label: {
Image("user_photo_placeholder")
}
.confirmationDialog("Profile picture",
isPresented: $displayImageActionSheet,
titleVisibility: .visible) {
PhotosPicker("Choose from gallery",
selection: $selectedPhotoImage,
matching: .any(of: [.videos, .not(.images)]))
Button("Take picture") {
}
Button("Remove", role: .destructive) {
}
}
You can present it by using photosPicker(isPresented:)
import SwiftUI
import PhotosUI
struct ConfimShowPhotos: View {
@State var showPicker: Bool = false
@State var showDialog: Bool = false
@State var showCamera: Bool = false
@State var selectedItem: PhotosPickerItem? = nil
var body: some View {
Button {
showDialog.toggle()
} label: {
Image(systemName: "photo")
}
.confirmationDialog("Profile Picture", isPresented: $showDialog) {
Button {
showCamera.toggle()
} label: {
Label("Camera", systemImage: "camera")
}
Button {
showPicker.toggle()
} label: {
Label("Gallery", systemImage: "photo.artframe")
}
}
.photosPicker(isPresented: $showPicker, selection: $selectedItem)
.alert("Say Cheese!!", isPresented: $showCamera) {
Text("Mimicking showing camera")
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With