8

Is there anyway we could remove the default button highlight in SwiftUI? I currently have a view that acts as a navigationlink but when I tap on it, I would like it to not have that default highlight (the fade out ).

The main view looks like:

NavigationLink( ... ) {
    VStack{
        { ... }
        Button(action: ... ){ ... }
    }
}
.buttonStyle(PlainButtonStyle()) 

It's gotten rid of the blue foreground text color, but has not removed the default highlight.

I would like to do this as I have another button inside that view that does a seperate action, but when I click on that button, it highlights the entire view (but doesn't trigger the main view navigationlink!! it only triggers the inner button action)

I am currently using swiftui 2.0

edit: I couldn't a find a way to remove that button highlight, but I found a different approach. Instead, I would just navigate programmatically by using the isActive version of NavigationLink. So instead it would be :

@State private var showOneLevelIn = false

//this navigationLink is hidden
NavigationLink(destination: OneLevelInView(), isActive: $showOneLevelIn, label: { EmptyView() })

//original view without navigationlink wrapped around
    VStack{
        { ... }
        Button(action: ... ){ ... }
    }
    .onTapGesture(count: 1) {
         showOneLevelIn = true
    }

found from: Use NavigationLink programmatically in SwiftUI

daee kang
  • 285
  • 1
  • 3
  • 9
  • If it is in List row then the issue is different. Would you show more code in context or better provide minimal reproducible example? – Asperi Jul 29 '20 at 07:20
  • @Asperi I gave a quick edit, hopefully it makes more sense. I essentially made a vstack a navigation link because I wanted to have the ability that if you click anywhere in the vstack it would navigate you. – daee kang Jul 29 '20 at 18:03
  • Look at this https://stackoverflow.com/questions/62622560/remove-change-list-highlight-color-or-adjust-space-between-items – Asperi Jul 29 '20 at 18:06
  • thank you @asperi but it doesn't seem to be what I'm looking for – daee kang Jul 29 '20 at 18:12

1 Answers1

8

List detects any default button at any subview level. So try to change button style not only for link but for buttons as well

NavigationLink( ... ) {
    VStack{
        { ... }
        Button(action: ... ){ ... }
            .buttonStyle(PlainButtonStyle())    // << here !!

    }
}
.buttonStyle(PlainButtonStyle()) 
Asperi
  • 228,894
  • 20
  • 464
  • 690