Skip to content

Commit

Permalink
Remove explicit press highlight handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Apr 6, 2021
1 parent bc0f16f commit 733b094
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/danielsaidi/MockingKit.git",
"state": {
"branch": null,
"revision": "3fb3fb321c6752b06662462d2b10c7377b7d3843",
"version": "0.9.3"
"revision": "ebb888c98bd1de2f2409c7b06f2386a55120d910",
"version": "0.9.4"
}
},
{
Expand Down
44 changes: 18 additions & 26 deletions Sources/KeyboardKit/Gestures/KeyboardGestures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,25 @@ private extension KeyboardGestures {
This is a plain double-tap gesure.
*/
var doubleTapGesture: some Gesture {
TapGesture(count: 2).onEnded {
doubleTapAction?()
triggerPressedHighlight()
}
TapGesture(count: 2)
.onEnded { doubleTapAction?() }
}

/**
This is a drag gesture that starts immediately.
*/
func dragGesture(for geo: GeometryProxy) -> some Gesture {
DragGesture(minimumDistance: 0)
.onChanged { _ in
handlePressGesture(for: geo) }
.onEnded { _ in
handleReleaseGesture()
}
.onChanged { _ in handlePressGesture(for: geo) }
.onEnded { _ in handleReleaseGesture() }
}

/**
This is a plain long press gesure.
*/
var longPressGesture: some Gesture {
LongPressGesture().onEnded { _ in
longPressAction?()
startRepeatTimer()
}
LongPressGesture()
.onEnded { _ in handleLongPressGesture() }
}

/**
Expand All @@ -128,11 +121,8 @@ private extension KeyboardGestures {
This is a plain tap gesure.
*/
var tapGesture: some Gesture {
TapGesture().onEnded {
tapAction?()
triggerPressedHighlight()
inputCalloutContext.reset()
}
TapGesture()
.onEnded(handleTapGesture)
}
}

Expand All @@ -159,6 +149,11 @@ private extension KeyboardGestures {
guard secondaryInputCalloutContext.isActive else { return }
}

func handleLongPressGesture() {
longPressAction?()
startRepeatTimer()
}

func handlePressGesture(for geo: GeometryProxy) {
if isDragGestureTriggered { return }
isDragGestureTriggered = true
Expand All @@ -182,6 +177,11 @@ private extension KeyboardGestures {
dragAction?(drag.startLocation, drag.location)
}

func handleTapGesture() {
tapAction?()
inputCalloutContext.reset()
}

func startRepeatTimer() {
guard let action = repeatAction else { return repeatTimer.stop() }
repeatTimer.start(action: action)
Expand All @@ -190,12 +190,4 @@ private extension KeyboardGestures {
func stopRepeatTimer() {
repeatTimer.stop()
}

func triggerPressedHighlight() {
if isInputCalloutEnabled { return }
isPressed.wrappedValue = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
isPressed.wrappedValue = false
}
}
}

0 comments on commit 733b094

Please sign in to comment.