I am trying to insert a button inside of another button using SwiftUI. However, if I press that button, it also animates the outer button being pressed, even though it doesn't run the action closure. Is there a way to prevent this, perhaps using a custom ButtonStyle?
This is what it looks like:
This is what it looks like when the inner button is pressed:
And here is my code:
var body: some View {
Button(action: {
print("outer button pressed")
}) {
HStack {
Text("Button")
Spacer()
Button(action: {
print("inner button pressed")
}) {
Circle()
.foregroundColor(Color.accentColor.opacity(0.2))
.frame(width: 28.0, height: 28.0)
.overlay(Image(systemName: "ellipsis"))
}
}
.padding()
.accentColor(.white)
.background(Color.accentColor)
.clipShape(RoundedRectangle(cornerRadius: 14.0, style: .continuous))
}
.frame(maxWidth: 200.0)
.padding()
}
How about using 2 different buttons, within a ZStack?