简体   繁体   English

SwiftUI - 显示 contextMenu 时,NavigationLink 的内容不可读

[英]SwiftUI - NavigationLink' content is not readable when contextMenu is presented

I have a coloured NavigationLink that has context-menu.我有一个带有上下文菜单的彩色NavigationLink Its content is not readable when the context-menu is presened.当显示上下文菜单时,其内容不可读。 I have epxreminted using the context-menu on the immediate sub-view of the NavigationLink , but it is stil the same issue.我已经 epxreminted 在NavigationLink的直接子视图上使用上下文菜单,但它仍然是同一个问题。

NavigationLink(destination: Text("View")) {
    VStack(alignment: .leading) {
        Text("Context Menu")

            .font(.system(size: 24, weight: .bold))
    }
    .frame(minWidth: 0, maxWidth: .infinity, idealHeight: 70)
    .foregroundColor(.white)
    .padding()
    .cornerRadius(3.0)
}
.background(Color.red)
.contextMenu {
    Section {
        Button(action: {
        }) {
            Label("Edit", systemImage: "square.and.pencil")
        }
    }
    
    Section(header: Text("Secondary actions")) {
        Button(action: {}) {
            Label("Delete", systemImage: "trash")
        }
    }
}

NavigatoinLinks look like in its original state. NavigatoinLinks看起来像其原始的 state。

在此处输入图像描述

When the context-menu is presented.当显示上下文菜单时。 The problem is even worse If I use small sized text.如果我使用小尺寸文本,问题会更糟。

在此处输入图像描述

I have tested on ios 14.2 both on simulator and physical device.我已经在模拟器和物理设备上对 ios 14.2 进行了测试。


Info信息

Hierarchy of views.视图的层次结构。

ScrollView {
  LazyVStack {
      ForEach(data) { item in
        // NavigationLink
      }
  }
}

Update更新

This is a similar project that has the same issue.这是一个具有相同问题的类似项目。

struct ContentView: View {
    var body: some View {
        NavigationView {
            ScrollView {
                LazyVStack {
                    ForEach(0..<10) { item in
                        NavigationLink(destination: Text("View")) {
                            VStack(alignment: .leading) {
                                Text("Context Menu")
                                    .font(.system(size: 24, weight: .bold))
                            }
                            .frame(minWidth: 0, maxWidth: .infinity, idealHeight: 70)
                            .foregroundColor(.white)
                            .padding()
                            .cornerRadius(3.0)
                        }
                        .background(Color.red)
                        .contextMenu {
                            Section {
                                Button(action: {
                                }) {
                                    Label("Edit", systemImage: "square.and.pencil")
                                }
                            }
                            
                            Section(header: Text("Secondary actions")) {
                                Button(action: {}) {
                                    Label("Delete", systemImage: "trash")
                                }
                            }
                        }
                        
                    }
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I know it's been two years, but this still remains an issue with iOS 16 when you use LazyVStack.我知道已经两年了,但是当您使用 LazyVStack 时,这仍然是 iOS 16 的问题。 In contrast with List, SwiftUI generates a clear automatic preview.对比List,SwiftUI生成清晰的自动预览。 What's new with iOS 16 is that you can now define a custom preview, and SwiftUI will present that preview without the blur. iOS 16 的新功能是您现在可以定义自定义预览,而 SwiftUI 将在没有模糊的情况下呈现该预览。 If you choose to use LazyVStack for performance or another reason, this gives you an alternative, albeit with duplicate code.如果您出于性能或其他原因选择使用 LazyVStack,这为您提供了一个替代方案,尽管有重复的代码。

From your example above, you would add:从上面的示例中,您将添加:

NavigationLink(destination: Text("View")) {
    // View such as your VStack containing Text
}
.contextMenu {
    // Menu items
} preview: {
    // View, again, but you might want to simplify or modify 
}
                    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM