I’m trying to make a multi stage long press gesture where it switches between pressing, released, or inactive to execute certain action depending on the states appropriately.
However, I have trouble changing the gesture state of the LongPressState. The updating closure does not seem to be called.
Below is the code I have currently.
enum LongPressState {
case inactive
case pressing
case released
}
@GestureState private var longPressState: LongPressState = .inactive
private let longPressDuration: Double = 1.0
private let longPressDistance: CGFloat = 50.0
var longPress: some Gesture {
LongPressGesture(minimumDuration: longPressDuration, maximumDistance: longPressDistance)
.targetedToAnyEntity()
.updating($longPressState) { value, gestureState, transaction in
print("Updating")
gestureState = .pressing
}
.onEnded { value in
print(longPressState)
switch longPressState {
case .inactive:
print("Inactive stage")
case .pressing:
print("Pressing stage")
case .released:
print("Released stage")
}
}
}
var body: some View {
RealityView { content in
...
}
.gesture(longPress)
}