File tree Expand file tree Collapse file tree 5 files changed +45
-30
lines changed
Sources/ComponentsKit/Components Expand file tree Collapse file tree 5 files changed +45
-30
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ struct AlertContent: View {
60
60
. foregroundStyle ( UniversalColor . foreground. color)
61
61
. multilineTextAlignment ( . center)
62
62
. frame ( maxWidth: . infinity)
63
+ . fixedSize ( horizontal: false , vertical: true )
63
64
}
64
65
65
66
func message( _ text: String ) -> some View {
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ public struct SUButton: View {
9
9
/// A closure that is triggered when the button is tapped.
10
10
public var action : ( ) -> Void
11
11
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
14
14
15
15
// MARK: Initialization
16
16
@@ -37,17 +37,15 @@ public struct SUButton: View {
37
37
. buttonStyle ( CustomButtonStyle ( model: self . model) )
38
38
. simultaneousGesture ( DragGesture ( minimumDistance: 0.0 )
39
39
. onChanged { _ in
40
- self . isPressed = true
40
+ self . scale = self . model . animationScale . value
41
41
}
42
42
. onEnded { _ in
43
- self . isPressed = false
43
+ self . scale = 1.0
44
44
}
45
45
)
46
46
. 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)
51
49
}
52
50
53
51
@ViewBuilder
Original file line number Diff line number Diff line change @@ -18,12 +18,14 @@ open class UKButton: FullWidthComponent, UKComponent {
18
18
/// A Boolean value indicating whether the button is pressed.
19
19
public private( set) var isPressed : Bool = false {
20
20
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
+ }
27
29
}
28
30
}
29
31
@@ -197,7 +199,13 @@ open class UKButton: FullWidthComponent, UKComponent {
197
199
) {
198
200
super. touchesCancelled ( touches, with: event)
199
201
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
+ }
201
209
}
202
210
203
211
open override func traitCollectionDidChange(
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ public struct SUCard<Content: View>: View {
19
19
/// A closure that is triggered when the card is tapped.
20
20
public var onTap : ( ) -> Void
21
21
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
24
24
25
25
@ViewBuilder private let content : ( ) -> Content
26
26
@State private var contentSize : CGSize = . zero
@@ -66,16 +66,14 @@ public struct SUCard<Content: View>: View {
66
66
. simultaneousGesture (
67
67
DragGesture ( minimumDistance: 0.0 )
68
68
. onChanged { _ in
69
- self . isPressed = true
69
+ self . scale = self . model . animationScale . value
70
70
}
71
71
. onEnded { _ in
72
- self . isPressed = false
72
+ self . scale = 1.0
73
73
} ,
74
74
isEnabled: self . model. isTappable
75
75
)
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)
80
78
}
81
79
}
Original file line number Diff line number Diff line change @@ -29,12 +29,14 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
29
29
/// A Boolean value indicating whether the button is pressed.
30
30
public private( set) var isPressed : Bool = false {
31
31
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
+ }
38
40
}
39
41
}
40
42
@@ -168,7 +170,15 @@ open class UKCard<Content: UIView>: UIView, UKComponent {
168
170
) {
169
171
super. touchesCancelled ( touches, with: event)
170
172
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
+ }
172
182
}
173
183
174
184
open override func traitCollectionDidChange(
You can’t perform that action at this time.
0 commit comments