contextMenu not refreshing

.contextMenu(menuItems: {Button(action: {
      tangoArray[randomNum].bookmark.toggle()
      database.updateUserData(tango: tangoArray[randomNum])
      self.fullRotation.toggle()
    }, label: {
      VStack{
        Image(systemName: tangoArray[randomNum].bookmark ? "bookmark" : "bookmark.fill")
          .font(.title)
        Text(tangoArray[randomNum].bookmark ? "Remove bookmark" : "Bookmark")
      }
    })
    })

I'm trying to use a contextMenu to bookmark flashcard items. What I have found though is that even after randonNum has changed, so a

different flashcard is presented, the bookmark in the context menu is still showing the previous card's status. For example, it's a filled bookmark if I just tagged the previous card as a bookmark.

Replies

I'm having a similar problem I'm attempting to change the content (text) o f the contextmenus buttons. I need to change between KG and LBM. I tried to do this using a var(context1) set in the view struct. Either I get the first two menu items duplicated or it fails to compile with a too complex error.


Maybe this is a bug.


.contextMenu(menuItems:{
                    Button(context1. action: {
                        self.animal = AnimalSize.smallAnimal
                    })
                    Button("10..50 lbm", action: {
                        self.animal = AnimalSize.mediumAnimal
  
                    })
                    Button("50..150 lbm", action: {
                        self.animal = AnimalSize.largeAnimal
  
                    })
                 Button("Toggle Kg - lbm", action: {
                    self.drugDosage.unitsLbm.toggle()
                    self.clientLbmDex = 0
                })
  

          })

I've just done a quick fix/hack to solve all sorts of SwiftUI issues where my view isn't refreshing when I expect it to. Using .rotation3DEffect I do a 360 degree rotation after every action to force the view to do a quick refresh. It has solved my contextMenu issue as well for now. I'm sure this isn't the most elegant solution so hopefully someone else can guide us to the proper way.