Skip to content

Instantly share code, notes, and snippets.

@ryanmeisters
Last active November 10, 2024 14:23
Show Gist options
  • Save ryanmeisters/e894a2aa1dbd9baceb244b8f1450326c to your computer and use it in GitHub Desktop.
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
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()
@ryanmeisters
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment