Created
May 11, 2023 11:50
-
-
Save ayaysir/05e509370e3ffb91706f83391930489e to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct ContinuousLongPressView: View { | |
@GestureState private var isDetectingLongPress = false | |
var longPress: some Gesture { | |
LongPressGesture(minimumDuration: 1) | |
.updating($isDetectingLongPress) { value, gestureState, _ in | |
gestureState = value | |
}.onEnded { value in | |
print("LongPress OnEnded") | |
} | |
} | |
@GestureState private var isDetectingContinuousPress = false | |
var continuousPress: some Gesture { | |
LongPressGesture(minimumDuration: 0.1) | |
.sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local)) | |
.updating($isDetectingContinuousPress) { value, gestureState, _ in | |
switch value { | |
case .second(true, nil): | |
gestureState = true | |
print("updating: Second") | |
default: | |
break | |
} | |
}.onEnded { value in | |
switch value { | |
case .second(_, _): | |
print("onended: Second") | |
default: | |
break | |
} | |
} | |
} | |
var body: some View { | |
VStack { | |
Image(systemName: isDetectingLongPress ? "globe" : "pause.fill") | |
Button {} label: { | |
Text("Long Press Button") | |
}.simultaneousGesture(longPress) | |
Divider() | |
Image(systemName: isDetectingContinuousPress ? "globe" : "pause.fill") | |
Button {} label: { | |
Text("Continuous Press Button") | |
}.simultaneousGesture(continuousPress) | |
} | |
// Bool 값이 변경되었을 때의 처리는 onChange에서 | |
// .onChange(of: isDetectingLongPress) { newValue in | |
// print("onChange", newValue) | |
// } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment