7

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)
            }
        }
    }
DrainOpener
  • 186
  • 1
  • 18
JoshHolme
  • 303
  • 2
  • 15

1 Answers1

3

I've played with different things: fg, bg, accent etc but to no avail. I'm guessing "not possible" at the moment.

ps ContextMenu is deprecated, but not .contextMenu You're doing it right.

This is the non-deprecated one. The other one doesn't use a ViewBuilder

public func contextMenu<MenuItems>(@ViewBuilder menuItems: () -> MenuItems) -> some View where MenuItems : View
Gene De Lisa
  • 3,628
  • 1
  • 21
  • 36
  • Wow, thank you for the info on `.contextMenu` not being deprecated. Pretty confusing the naming of them, makes it hard to differentiate like that if you don't know that there's two. – JoshHolme Oct 19 '20 at 20:07