Reputation: 355
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
Upvotes: 12
Views: 9619
Reputation: 257493
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())
Upvotes: 11