Skip to content

Commit

Permalink
Merge pull request #248 from skyflowapi/public-release/1.20.0
Browse files Browse the repository at this point in the history
SK-1126 Public release/1.20.0
  • Loading branch information
skyflow-bharti authored Oct 6, 2023
2 parents f9bb5f9 + fbe989d commit 17333a8
Show file tree
Hide file tree
Showing 17 changed files with 406 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Skyflow.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |spec|

spec.name = "Skyflow"

spec.version = "1.19.0"
spec.version = "1.20.0"

spec.summary = "skyflow-iOS"

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

spec.ios.deployment_target = "9.0"

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Copy-Icon.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Success-Icon.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Sources/Skyflow/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

import Foundation

var SDK_VERSION = "1.19.0"
var SDK_VERSION = "1.20.0"
71 changes: 70 additions & 1 deletion Sources/Skyflow/elements/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class TextField: SkyflowElement, Element, BaseElement {
internal var stackView = UIStackView()
internal var textFieldLabel = PaddingLabel(frame: .zero)
internal var hasBecomeResponder: Bool = false
internal var copyIconImageView: UIImageView?

internal var textFieldDelegate: UITextFieldDelegate? = nil

Expand Down Expand Up @@ -266,6 +267,12 @@ public class TextField: SkyflowElement, Element, BaseElement {
containerView.addSubview(imageView)
textField.leftView = containerView
}
if self.options.enableCopy {
textField.rightViewMode = UITextField.ViewMode.always
textField.rightView = addCopyIcon()
textField.rightView?.isHidden = true
}


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

}

