在 NavigationView 中滚动时,SwiftUI 列表行颜色不一致

SwiftUI List row color inconsistent while scrolling in a NavigationView

当我滚动时,NavigationView 中的 List 中的行视图的背景颜色不一致地从透明切换为白色。

使用

@Environment(\.colorScheme) var colorScheme

struct YourView: View {

    var body: some View {
        Text("Your views")
        .listRowBackground(
            colorScheme == .light ? Color.white : Color(white: 0.09, opacity: 1)
        )
    }
}

colorScheme 是支持深色模式所必需的。