From 290396336d8d31f67b079886637d83af645e0271 Mon Sep 17 00:00:00 2001 From: Vislov Ivan Date: Thu, 19 Jun 2025 15:47:09 +0300 Subject: [PATCH 1/4] simultaneous tap fix - swiftui fix - uikit fix --- .../Components/Card/SUCard.swift | 24 +++++++++-------- .../Components/Card/UKCard.swift | 27 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Sources/ComponentsKit/Components/Card/SUCard.swift b/Sources/ComponentsKit/Components/Card/SUCard.swift index 368db91..8fb2246 100644 --- a/Sources/ComponentsKit/Components/Card/SUCard.swift +++ b/Sources/ComponentsKit/Components/Card/SUCard.swift @@ -58,20 +58,22 @@ public struct SUCard: View { ) .shadow(self.model.shadow) .observeSize { self.contentSize = $0 } - .simultaneousGesture(DragGesture(minimumDistance: 0.0) - .onChanged { _ in - guard self.model.isTappable else { return } - self.isPressed = true - } - .onEnded { value in - guard self.model.isTappable else { return } + .gesture( + DragGesture(minimumDistance: 0.0) + .onChanged { _ in + guard self.model.isTappable else { return } + self.isPressed = true + } + .onEnded { value in + guard self.model.isTappable else { return } - defer { self.isPressed = false } + defer { self.isPressed = false } - if CGRect(origin: .zero, size: self.contentSize).contains(value.location) { - self.onTap() + if CGRect(origin: .zero, size: self.contentSize) + .contains(value.location) { + self.onTap() + } } - } ) .scaleEffect( self.isPressed ? self.model.animationScale.value : 1, diff --git a/Sources/ComponentsKit/Components/Card/UKCard.swift b/Sources/ComponentsKit/Components/Card/UKCard.swift index aa63418..e3663c0 100644 --- a/Sources/ComponentsKit/Components/Card/UKCard.swift +++ b/Sources/ComponentsKit/Components/Card/UKCard.swift @@ -138,10 +138,15 @@ open class UKCard: UIView, UKComponent { _ touches: Set, with event: UIEvent? ) { - super.touchesBegan(touches, with: event) - - guard self.model.isTappable else { return } + guard self.model.isTappable, + let touch = touches.first, + touch.view == self + else { + super.touchesBegan(touches, with: event) + return + } + super.touchesBegan(touches, with: event) self.isPressed = true } @@ -149,17 +154,21 @@ open class UKCard: UIView, UKComponent { _ touches: Set, with event: UIEvent? ) { - super.touchesEnded(touches, with: event) - - guard self.model.isTappable else { return } + guard self.model.isTappable, + let touch = touches.first, + touch.view == self + else { + super.touchesEnded(touches, with: event) + return + } defer { self.isPressed = false } - if self.model.isTappable, - let location = touches.first?.location(in: self), - self.bounds.contains(location) { + let location = touch.location(in: self) + if bounds.contains(location) { self.onTap() } + super.touchesEnded(touches, with: event) } open override func touchesCancelled( From 9067d1a1be93fc542b8bdfbc4dd7ba59c4f1cbb0 Mon Sep 17 00:00:00 2001 From: Vislov Ivan Date: Thu, 19 Jun 2025 16:19:37 +0300 Subject: [PATCH 2/4] fix tap recognition on clear background --- Sources/ComponentsKit/Components/Card/SUCard.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/ComponentsKit/Components/Card/SUCard.swift b/Sources/ComponentsKit/Components/Card/SUCard.swift index 8fb2246..029033f 100644 --- a/Sources/ComponentsKit/Components/Card/SUCard.swift +++ b/Sources/ComponentsKit/Components/Card/SUCard.swift @@ -58,6 +58,7 @@ public struct SUCard: View { ) .shadow(self.model.shadow) .observeSize { self.contentSize = $0 } + .contentShape(.rect) .gesture( DragGesture(minimumDistance: 0.0) .onChanged { _ in From 98852e427f9218a494c82afd78f459be258dd767 Mon Sep 17 00:00:00 2001 From: Vislov Ivan Date: Thu, 19 Jun 2025 17:16:08 +0300 Subject: [PATCH 3/4] swiftui card fix border bug --- Sources/ComponentsKit/Components/Card/SUCard.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComponentsKit/Components/Card/SUCard.swift b/Sources/ComponentsKit/Components/Card/SUCard.swift index 029033f..0f1934b 100644 --- a/Sources/ComponentsKit/Components/Card/SUCard.swift +++ b/Sources/ComponentsKit/Components/Card/SUCard.swift @@ -51,7 +51,7 @@ public struct SUCard: View { .cornerRadius(self.model.cornerRadius.value) .overlay( RoundedRectangle(cornerRadius: self.model.cornerRadius.value) - .stroke( + .strokeBorder( self.model.borderColor.color, lineWidth: self.model.borderWidth.value ) From 52c1dbcd4837dfb0c1b4577546af1c1e6c9f7a05 Mon Sep 17 00:00:00 2001 From: Vislov Ivan Date: Thu, 19 Jun 2025 20:04:11 +0300 Subject: [PATCH 4/4] revert touchesBegan and touchesEnded code --- .../Components/Card/UKCard.swift | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Sources/ComponentsKit/Components/Card/UKCard.swift b/Sources/ComponentsKit/Components/Card/UKCard.swift index e3663c0..aa63418 100644 --- a/Sources/ComponentsKit/Components/Card/UKCard.swift +++ b/Sources/ComponentsKit/Components/Card/UKCard.swift @@ -138,15 +138,10 @@ open class UKCard: UIView, UKComponent { _ touches: Set, with event: UIEvent? ) { - guard self.model.isTappable, - let touch = touches.first, - touch.view == self - else { - super.touchesBegan(touches, with: event) - return - } - super.touchesBegan(touches, with: event) + + guard self.model.isTappable else { return } + self.isPressed = true } @@ -154,21 +149,17 @@ open class UKCard: UIView, UKComponent { _ touches: Set, with event: UIEvent? ) { - guard self.model.isTappable, - let touch = touches.first, - touch.view == self - else { - super.touchesEnded(touches, with: event) - return - } + super.touchesEnded(touches, with: event) + + guard self.model.isTappable else { return } defer { self.isPressed = false } - let location = touch.location(in: self) - if bounds.contains(location) { + if self.model.isTappable, + let location = touches.first?.location(in: self), + self.bounds.contains(location) { self.onTap() } - super.touchesEnded(touches, with: event) } open override func touchesCancelled(