private func addCopyIcon() -> UIView{
copyIconImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
#if SWIFT_PACKAGE
let image = UIImage(named: "Copy-Icon", in: Bundle.module, compatibleWith: nil)
#else
let frameworkBundle = Bundle(for: TextField.self)
var bundleURL = frameworkBundle.resourceURL
bundleURL!.appendPathComponent("Skyflow.bundle")
let resourceBundle = Bundle(url: bundleURL!)
var image = UIImage(named: "Copy-Icon", in: resourceBundle, compatibleWith: nil)
#endif
copyIconImageView?.image = image
copyIconImageView?.contentMode = .scaleAspectFit
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 24 , height: 24))
containerView.addSubview(copyIconImageView!)
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(copyIconTapped(_:)))
containerView.isUserInteractionEnabled = true
containerView.addGestureRecognizer(tapGesture)
return containerView
}
@objc private func copyIconTapped(_ sender: UITapGestureRecognizer) {
// Copy text when the copy icon is tapped
copy(sender)
}
@objc
public override func copy(_ sender: Any?) {
let pasteboard = UIPasteboard.general
pasteboard.string = actualValue
#if SWIFT_PACKAGE
let image = UIImage(named: "Success-Icon", in: Bundle.module, compatibleWith: nil)
#else
let frameworkBundle = Bundle(for: TextField.self)
var bundleURL = frameworkBundle.resourceURL
bundleURL!.appendPathComponent("Skyflow.bundle")
let resourceBundle = Bundle(url: bundleURL!)
var image = UIImage(named: "Success-Icon", in: resourceBundle, compatibleWith: nil)
#endif
copyIconImageView?.image = image

// Reset the copy icon after a delay
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
#if SWIFT_PACKAGE
let copyImage = UIImage(named: "Copy-Icon", in: Bundle.module, compatibleWith: nil)
#else
let frameworkBundle = Bundle(for: TextField.self)
var bundleURL = frameworkBundle.resourceURL
bundleURL!.appendPathComponent("Skyflow.bundle")
let resourceBundle = Bundle(url: bundleURL!)
var copyImage = UIImage(named: "Copy-Icon", in: resourceBundle, compatibleWith: nil)
#endif
self?.copyIconImageView?.image = copyImage
}

}
internal func updateImage(name: String){

if self.options.enableCardIcon == false {
Expand All @@ -303,7 +364,6 @@ public class TextField: SkyflowElement, Element, BaseElement {
imageView.layer.cornerRadius = self.collectInput!.iconStyles.base?.cornerRadius ?? 0
textField.leftViewMode = .always
textField.leftView = containerView

}

override func validate() -> SkyflowValidationError {
Expand Down Expand Up @@ -415,6 +475,15 @@ extension TextField {
updateImage(name: card.imageName)
}
setFormatPattern()

if self.options.enableCopy && (self.state.getState()["isValid"] as! Bool && !self.actualValue.isEmpty) {
self.textField.rightViewMode = .always
self.textField.rightView?.isHidden = false
} else if self.options.enableCopy {
self.textField.rightViewMode = .always
self.textField.rightView?.isHidden = true
}

}

func updateActualValue() {
Expand Down
10 changes: 9 additions & 1 deletion Sources/Skyflow/elements/TextFieldValidationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ internal class TextFieldValidationDelegate: NSObject, UITextFieldDelegate {
}
let text = ((textField as! FormatTextField).secureText! as NSString).replacingCharacters(in: range, with: string)
let count = text.count

if collectField.fieldType == .EXPIRATION_MONTH {
if collectField.options.enableCopy && (text != "0" && text.count > 0) {
collectField.textField.rightViewMode = .always
collectField.textField.rightView?.isHidden = false
} else if collectField.options.enableCopy {
collectField.textField.rightViewMode = .always
collectField.textField.rightView?.isHidden = true
}
}
if string.isEmpty {
if (collectField.fieldType == .EXPIRATION_MONTH){
(textField as! FormatTextField).secureText = ""
Expand Down
4 changes: 3 additions & 1 deletion Sources/Skyflow/elements/core/CollectElementOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ public struct CollectElementOptions {
var enableCardIcon: Bool
var format: String
var translation: [ Character: String ]?
var enableCopy: Bool


public init(required: Bool? = false, enableCardIcon: Bool = true, format: String = "mm/yy", translation: [ Character: String ]? = nil) {
public init(required: Bool? = false, enableCardIcon: Bool = true, format: String = "mm/yy", translation: [ Character: String ]? = nil, enableCopy: Bool = false) {
self.required = required!
self.enableCardIcon = enableCardIcon
self.format = format
self.translation = translation
self.enableCopy = enableCopy

if (self.translation != nil){
for (key, value) in self.translation! {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Skyflow/reveal/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ public class Label: UIView, Element, BaseElement {
}
}
let formattedText = formatInput(input: value, format: format, translation: self.options.translation!)
self.skyflowLabelView.updateVal(value: formattedText)
self.skyflowLabelView.updateVal(value: formattedText, actualValue: value)
self.actualValue = value
}
else {
self.skyflowLabelView.updateVal(value: value)
self.skyflowLabelView.updateVal(value: value, actualValue: value)
self.actualValue = value
}
}
else {
self.skyflowLabelView.updateVal(value: value)
self.skyflowLabelView.updateVal(value: value, actualValue: value)
self.actualValue = value
}
}
Expand Down Expand Up @@ -218,18 +218,18 @@ public class Label: UIView, Element, BaseElement {
public func setToken(_ token: String) {
self.revealInput.token = token
if self.revealInput.altText.isEmpty {
self.skyflowLabelView.updateVal(value: token)
self.skyflowLabelView.updateVal(value: token, actualValue: nil)
}
}

public func setAltText(_ altText: String) {
self.revealInput.altText = altText
self.skyflowLabelView.updateVal(value: altText)
self.skyflowLabelView.updateVal(value: altText, actualValue: nil)
}

public func clearAltText() {
self.revealInput.altText = ""
self.skyflowLabelView.updateVal(value: actualValue == nil ? revealInput.token : actualValue!)
self.skyflowLabelView.updateVal(value: actualValue == nil ? revealInput.token : actualValue!, actualValue: nil)
}

internal func getToken() -> String{
Expand Down
6 changes: 4 additions & 2 deletions Sources/Skyflow/reveal/RevealElementOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Foundation
public struct RevealElementOptions {
var format: String?
var translation: [ Character: String ]?
var enableCopy: Bool?


public init(format: String? = nil, translation: [ Character: String ]? = nil) {
public init(format: String? = nil, translation: [ Character: String ]? = nil, enableCopy: Bool? = false) {
self.format = format
self.translation = translation
self.enableCopy = enableCopy
if (self.translation != nil){
for (key, value) in self.translation! {
for (_, value) in self.translation! {
if value == "" {
var contextOptions = ContextOptions()
contextOptions.interface = .REVEAL_CONTAINER
Expand Down
7 changes: 5 additions & 2 deletions Sources/Skyflow/reveal/SkyflowLabelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class SkyflowLabelView: UIView {
internal var label = FormatLabel(frame: .zero)
internal var revealInput: RevealElementInput!
internal var options: RevealElementOptions!

internal var horizontalConstraints = [NSLayoutConstraint]()

internal var verticalConstraint = [NSLayoutConstraint]()
Expand Down Expand Up @@ -115,8 +114,12 @@ public class SkyflowLabelView: UIView {
super.init(coder: aDecoder)
}

internal func updateVal(value: String) {
internal func updateVal(value: String, actualValue: String?) {
self.label.secureText = value
if options.enableCopy == true && actualValue != nil {
self.label.copyAfterReveal = true
self.label.actualValue = actualValue ?? ""
}
}

internal func buildLabel() {
Expand Down
Loading

0 comments on commit 17333a8

Please sign in to comment.