@@ -11,6 +11,7 @@ import UIKit
11
11
protocol WelcomeContentViewDelegate : AnyObject , Sendable {
12
12
func didTapPurchaseButton( welcomeContentView: WelcomeContentView , button: AppButton )
13
13
func didTapInfoButton( welcomeContentView: WelcomeContentView , button: UIButton )
14
+ func didTapCopyButton( welcomeContentView: WelcomeContentView , button: UIButton )
14
15
}
15
16
16
17
struct WelcomeViewModel : Sendable {
@@ -19,6 +20,8 @@ struct WelcomeViewModel: Sendable {
19
20
}
20
21
21
22
final class WelcomeContentView : UIView , Sendable {
23
+ private var revertCopyImageWorkItem : DispatchWorkItem ?
24
+
22
25
private let titleLabel : UILabel = {
23
26
let label = UILabel ( )
24
27
label. font = . preferredFont( forTextStyle: . largeTitle, weight: . bold)
@@ -62,6 +65,14 @@ final class WelcomeContentView: UIView, Sendable {
62
65
return label
63
66
} ( )
64
67
68
+ private let copyButton : UIButton = {
69
+ let button = UIButton ( type: . system)
70
+ button. setAccessibilityIdentifier ( . copyButton)
71
+ button. tintColor = . white
72
+ button. setContentHuggingPriority ( . defaultHigh, for: . horizontal)
73
+ return button
74
+ } ( )
75
+
65
76
private let deviceNameLabel : UILabel = {
66
77
let label = UILabel ( )
67
78
label. adjustsFontForContentSizeCategory = true
@@ -124,6 +135,14 @@ final class WelcomeContentView: UIView, Sendable {
124
135
return stackView
125
136
} ( )
126
137
138
+ private let accountRowStackView : UIStackView = {
139
+ let stackView = UIStackView ( )
140
+ stackView. axis = . horizontal
141
+ stackView. distribution = . fill
142
+ stackView. spacing = UIMetrics . padding8
143
+ return stackView
144
+ } ( )
145
+
127
146
private let deviceRowStackView : UIStackView = {
128
147
let stackView = UIStackView ( )
129
148
stackView. axis = . horizontal
@@ -175,12 +194,16 @@ final class WelcomeContentView: UIView, Sendable {
175
194
}
176
195
177
196
private func configureUI( ) {
197
+ accountRowStackView. addArrangedSubview ( accountNumberLabel)
198
+ accountRowStackView. addArrangedSubview ( copyButton)
199
+ accountRowStackView. addArrangedSubview ( UIView ( ) ) // To push content to the left.
200
+
178
201
textsStackView. addArrangedSubview ( titleLabel)
179
202
textsStackView. setCustomSpacing ( UIMetrics . padding8, after: titleLabel)
180
203
textsStackView. addArrangedSubview ( subtitleLabel)
181
204
textsStackView. setCustomSpacing ( UIMetrics . padding16, after: subtitleLabel)
182
- textsStackView. addArrangedSubview ( accountNumberLabel )
183
- textsStackView. setCustomSpacing ( UIMetrics . padding16, after: accountNumberLabel )
205
+ textsStackView. addArrangedSubview ( accountRowStackView )
206
+ textsStackView. setCustomSpacing ( UIMetrics . padding16, after: accountRowStackView )
184
207
185
208
deviceRowStackView. addArrangedSubview ( deviceNameLabel)
186
209
deviceRowStackView. setCustomSpacing ( UIMetrics . padding8, after: deviceNameLabel)
@@ -196,6 +219,8 @@ final class WelcomeContentView: UIView, Sendable {
196
219
addSubview ( textsStackView)
197
220
addSubview ( buttonsStackView)
198
221
addConstraints ( )
222
+
223
+ showCheckmark ( false )
199
224
}
200
225
201
226
private func addConstraints( ) {
@@ -209,7 +234,7 @@ final class WelcomeContentView: UIView, Sendable {
209
234
}
210
235
211
236
private func addActions( ) {
212
- [ purchaseButton, infoButton] . forEach {
237
+ [ purchaseButton, infoButton, copyButton ] . forEach {
213
238
$0. addTarget ( self , action: #selector( tapped ( button: ) ) , for: . touchUpInside)
214
239
}
215
240
}
@@ -220,7 +245,40 @@ final class WelcomeContentView: UIView, Sendable {
220
245
delegate? . didTapPurchaseButton ( welcomeContentView: self , button: button)
221
246
case AccessibilityIdentifier . infoButton. asString:
222
247
delegate? . didTapInfoButton ( welcomeContentView: self , button: button)
248
+ case AccessibilityIdentifier . copyButton. asString:
249
+ didTapCopyAccountNumber ( )
223
250
default : return
224
251
}
225
252
}
253
+
254
+ private func showCheckmark( _ showCheckmark: Bool ) {
255
+ if showCheckmark {
256
+ let tickIcon = UIImage ( named: " IconTick " )
257
+
258
+ copyButton. setImage ( tickIcon, for: . normal)
259
+ copyButton. tintColor = . successColor
260
+ } else {
261
+ let copyIcon = UIImage ( named: " IconCopy " )
262
+
263
+ copyButton. setImage ( copyIcon, for: . normal)
264
+ copyButton. tintColor = . white
265
+ }
266
+ }
267
+
268
+ @objc private func didTapCopyAccountNumber( ) {
269
+ let delayedWorkItem = DispatchWorkItem { [ weak self] in
270
+ self ? . showCheckmark ( false )
271
+ }
272
+
273
+ revertCopyImageWorkItem? . cancel ( )
274
+ revertCopyImageWorkItem = delayedWorkItem
275
+
276
+ showCheckmark ( true )
277
+ delegate? . didTapCopyButton ( welcomeContentView: self , button: copyButton)
278
+
279
+ DispatchQueue . main. asyncAfter (
280
+ deadline: . now( ) + . seconds( 2 ) ,
281
+ execute: delayedWorkItem
282
+ )
283
+ }
226
284
}
0 commit comments