Skip to content

Commit fe56aaf

Browse files
Merge pull request #103 from componentskit/dev
v1.5.4
2 parents 621676a + b68d4ff commit fe56aaf

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

Sources/ComponentsKit/Components/Alert/SUAlert.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct AlertContent: View {
6060
.foregroundStyle(UniversalColor.foreground.color)
6161
.multilineTextAlignment(.center)
6262
.frame(maxWidth: .infinity)
63+
.fixedSize(horizontal: false, vertical: true)
6364
}
6465

6566
func message(_ text: String) -> some View {

Sources/ComponentsKit/Components/Button/SUButton.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public struct SUButton: View {
99
/// A closure that is triggered when the button is tapped.
1010
public var action: () -> Void
1111

12-
/// A Boolean value indicating whether the button is pressed.
13-
@State public var isPressed: Bool = false
12+
/// A current scale effect value.
13+
@State public var scale: CGFloat = 1.0
1414

1515
// MARK: Initialization
1616

@@ -37,17 +37,15 @@ public struct SUButton: View {
3737
.buttonStyle(CustomButtonStyle(model: self.model))
3838
.simultaneousGesture(DragGesture(minimumDistance: 0.0)
3939
.onChanged { _ in
40-
self.isPressed = true
40+
self.scale = self.model.animationScale.value
4141
}
4242
.onEnded { _ in
43-
self.isPressed = false
43+
self.scale = 1.0
4444
}
4545
)
4646
.disabled(!self.model.isInteractive)
47-
.scaleEffect(
48-
self.isPressed ? self.model.animationScale.value : 1,
49-
anchor: .center
50-
)
47+
.scaleEffect(self.scale, anchor: .center)
48+
.animation(.easeOut(duration: 0.05), value: self.scale)
5149
}
5250

5351
@ViewBuilder

Sources/ComponentsKit/Components/Button/UKButton.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ open class UKButton: FullWidthComponent, UKComponent {
1818
/// A Boolean value indicating whether the button is pressed.
1919
public private(set) var isPressed: Bool = false {
2020
didSet {
21-
self.transform = self.isPressed && self.model.isInteractive
22-
? .init(
23-
scaleX: self.model.animationScale.value,
24-
y: self.model.animationScale.value
25-
)
26-
: .identity
21+
UIView.animate(withDuration: 0.05, delay: 0, options: [.curveEaseOut]) {
22+
self.transform = self.isPressed && self.model.isInteractive
23+
? .init(
24+
scaleX: self.model.animationScale.value,
25+
y: self.model.animationScale.value
26+
)
27+
: .identity
28+
}
2729
}
2830
}
2931

@@ -197,7 +199,13 @@ open class UKButton: FullWidthComponent, UKComponent {
197199
) {
198200
super.touchesCancelled(touches, with: event)
199201

200-
self.isPressed = false
202+
defer { self.isPressed = false }
203+
204+
if self.model.isInteractive,
205+
let location = touches.first?.location(in: self),
206+
self.bounds.contains(location) {
207+
self.action()
208+
}
201209
}
202210

203211
open override func traitCollectionDidChange(

Sources/ComponentsKit/Components/Card/SUCard.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public struct SUCard<Content: View>: View {
1919
/// A closure that is triggered when the card is tapped.
2020
public var onTap: () -> Void
2121

22-
/// A Boolean value indicating whether the card is pressed.
23-
@State public var isPressed: Bool = false
22+
/// A current scale effect value.
23+
@State public var scale: CGFloat = 1.0
2424

2525
@ViewBuilder private let content: () -> Content
2626
@State private var contentSize: CGSize = .zero
@@ -66,16 +66,14 @@ public struct SUCard<Content: View>: View {
6666
.simultaneousGesture(
6767
DragGesture(minimumDistance: 0.0)
6868
.onChanged { _ in
69-
self.isPressed = true
69+
self.scale = self.model.animationScale.value
7070
}
7171
.onEnded { _ in
72-
self.isPressed = false
72+
self.scale = 1.0
7373
},
7474
isEnabled: self.model.isTappable
7575
)
76-
.scaleEffect(
77-
self.isPressed ? self.model.animationScale.value : 1,
78-
anchor: .center
79-
)
76+
.scaleEffect(self.scale, anchor: .center)
77+
.animation(.easeOut(duration: 0.05), value: self.scale)
8078
}
8179
}

Sources/ComponentsKit/Components/Card/UKCard.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
2929
/// A Boolean value indicating whether the button is pressed.
3030
public private(set) var isPressed: Bool = false {
3131
didSet {
32-
self.transform = self.isPressed
33-
? .init(
34-
scaleX: self.model.animationScale.value,
35-
y: self.model.animationScale.value
36-
)
37-
: .identity
32+
UIView.animate(withDuration: 0.05, delay: 0, options: [.curveEaseOut]) {
33+
self.transform = self.isPressed
34+
? .init(
35+
scaleX: self.model.animationScale.value,
36+
y: self.model.animationScale.value
37+
)
38+
: .identity
39+
}
3840
}
3941
}
4042

@@ -168,7 +170,15 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
168170
) {
169171
super.touchesCancelled(touches, with: event)
170172

171-
self.isPressed = false
173+
guard self.model.isTappable else { return }
174+
175+
defer { self.isPressed = false }
176+
177+
if self.model.isTappable,
178+
let location = touches.first?.location(in: self),
179+
self.bounds.contains(location) {
180+
self.onTap()
181+
}
172182
}
173183

174184
open override func traitCollectionDidChange(

0 commit comments

Comments
 (0)