如何使 SwiftUI 列表行背景颜色扩展到整个宽度,包括安全区域之外

How can I make a SwiftUI List row background color extend the full width, including outside of the safe area

在 SwiftUI List 中,如何使列表行背景(通过 .listRowBackground() 设置)扩展视图的整个宽度,甚至在安全区域下方?例如。当 运行 在横向 iPhone 上时(例如 iPhone 12 Pro Max)。目前,该单元格在单元格的最左侧显示为白色,直到安全区域开始。

示例代码:

struct ContentView: View {
    var body: some View {
        List {
            Text("Test")
                .listRowBackground(Color(.systemGray3))
        }.listStyle(GroupedListStyle())
    }
}

这会产生一个 UI,如下所示。我想要单元格的灰色背景来扩展设备的整个宽度。

我尝试将 .edgesIgnoringSafeArea(.all) 添加到 Text,但没有任何区别。

答案是将 .edgesIgnoringSafeArea([.leading, .trailing]) 放在背景上 Color 本身,而不是列表项。

struct ContentView: View {
    var body: some View {
        List {
            Text("Test").listRowBackground(
                Color(.systemGray3).edgesIgnoringSafeArea([.leading, .trailing])
            )
        }.listStyle(GroupedListStyle())
    }
}