I want to write my own button style which behaves like those in macOS menu list.
As it shown below, after click, its background changed: blue -> transparent -> blue, and then disappear. And they all happen after releasing, so I don't think configuration.isPressed
can help.
I tried following code, but they didn't perform correctly. No animation at all. And even worse, "hovering to show blue background" is animated.
I only want that "blink" effect after I release my mouse, instead affecting animation before I releasing it. I don't know where to go next. Please help me out.
@State var onHover: Bool = false
public func makeBody(configuration: Configuration) -> some View {
configuration.label
.background {
onHover ? Color.accentColor : Color.clear
}
.onHover { onHover = $0 }
.animation(.easeOut(duration: 0.1))
.onTapGesture {
onHover = false // Blinking here
onHover = true
}
}