Skip to content

Commit 2903963

Browse files
committed
simultaneous tap fix
- swiftui fix - uikit fix
1 parent 6f8cc9f commit 2903963

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

Sources/ComponentsKit/Components/Card/SUCard.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,22 @@ public struct SUCard<Content: View>: View {
5858
)
5959
.shadow(self.model.shadow)
6060
.observeSize { self.contentSize = $0 }
61-
.simultaneousGesture(DragGesture(minimumDistance: 0.0)
62-
.onChanged { _ in
63-
guard self.model.isTappable else { return }
64-
self.isPressed = true
65-
}
66-
.onEnded { value in
67-
guard self.model.isTappable else { return }
61+
.gesture(
62+
DragGesture(minimumDistance: 0.0)
63+
.onChanged { _ in
64+
guard self.model.isTappable else { return }
65+
self.isPressed = true
66+
}
67+
.onEnded { value in
68+
guard self.model.isTappable else { return }
6869

69-
defer { self.isPressed = false }
70+
defer { self.isPressed = false }
7071

71-
if CGRect(origin: .zero, size: self.contentSize).contains(value.location) {
72-
self.onTap()
72+
if CGRect(origin: .zero, size: self.contentSize)
73+
.contains(value.location) {
74+
self.onTap()
75+
}
7376
}
74-
}
7577
)
7678
.scaleEffect(
7779
self.isPressed ? self.model.animationScale.value : 1,

Sources/ComponentsKit/Components/Card/UKCard.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,37 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
138138
_ touches: Set<UITouch>,
139139
with event: UIEvent?
140140
) {
141-
super.touchesBegan(touches, with: event)
142-
143-
guard self.model.isTappable else { return }
141+
guard self.model.isTappable,
142+
let touch = touches.first,
143+
touch.view == self
144+
else {
145+
super.touchesBegan(touches, with: event)
146+
return
147+
}
144148

149+
super.touchesBegan(touches, with: event)
145150
self.isPressed = true
146151
}
147152

148153
open override func touchesEnded(
149154
_ touches: Set<UITouch>,
150155
with event: UIEvent?
151156
) {
152-
super.touchesEnded(touches, with: event)
153-
154-
guard self.model.isTappable else { return }
157+
guard self.model.isTappable,
158+
let touch = touches.first,
159+
touch.view == self
160+
else {
161+
super.touchesEnded(touches, with: event)
162+
return
163+
}
155164

156165
defer { self.isPressed = false }
157166

158-
if self.model.isTappable,
159-
let location = touches.first?.location(in: self),
160-
self.bounds.contains(location) {
167+
let location = touch.location(in: self)
168+
if bounds.contains(location) {
161169
self.onTap()
162170
}
171+
super.touchesEnded(touches, with: event)
163172
}
164173

165174
open override func touchesCancelled(

0 commit comments

Comments
 (0)