Skip to content

Commit

Permalink
Public Release 1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokhl authored Jul 19, 2023
2 parents 1c96933 + 4e977df commit 669a8a3
Show file tree
Hide file tree
Showing 69 changed files with 574 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal extension VGSLabel {
setDefaultStyle()
// add UI elements
buildUI()

// setup accessibility
vgsIsAccessibilityElement = true
labelModel.onValueChanged = { [weak self](text) in
self?.revealedRawText = text
}
Expand Down
82 changes: 55 additions & 27 deletions Sources/VGSShowSDK/UIElements/VGSLabel/VGSLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,39 +219,67 @@ public final class VGSLabel: UIView, VGSLabelProtocol {
didSet { setPlaceholderPaddings() }
}

/// A succinct label in a localized string that identifies the accessibility element.
public var vgsAccessibilityLabel: String?
{
get {
return label.accessibilityLabel
}

set {
label.accessibilityLabel = newValue
// MARK: - Accessibility Attributes
/// A succinct label in a localized string that
/// identifies the accessibility element.
public var vgsAccessibilityLabel: String? {
get {
return label.accessibilityLabel
}
set {
label.accessibilityLabel = newValue
placeholderLabel.accessibilityLabel = label.accessibilityLabel
}
}
}

/// A localized string that contains a brief description of the result of performing an action on the accessibility element.
public var vgsAccessibilityHint: String?
{
get {
return label.accessibilityHint
/// A localized string that contains a brief description of the result of
/// performing an action on the accessibility element.
public var vgsAccessibilityHint: String? {
get {
return label.accessibilityHint
}
set {
label.accessibilityHint = newValue
placeholderLabel.accessibilityHint = label.accessibilityHint
}
}

set {
label.accessibilityHint = newValue

/// Boolean value that determinates if the text field should be exposed as
/// an accesibility element.
public var vgsIsAccessibilityElement: Bool {
get {
return label.isAccessibilityElement
}
set {
label.isAccessibilityElement = newValue
placeholderLabel.isAccessibilityElement = label.isAccessibilityElement
}
}
}

/// `VGSLabel` text font.
public var font: UIFont? {
get {
return label.font

// MARK: - Font Attributes
/// Indicates whether `VGSLabel ` should automatically update its font
/// when the device’s `UIContentSizeCategory` is changed. It only works
/// automatically with dynamic fonts
public var vgsAdjustsFontForContentSizeCategory: Bool {
get {
return label.adjustsFontForContentSizeCategory
}
set {
label.adjustsFontForContentSizeCategory = newValue
placeholderLabel.adjustsFontForContentSizeCategory = label.adjustsFontForContentSizeCategory
}
}
set {
label.font = newValue

/// `VGSLabel` text font. By default use default dynamic font style `.body` to update its size
/// automatically when the device’s `UIContentSizeCategory` changed.
public var font: UIFont? {
get {
return label.font
}
set {
label.font = newValue
}
}
}

/// Number of lines.
public var numberOfLines: Int {
Expand Down
7 changes: 6 additions & 1 deletion Sources/VGSShowSDK/UIElements/VGSPlaceholderLabelStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public struct VGSPlaceholderLabelStyle {
public var color: UIColor = UIColor.gray.withAlphaComponent(0.7)

/// Font.
public var font: UIFont?
public var font: UIFont?

/// Indicates whether placeholder should automatically update its font
/// when the device’s `UIContentSizeCategory` is changed. It only works
/// automatically with dynamic fonts
public var adjustsFontForContentSizeCategory: Bool = false

/// Number of lines, default is `1`.
public var numberOfLines: Int = 1
Expand Down
2 changes: 1 addition & 1 deletion Sources/VGSShowSDK/Utils/Helpers/VGSUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ internal class Utils {

/// VGS Show SDK Version.
/// Necessary since SPM doesn't track info plist correctly: https://forums.swift.org/t/add-info-plist-on-spm-bundle/40274/5
static let vgsShowVersion = "1.1.5"
static let vgsShowVersion = "1.1.6"
}
27 changes: 27 additions & 0 deletions Tests/VGSShowSDKTests/UIElements/VGSImageViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,31 @@ class VGSImageViewTests: XCTestCase {
XCTAssertNil(imageViewChild?.image)
XCTAssertNotNil(imageView.baseImageView.secureImage)
}

/// Test accessibility properties
func testPDFAccessibilityAttributes() {
let imageView = VGSImageView()

// Hint
let accHint = "accessibility hint"
imageView.accessibilityHint = accHint
XCTAssertNotNil(imageView.accessibilityHint)
XCTAssertEqual(imageView.accessibilityHint, accHint)

// Label
let accLabel = "accessibility label"
imageView.accessibilityLabel = accLabel
XCTAssertNotNil(imageView.accessibilityLabel)
XCTAssertEqual(imageView.accessibilityLabel, accLabel)

// Element
imageView.isAccessibilityElement = true
XCTAssertTrue(imageView.isAccessibilityElement)

// Value
let accValue = "acc value"
imageView.accessibilityValue = accValue
XCTAssertNotNil(imageView.accessibilityValue)
XCTAssertEqual(imageView.accessibilityValue, accValue)
}
}
58 changes: 44 additions & 14 deletions Tests/VGSShowSDKTests/UIElements/VGSLabelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,50 @@ import XCTest
@testable import VGSShowSDK

class VGSLabelTests: XCTestCase {

/// Test valid jsonSelectors.
func testLabelTextAttributes() {
let label = VGSLabel()
label.contentPath = "test.label"

XCTAssertTrue(label.contentPath == "test.label")
XCTAssertTrue(label.isEmpty)

label.label.secureText = "123"
XCTAssertFalse(label.isEmpty)
XCTAssertTrue( label.label.text == nil)
/// Test valid jsonSelectors.
func testLabelTextAttributes() {
let label = VGSLabel()
label.contentPath = "test.label"

XCTAssertTrue(label.contentPath == "test.label")
XCTAssertTrue(label.isEmpty)

label.label.secureText = "123"
XCTAssertFalse(label.isEmpty)
XCTAssertTrue(label.label.text == nil)

label.label.secureText = ""
XCTAssertTrue(label.isEmpty)
}

label.label.secureText = ""
XCTAssertTrue(label.isEmpty)
}
/// Test accessibility properties
func testLabelAccessibilityAttributes() {
let labelView = VGSLabel()

// Label
let accLabel = "accessibility label"
labelView.vgsAccessibilityLabel = accLabel
XCTAssertNotNil(labelView.vgsAccessibilityLabel)
XCTAssertEqual(labelView.vgsAccessibilityLabel, accLabel)

// Hint
let accHint = "accessibility hint"
labelView.vgsAccessibilityHint = accHint
XCTAssertNotNil(labelView.vgsAccessibilityHint)
XCTAssertEqual(labelView.vgsAccessibilityHint, accHint)

// Element
labelView.vgsIsAccessibilityElement = true
XCTAssertTrue(labelView.vgsIsAccessibilityElement)

// Value
let accValue = "123"
labelView.label.secureText = accValue
XCTAssertFalse(labelView.isEmpty)
XCTAssertNil(labelView.label.accessibilityValue)
labelView.isSecureText = true
XCTAssertTrue(labelView.isEmpty)
XCTAssertNil(labelView.label.accessibilityValue)
}
}
27 changes: 27 additions & 0 deletions Tests/VGSShowSDKTests/UIElements/VGSPDFViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,31 @@ class VGSPDFViewTests: XCTestCase {
pdfView.maskedPdfView.secureDocument = nil
XCTAssertFalse(pdfView.hasDocument)
}

/// Test accessibility properties
func testPDFAccessibilityAttributes() {
let pdfView = VGSPDFView()

// Hint
let accHint = "accessibility hint"
pdfView.accessibilityHint = accHint
XCTAssertNotNil(pdfView.accessibilityHint)
XCTAssertEqual(pdfView.accessibilityHint, accHint)

// Label
let accLabel = "accessibility label"
pdfView.accessibilityLabel = accLabel
XCTAssertNotNil(pdfView.accessibilityLabel)
XCTAssertEqual(pdfView.accessibilityLabel, accLabel)

// Element
pdfView.isAccessibilityElement = true
XCTAssertTrue(pdfView.isAccessibilityElement)

// Value
let accValue = "acc value"
pdfView.accessibilityValue = accValue
XCTAssertNotNil(pdfView.accessibilityValue)
XCTAssertEqual(pdfView.accessibilityValue, accValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class CollectViewController: UIViewController {

vgsCollect.textFields.forEach { textField in
textField.textColor = UIColor.inputBlackTextColor
textField.font = .systemFont(ofSize: 22)
textField.padding = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
textField.tintColor = .lightGray
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,70 +78,64 @@ class ShowDemoViewController: UIViewController {

// MARK: - Helpers

private func configureUI() {
let paddings = UIEdgeInsets.init(top: 8, left: 8, bottom: 8, right: 8)
let textColor = UIColor.white
let borderColor = UIColor.clear
let font = UIFont.systemFont(ofSize: 20)
let backgroundColor = UIColor.clear
let cornerRadius: CGFloat = 6
let textAlignment = NSTextAlignment.left

let placeholderColor = UIColor.white.withAlphaComponent(0.7)

// Secure revealed data with mask in ranges
cardNumberLabel.isSecureText = true
cardNumberLabel.setSecureText(ranges: [VGSTextRange(start: 5, end: 8),
VGSTextRange(start: 10, end: 13)])

// cardNumberLabel.vgsAccessibilityLabel = "Card number"
// cardNumberLabel.vgsAccessibilityHint = "Tap to show card number"
// expDateLabel.vgsAccessibilityLabel = "Expiration date"
// cardHolderNameLabel.vgsAccessibilityLabel = "Cardholder"

// Set placeholder text. Placeholder will appear until revealed text will be set in VGSLabel
cardNumberLabel.placeholder = "XXXX XXXX XXXX XXXX"
cardNumberLabel.contentPath = "json.payment_card_number"

// Create regex object, split card number to XXXX-XXXX-XXXX-XXXX format.
do {
let cardNumberPattern = "(\\d{4})(\\d{4})(\\d{4})(\\d{4})"
let template = "$1 $2 $3 $4"
let regex = try NSRegularExpression(pattern: cardNumberPattern, options: [])

// Add transformation regex to your label.
cardNumberLabel.addTransformationRegex(regex, template: template)
} catch {
assertionFailure("invalid regex, error: \(error)")
}

expDateLabel.placeholder = "XX/XX"
expDateLabel.contentPath = "json.payment_card_expiration_date"

cardHolderNameLabel.placeholder = "XXXXXXXXXXXXXXXXXXX"
cardHolderNameLabel.contentPath = "json.payment_card_holder_name"

// Set default VGSLabel UI style
vgsShow.subscribedLabels.forEach {
$0.textAlignment = textAlignment
$0.textColor = textColor
$0.paddings = paddings
$0.borderColor = borderColor
$0.font = font
$0.backgroundColor = backgroundColor
$0.layer.cornerRadius = cornerRadius
$0.characterSpacing = 0.83
$0.placeholderStyle.color = placeholderColor
$0.placeholderStyle.textAlignment = textAlignment

// set delegate to follow the updates in VGSLabel
$0.delegate = self
private func configureUI() {
let paddings = UIEdgeInsets.init(top: 8, left: 8, bottom: 8, right: 8)
let textColor = UIColor.white
let borderColor = UIColor.clear
let backgroundColor = UIColor.clear
let cornerRadius: CGFloat = 6
let textAlignment = NSTextAlignment.left
let placeholderColor = UIColor.white.withAlphaComponent(0.7)

// Secure revealed data with mask in ranges
cardNumberLabel.isSecureText = true
cardNumberLabel.setSecureText(
ranges: [VGSTextRange(start: 5, end: 8),
VGSTextRange(start: 10, end: 13)]
)

// Set placeholder text. Placeholder will appear until revealed text will be set in VGSLabel
cardNumberLabel.placeholder = "XXXX XXXX XXXX XXXX"
cardNumberLabel.contentPath = "json.payment_card_number"

// Create regex object, split card number to XXXX-XXXX-XXXX-XXXX format.
do {
let cardNumberPattern = "(\\d{4})(\\d{4})(\\d{4})(\\d{4})"
let template = "$1 $2 $3 $4"
let regex = try NSRegularExpression(pattern: cardNumberPattern, options: [])

// Add transformation regex to your label.
cardNumberLabel.addTransformationRegex(regex, template: template)
} catch {
assertionFailure("invalid regex, error: \(error)")
}

expDateLabel.placeholder = "XX/XX"
expDateLabel.contentPath = "json.payment_card_expiration_date"

cardHolderNameLabel.placeholder = "XXXXXXXXXXXXXXXXXXX"
cardHolderNameLabel.contentPath = "json.payment_card_holder_name"

// Set default VGSLabel UI style
vgsShow.subscribedLabels.forEach {
$0.textAlignment = textAlignment
$0.textColor = textColor
$0.paddings = paddings
$0.borderColor = borderColor
$0.backgroundColor = backgroundColor
$0.layer.cornerRadius = cornerRadius
$0.characterSpacing = 0.83
$0.placeholderStyle.color = placeholderColor
$0.placeholderStyle.textAlignment = textAlignment

// set delegate to follow the updates in VGSLabel
$0.delegate = self
}

stackView.addArrangedSubview(cardHolderNameLabel)
stackView.addArrangedSubview(cardNumberLabel)
stackView.addArrangedSubview(expDateLabel)
}

stackView.addArrangedSubview(cardHolderNameLabel)
stackView.addArrangedSubview(cardNumberLabel)
stackView.addArrangedSubview(expDateLabel)
}

private func loadData() {

Expand Down
2 changes: 1 addition & 1 deletion VGSShowSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "VGSShowSDK"
spec.version = "1.1.5"
spec.version = "1.1.6"
spec.summary = "VGS Show - is a product suite that allows customers to reveal and show information securely without possession of it."
spec.swift_version = '5.0'
spec.description = <<-DESC
Expand Down
Loading

0 comments on commit 669a8a3

Please sign in to comment.