14

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

4
  • If it is in List row then the issue is different. Would you show more code in context or better provide minimal reproducible example? Commented Jul 29, 2020 at 7: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. Commented Jul 29, 2020 at 18:03
  • Look at this stackoverflow.com/questions/62622560/… Commented Jul 29, 2020 at 18:06
  • thank you @asperi but it doesn't seem to be what I'm looking for Commented Jul 29, 2020 at 18:12

1 Answer 1

11

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()) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.