BobdeBloke
BobdeBloke

Reputation: 159

Creating Menu in SwiftUI - receive output message of [UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:]

I'm attempting to create a pull down menu in SwiftUI , the menu seems to be fully visible on the device/simulator and I can interact with it but I get the following message:

[UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.

Can anyone suggest a solution or help me understand the problem ? XCode Version 12.2 beta 4

struct AardvarkQuantity: View {
    
    var body: some View {
        
        VStack{
            Menu(content: {
                
                ForEach((1...5), id: \.self) {
                    Text("\($0)")
                        .font(Font.fontSFProText(size: 9))
                }
                
            }, label: {
                Text("Number of Aardvarks")
                    .font(Font.fontSFProText(size: 12))
                    .foregroundColor(ColorManager.itemRowLabelText)
            })
        }
    }
}

Upvotes: 10

Views: 7380

Answers (2)

glotcha
glotcha

Reputation: 578

I had a similar case, it seems the warning occurs when your code to generate the menu is not performant enough to return in time for when the system wants to layout the menu and the preview, in some cases you might have an animation glitch or other layout warnings because the system goes ahead anyway even if your code was too slow. To fix you have to optimize/defer code into the action handlers so that it's run lazily (when the menu items are tapped and not when the menu items are created). Its seems one other place to optimize are the cell registration/update handlers if you are showing a preview.

Upvotes: 0

BobdeBloke
BobdeBloke

Reputation: 159

As Andrew and pawello2222 both confirmed, the error message appears to be a log warning and code appears to be working I ended up using the solution listed here.

Although I'm still not clear on how I should respond to the warning.

Upvotes: 0

Related Questions