Skip to content

Commit

Permalink
Merge branch 'develop' into move-stagetag-devtouchpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yeul committed Nov 28, 2023
2 parents 32933dd + 751c903 commit 9ac2a11
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 202 deletions.
13 changes: 1 addition & 12 deletions Demo/Demo/UIKitContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,7 @@ class UIKitContentViewController: UIViewController {
}()

lazy var stackView: UIStackView = {
let paypalMessageContainer = UIView()

paypalMessageContainer.addSubview(paypalMessage)

paypalMessage.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
paypalMessage.leadingAnchor.constraint(equalTo: paypalMessageContainer.leadingAnchor),
paypalMessage.trailingAnchor.constraint(equalTo: paypalMessageContainer.trailingAnchor),
paypalMessage.topAnchor.constraint(equalTo: paypalMessageContainer.topAnchor),
paypalMessage.bottomAnchor.constraint(equalTo: paypalMessageContainer.bottomAnchor, constant: 20)
])


return getStackView(
subviews: [
Expand Down Expand Up @@ -150,7 +139,7 @@ class UIKitContentViewController: UIViewController {
axis: .horizontal
),
getSeparator(),
paypalMessageContainer
paypalMessage
],
padding: 12
)
Expand Down
7 changes: 0 additions & 7 deletions Sources/PayPalMessages/Config/PayPalMessageModalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class PayPalMessageModalDataConfig: NSObject {
var partnerAttributionID: String?
var environment: Environment
var amount: Double?
var currency: String?
var buyerCountry: String?
var offerType: PayPalMessageOfferType?
var placement: PayPalMessagePlacement?
Expand All @@ -49,14 +48,12 @@ class PayPalMessageModalDataConfig: NSObject {
clientID: String,
environment: Environment,
amount: Double? = nil,
currency: String? = nil,
placement: PayPalMessagePlacement? = nil,
offerType: PayPalMessageOfferType? = nil,
modalCloseButton: ModalCloseButtonConfig = ModalCloseButtonConfig()
) {
self.clientID = clientID
self.amount = amount
self.currency = currency
self.placement = placement
self.offerType = offerType
self.modalCloseButton = modalCloseButton
Expand All @@ -70,7 +67,6 @@ class PayPalMessageModalDataConfig: NSObject {
environment: Environment,
partnerAttributionID: String,
amount: Double? = nil,
currency: String? = nil,
placement: PayPalMessagePlacement? = nil,
offerType: PayPalMessageOfferType? = nil,
modalCloseButton: ModalCloseButtonConfig = ModalCloseButtonConfig()
Expand All @@ -79,7 +75,6 @@ class PayPalMessageModalDataConfig: NSObject {
self.merchantID = merchantID
self.partnerAttributionID = partnerAttributionID
self.amount = amount
self.currency = currency
self.placement = placement
self.offerType = offerType
self.modalCloseButton = modalCloseButton
Expand Down Expand Up @@ -120,7 +115,6 @@ class PayPalMessageModalConfig: NSObject, Encodable {
case merchantID = "merchant_id"
case partnerAttributionID = "partner_attribution_id"
case amount
case currency
case buyerCountry
case offerType = "offer"
case channel
Expand All @@ -135,7 +129,6 @@ class PayPalMessageModalConfig: NSObject, Encodable {
try container.encodeIfPresent(data.merchantID, forKey: .merchantID)
try container.encodeIfPresent(data.partnerAttributionID, forKey: .partnerAttributionID)
try container.encodeIfPresent(data.amount, forKey: .amount)
try container.encodeIfPresent(data.currency, forKey: .currency)
try container.encodeIfPresent(data.buyerCountry, forKey: .buyerCountry)
try container.encodeIfPresent(data.offerType?.rawValue, forKey: .offerType)
try container.encodeIfPresent(data.channel, forKey: .channel)
Expand Down
5 changes: 2 additions & 3 deletions Sources/PayPalMessages/PayPalMessageModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ final class PayPalMessageModal: UIViewController, WKUIDelegate {
@Proxy(\.viewModel.amount)
var amount: Double?

@Proxy(\.viewModel.currency)
var currency: String?

@Proxy(\.viewModel.buyerCountry)
var buyerCountry: String?

Expand Down Expand Up @@ -258,6 +255,8 @@ final class PayPalMessageModal: UIViewController, WKUIDelegate {
}

closeButton.translatesAutoresizingMaskIntoConstraints = false
closeButton.isAccessibilityElement = true
closeButton.accessibilityLabel = "PayPal Learn More Modal Close"

view.addSubview(closeButton)

Expand Down
7 changes: 0 additions & 7 deletions Sources/PayPalMessages/PayPalMessageModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
var amount: Double? {
didSet { queueUpdate(from: oldValue, to: amount) }
}
var currency: String? {
didSet { queueUpdate(from: oldValue, to: currency) }
}
var buyerCountry: String? {
didSet { queueUpdate(from: oldValue, to: buyerCountry) }
}
Expand Down Expand Up @@ -69,7 +66,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
"merchant_id": merchantID,
"partner_attribution_id": partnerAttributionID,
"amount": amount?.description,
"currency": currency,
"buyer_country": buyerCountry,
"offer": offerType?.rawValue,
"channel": channel,
Expand Down Expand Up @@ -123,7 +119,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
merchantID = config.data.merchantID
partnerAttributionID = config.data.partnerAttributionID
amount = config.data.amount
currency = config.data.currency
offerType = config.data.offerType
buyerCountry = config.data.buyerCountry
channel = config.data.channel
Expand Down Expand Up @@ -164,7 +159,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
merchantID = config.data.merchantID
partnerAttributionID = config.data.partnerAttributionID
amount = config.data.amount
currency = config.data.currency
offerType = config.data.offerType
buyerCountry = config.data.buyerCountry
channel = config.data.channel
Expand All @@ -177,7 +171,6 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
clientID: self.clientID,
environment: self.environment,
amount: self.amount,
currency: self.currency,
placement: self.placement,
offerType: self.offerType
))
Expand Down
13 changes: 5 additions & 8 deletions Sources/PayPalMessages/PayPalMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public final class PayPalMessageView: UIControl {
addSubview(containerView)

configConstraints()
configAccessibility()
}

private func configConstraints() {
Expand Down Expand Up @@ -232,6 +231,11 @@ extension PayPalMessageView: PayPalMessageViewModelDelegate {
messageLabel.attributedText = PayPalMessageAttributedStringBuilder().makeMessageString(params)
// Force recalculation for layout
invalidateIntrinsicContentSize()

// Update accessibility properties
self.accessibilityLabel = params?.accessibilityLabel ?? ""
self.accessibilityTraits = params?.accessibilityTraits ?? .none
self.isAccessibilityElement = params?.isAccessibilityElement ?? false
}
}

Expand All @@ -244,20 +248,13 @@ extension PayPalMessageView {
super.traitCollectionDidChange(previousTraitCollection)
refreshContent()
}

private func configAccessibility() {
accessibilityTraits = .link
isAccessibilityElement = true
accessibilityLabel = Constants.accessibilityLabel
}
}

// MARK: - Constants

extension PayPalMessageView {

private enum Constants {
static let accessibilityLabel: String = "PayPalMessageView"
static let highlightedAnimationDuration: CGFloat = 1.0
static let highlightedAlpha: CGFloat = 0.75
static let regularAlpha: CGFloat = 1.0
Expand Down
2 changes: 1 addition & 1 deletion Sources/PayPalMessages/PayPalMessageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class PayPalMessageViewModel: PayPalMessageModalEventDelegate {
return parameterBuilder
.makeParameters(
message: response.defaultMainContent,
offerType: response.offerType,
linkDescription: response.defaultDisclaimer,
logoPlaceholder: response.logoPlaceholder,
logoType: logoType,
Expand Down Expand Up @@ -378,7 +379,6 @@ class PayPalMessageViewModel: PayPalMessageModalEventDelegate {
clientID: clientID,
environment: environment,
amount: amount,
// currency: currency, TODO: Implement?
placement: placement,
offerType: offerType,
modalCloseButton: modalCloseButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ struct PayPalMessageViewParameters {
let linkUnderlineColor: UIColor

let textAlignment: NSTextAlignment

let accessibilityLabel: String
let accessibilityTraits: UIAccessibilityTraits
let isAccessibilityElement: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct PayPalMessageViewParametersBuilder {
// swiftlint:disable:next function_parameter_count
func makeParameters(
message: String,
offerType: PayPalMessageResponseOfferType,
linkDescription: String,
logoPlaceholder: String,
logoType: PayPalMessageLogoType,
Expand All @@ -23,6 +24,27 @@ struct PayPalMessageViewParametersBuilder {
productGroup: productGroup
)


// Creates a new sanitized string for use as the accessibilityLabel
let sanitizedMainContent = message
.replacingOccurrences(
of: logoPlaceholder,
with: offerType == .payPalCreditNoInterest ? "PayPal Credit" : "PayPal"
)
.replacingOccurrences(of: "/mo", with: " per month")

var accessibilityLabel = sanitizedMainContent

if !sanitizedMainContent.contains("PayPal") {
if offerType == .payPalCreditNoInterest {
accessibilityLabel = "PayPal Credit - " + accessibilityLabel
} else {
accessibilityLabel = "PayPal - " + accessibilityLabel
}
}

accessibilityLabel = accessibilityLabel + " " + linkDescription

return PayPalMessageViewParameters(
message: message,
messageColor: getLabelColor(payPalColor),
Expand All @@ -33,7 +55,10 @@ struct PayPalMessageViewParametersBuilder {
linkDescription: linkDescription,
linkColor: getLinkColor(payPalColor),
linkUnderlineColor: getUnderlineLinkColor(payPalColor),
textAlignment: getAlignment(payPalAlignment)
textAlignment: getAlignment(payPalAlignment),
accessibilityLabel: accessibilityLabel,
accessibilityTraits: .button,
isAccessibilityElement: true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ final class PayPalMessageAttributedStringTests: XCTestCase {
linkDescription: testLinkDescription,
linkColor: .blue,
linkUnderlineColor: .blue,
textAlignment: .left
textAlignment: .left,
accessibilityLabel: "Pay in several installments with PayPal. Learn More",
accessibilityTraits: .button,
isAccessibilityElement: true
)
}

Expand Down
Loading

0 comments on commit 9ac2a11

Please sign in to comment.