1

I want to show the original color of my list item, but it seems NavigationLink has an overlay above it. And I try .buttonStyle(PlainButtonStyle()), but it didn't help. Using both iOS 16+ and iOS 15+, same result.

Please look the screenshots for what I got.

Without NavigationLink
    var colors: [Color] = [.red, .blue, .yellow]
    
    var body: some View {
        VStack {
            List {
                ForEach(colors, id: \.self) { color in
                    color
                }
                .listRowInsets(EdgeInsets())
            }
            .listStyle(PlainListStyle())
        }
        .padding(.horizontal)
    }

enter image description here

With NavigationLink

var colors: [Color] = [.red, .blue, .yellow]
    
    var body: some View {
        VStack {
            List {
                ForEach(colors, id: \.self) { color in
                    NavigationLink {
                        // Some details view
                    } label: {
                        color
                        // Custom view in my real project
                    }
                    // No help
                    .buttonStyle(PlainButtonStyle())
                }
                .listRowInsets(EdgeInsets())
            }
            .listStyle(PlainListStyle())
        }
        .padding(.horizontal)
    }

enter image description here

Zhou Haibo
  • 1,681
  • 1
  • 12
  • 32
  • use a `NavigationStack` to wrap the `VStack`. `NavigationLink` is useless (and dimmed) if you don't you have one. – workingdog support Ukraine Jun 02 '23 at 05:09
  • @workingdog support Ukraine Nop, I do need `NavigationLink`, this is just a minimum code I created to show the problem. – Zhou Haibo Jun 02 '23 at 05:43
  • keep the `NavigationLink`, but use the `NavigationStack` to wrap the VStack with the List. Does this not work for you? The dimmed color indicates that the `NavigationLink` is `disabled`. – workingdog support Ukraine Jun 02 '23 at 05:48
  • @workingdogsupportUkraine cool! The problem is fixed after applying `NavigationStack`. But `NavigationStack` is only supported from iOS 16+, may I know what is the solution for iOS 15+ if you don't mind? – Zhou Haibo Jun 02 '23 at 06:58
  • try `NavigationView` see: https://developer.apple.com/documentation/swiftui/navigationview See also: https://stackoverflow.com/questions/73700850/swiftui-navigationview-vs-navigationstack-for-ios-15-16 – workingdog support Ukraine Jun 02 '23 at 07:10

0 Answers0