I'm trying to add a delete action in a context menu, however it just gets displayed as the default black color. The Photos app uses a red color for its delete action as well. I've seen in some spaces online that this is not a functionality currently provided of contextMenu
, however I have also seen it used in third party apps in the wild here. Does anyone know how to accomplish this?
Also, looking on Apple's documentation for contextMenu
it says that they have been deprecated for everything except for macOS. I find it strange that they deprecated it just one year after introducing it. Was this replaced by another component that I should be using?
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(photos) { photo in
Image(uiImage: UIImage(data: photo.imageData!)!)
.resizable()
.aspectRatio(1, contentMode: .fill)
.contextMenu(menuItems: {
Button(action: {
deletePhoto(selectedPhoto: photo)
}) {
Label("Remove", systemImage: "trash")
}
})
}
}
.padding()
.navigationBarTitle(Text("Albums"))
.navigationBarItems(trailing:
Button(action: {
self.showingImagePicker = true
}) {
Image(systemName: "plus.circle.fill")
}
)
.sheet(isPresented: $showingImagePicker, onDismiss: loadImage) {
ImagePicker(image: self.$inputImage)
}
}
}