Skip to content

Commit 17333a8

Browse files
Merge pull request #248 from skyflowapi/public-release/1.20.0
SK-1126 Public release/1.20.0
2 parents f9bb5f9 + fbe989d commit 17333a8

File tree

17 files changed

+406
-53
lines changed

17 files changed

+406
-53
lines changed

Skyflow.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |spec|
22

33
spec.name = "Skyflow"
44

5-
spec.version = "1.19.0"
5+
spec.version = "1.20.0"
66

77
spec.summary = "skyflow-iOS"
88

@@ -20,7 +20,7 @@ Pod::Spec.new do |spec|
2020

2121
spec.ios.deployment_target = "9.0"
2222

23-
spec.source = { :git => "https://github.com/skyflowapi/skyflow-iOS.git", :tag => "1.19.0" }
23+
spec.source = { :git => "https://github.com/skyflowapi/skyflow-iOS.git", :tag => "1.20.0" }
2424

2525
spec.source_files = "Sources/Skyflow/**/*.{swift}"
2626

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"scale" : "2x"
10+
},
11+
{
12+
"filename" : "Copy-Icon.png",
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
265 Bytes
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"scale" : "2x"
10+
},
11+
{
12+
"filename" : "Success-Icon.png",
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
487 Bytes
Loading

Sources/Skyflow/Version.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
import Foundation
1313

14-
var SDK_VERSION = "1.19.0"
14+
var SDK_VERSION = "1.20.0"

Sources/Skyflow/elements/TextField.swift

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class TextField: SkyflowElement, Element, BaseElement {
2323
internal var stackView = UIStackView()
2424
internal var textFieldLabel = PaddingLabel(frame: .zero)
2525
internal var hasBecomeResponder: Bool = false
26+
internal var copyIconImageView: UIImageView?
2627

2728
internal var textFieldDelegate: UITextFieldDelegate? = nil
2829

@@ -266,6 +267,12 @@ public class TextField: SkyflowElement, Element, BaseElement {
266267
containerView.addSubview(imageView)
267268
textField.leftView = containerView
268269
}
270+
if self.options.enableCopy {
271+
textField.rightViewMode = UITextField.ViewMode.always
272+
textField.rightView = addCopyIcon()
273+
textField.rightView?.isHidden = true
274+
}
275+
269276

270277
if self.fieldType == .CARD_NUMBER {
271278
let t = self.textField.secureText!.replacingOccurrences(of: "-", with: "").replacingOccurrences(of: " ", with: "")
@@ -277,6 +284,60 @@ public class TextField: SkyflowElement, Element, BaseElement {
277284

278285
}
279286

287+
private func addCopyIcon() -> UIView{
288+
copyIconImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
289+
#if SWIFT_PACKAGE
290+
let image = UIImage(named: "Copy-Icon", in: Bundle.module, compatibleWith: nil)
291+
#else
292+
let frameworkBundle = Bundle(for: TextField.self)
293+
var bundleURL = frameworkBundle.resourceURL
294+
bundleURL!.appendPathComponent("Skyflow.bundle")
295+
let resourceBundle = Bundle(url: bundleURL!)
296+
var image = UIImage(named: "Copy-Icon", in: resourceBundle, compatibleWith: nil)
297+
#endif
298+
copyIconImageView?.image = image
299+
copyIconImageView?.contentMode = .scaleAspectFit
300+
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 24 , height: 24))
301+
containerView.addSubview(copyIconImageView!)
302+
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(copyIconTapped(_:)))
303+
containerView.isUserInteractionEnabled = true
304+
containerView.addGestureRecognizer(tapGesture)
305+
return containerView
306+
}
307+
@objc private func copyIconTapped(_ sender: UITapGestureRecognizer) {
308+
// Copy text when the copy icon is tapped
309+
copy(sender)
310+
}
311+
@objc
312+
public override func copy(_ sender: Any?) {
313+
let pasteboard = UIPasteboard.general
314+
pasteboard.string = actualValue
315+
#if SWIFT_PACKAGE
316+
let image = UIImage(named: "Success-Icon", in: Bundle.module, compatibleWith: nil)
317+
#else
318+
let frameworkBundle = Bundle(for: TextField.self)
319+
var bundleURL = frameworkBundle.resourceURL
320+
bundleURL!.appendPathComponent("Skyflow.bundle")
321+
let resourceBundle = Bundle(url: bundleURL!)
322+
var image = UIImage(named: "Success-Icon", in: resourceBundle, compatibleWith: nil)
323+
#endif
324+
copyIconImageView?.image = image
325+
326+
// Reset the copy icon after a delay
327+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
328+
#if SWIFT_PACKAGE
329+
let copyImage = UIImage(named: "Copy-Icon", in: Bundle.module, compatibleWith: nil)
330+
#else
331+
let frameworkBundle = Bundle(for: TextField.self)
332+
var bundleURL = frameworkBundle.resourceURL
333+
bundleURL!.appendPathComponent("Skyflow.bundle")
334+
let resourceBundle = Bundle(url: bundleURL!)
335+
var copyImage = UIImage(named: "Copy-Icon", in: resourceBundle, compatibleWith: nil)
336+
#endif
337+
self?.copyIconImageView?.image = copyImage
338+
}
339+
340+
}
280341
internal func updateImage(name: String){
281342

282343
if self.options.enableCardIcon == false {
@@ -303,7 +364,6 @@ public class TextField: SkyflowElement, Element, BaseElement {
303364
imageView.layer.cornerRadius = self.collectInput!.iconStyles.base?.cornerRadius ?? 0
304365
textField.leftViewMode = .always
305366
textField.leftView = containerView
306-
307367
}
308368

309369
override func validate() -> SkyflowValidationError {
@@ -415,6 +475,15 @@ extension TextField {
415475
updateImage(name: card.imageName)
416476
}
417477
setFormatPattern()
478+
479+
if self.options.enableCopy && (self.state.getState()["isValid"] as! Bool && !self.actualValue.isEmpty) {
480+
self.textField.rightViewMode = .always
481+
self.textField.rightView?.isHidden = false
482+
} else if self.options.enableCopy {
483+
self.textField.rightViewMode = .always
484+
self.textField.rightView?.isHidden = true
485+
}
486+
418487
}
419488

420489
func updateActualValue() {

Sources/Skyflow/elements/TextFieldValidationDelegate.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ internal class TextFieldValidationDelegate: NSObject, UITextFieldDelegate {
8282
}
8383
let text = ((textField as! FormatTextField).secureText! as NSString).replacingCharacters(in: range, with: string)
8484
let count = text.count
85-
85+
if collectField.fieldType == .EXPIRATION_MONTH {
86+
if collectField.options.enableCopy && (text != "0" && text.count > 0) {
87+
collectField.textField.rightViewMode = .always
88+
collectField.textField.rightView?.isHidden = false
89+
} else if collectField.options.enableCopy {
90+
collectField.textField.rightViewMode = .always
91+
collectField.textField.rightView?.isHidden = true
92+
}
93+
}
8694
if string.isEmpty {
8795
if (collectField.fieldType == .EXPIRATION_MONTH){
8896
(textField as! FormatTextField).secureText = ""

Sources/Skyflow/elements/core/CollectElementOptions.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public struct CollectElementOptions {
1414
var enableCardIcon: Bool
1515
var format: String
1616
var translation: [ Character: String ]?
17+
var enableCopy: Bool
1718

1819

19-
public init(required: Bool? = false, enableCardIcon: Bool = true, format: String = "mm/yy", translation: [ Character: String ]? = nil) {
20+
public init(required: Bool? = false, enableCardIcon: Bool = true, format: String = "mm/yy", translation: [ Character: String ]? = nil, enableCopy: Bool = false) {
2021
self.required = required!
2122
self.enableCardIcon = enableCardIcon
2223
self.format = format
2324
self.translation = translation
25+
self.enableCopy = enableCopy
2426

2527
if (self.translation != nil){
2628
for (key, value) in self.translation! {

Sources/Skyflow/reveal/Label.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@ public class Label: UIView, Element, BaseElement {
108108
}
109109
}
110110
let formattedText = formatInput(input: value, format: format, translation: self.options.translation!)
111-
self.skyflowLabelView.updateVal(value: formattedText)
111+
self.skyflowLabelView.updateVal(value: formattedText, actualValue: value)
112112
self.actualValue = value
113113
}
114114
else {
115-
self.skyflowLabelView.updateVal(value: value)
115+
self.skyflowLabelView.updateVal(value: value, actualValue: value)
116116
self.actualValue = value
117117
}
118118
}
119119
else {
120-
self.skyflowLabelView.updateVal(value: value)
120+
self.skyflowLabelView.updateVal(value: value, actualValue: value)
121121
self.actualValue = value
122122
}
123123
}
@@ -218,18 +218,18 @@ public class Label: UIView, Element, BaseElement {
218218
public func setToken(_ token: String) {
219219
self.revealInput.token = token
220220
if self.revealInput.altText.isEmpty {
221-
self.skyflowLabelView.updateVal(value: token)
221+
self.skyflowLabelView.updateVal(value: token, actualValue: nil)
222222
}
223223
}
224224

225225
public func setAltText(_ altText: String) {
226226
self.revealInput.altText = altText
227-
self.skyflowLabelView.updateVal(value: altText)
227+
self.skyflowLabelView.updateVal(value: altText, actualValue: nil)
228228
}
229229

230230
public func clearAltText() {
231231
self.revealInput.altText = ""
232-
self.skyflowLabelView.updateVal(value: actualValue == nil ? revealInput.token : actualValue!)
232+
self.skyflowLabelView.updateVal(value: actualValue == nil ? revealInput.token : actualValue!, actualValue: nil)
233233
}
234234

235235
internal func getToken() -> String{

0 commit comments

Comments
 (0)