When creating and using a custom ButtonStyle for a SwiftUI button that changes its appearance based on the value of the configuration.isPressed property, that property sometimes get stuck with a "true" value, leaving the button to appear in its pressed state even when it is not being pressed. It stays stuck this way until the button is clicked again.
A sample project is attached. It's also in a public repo at https://github.com/siracusa/SwiftUIButtonIsPressedStateBug
To reproduce the bug:
-
Build and launch the sample project. A window should appear showing a large button view with a green background and some white text that says "Hello".
-
Click button view a few times and confirm that background color turns blue on mouse-down and switches back to green on mouse-up.