Last active
November 10, 2024 14:23
-
-
Save ryanmeisters/e894a2aa1dbd9baceb244b8f1450326c to your computer and use it in GitHub Desktop.
Created to illustrate that using ButtonStyle to detect touch down is unusably laggy. A slow tap will trigger, but a fast tap won't trigger at all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TestView: View { | |
@State private var isPressed = false | |
var body: some View { | |
List { | |
Section { | |
Button(action: { | |
print("hi") | |
}, label: { | |
HStack { | |
Text("Hello"); Spacer(); Text("hi") | |
} | |
.contentShape(.rect) | |
}) | |
.listRowBackground(isPressed ? Color.gray : Color.green) | |
.buttonStyle( | |
CustomButtonStyle( | |
onPressed: { isPressed = true }, | |
onReleased: { isPressed = false } | |
) | |
) | |
} | |
} | |
} | |
} | |
#Preview { | |
TestView() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the solution here... https://stackoverflow.com/a/79175060/1104780