diff --git a/Afterpay.xcodeproj/project.pbxproj b/Afterpay.xcodeproj/project.pbxproj index ed0c7591..81b92d47 100644 --- a/Afterpay.xcodeproj/project.pbxproj +++ b/Afterpay.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 6602EF0F25358A8000A0468C /* ColorScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6602EF0E25358A8000A0468C /* ColorScheme.swift */; }; 6605666324E5199500DA588E /* Locales.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6605666224E5199500DA588E /* Locales.swift */; }; 6615F99B24D14620005036F1 /* SVG.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6615F99A24D14620005036F1 /* SVG.swift */; }; + 661CFDB62570E7F000D8A1E8 /* PaymentButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */; }; 662A3AED24A999A500EFD826 /* CheckoutResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662A3AEC24A999A500EFD826 /* CheckoutResult.swift */; }; 6635B95F24CAA9F000EBB3A6 /* ConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6635B95E24CAA9F000EBB3A6 /* ConfigurationTests.swift */; }; 6640C15224D8E1A700F7F4CC /* Macaw in Frameworks */ = {isa = PBXBuildFile; productRef = 6640C15124D8E1A700F7F4CC /* Macaw */; }; @@ -48,6 +49,7 @@ 6602EF0E25358A8000A0468C /* ColorScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorScheme.swift; sourceTree = ""; }; 6605666224E5199500DA588E /* Locales.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locales.swift; sourceTree = ""; }; 6615F99A24D14620005036F1 /* SVG.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SVG.swift; sourceTree = ""; }; + 661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButton.swift; sourceTree = ""; }; 662A3AEC24A999A500EFD826 /* CheckoutResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckoutResult.swift; sourceTree = ""; }; 6632E0AE248A0171007F0BD9 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 6635B95E24CAA9F000EBB3A6 /* ConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationTests.swift; sourceTree = ""; }; @@ -111,6 +113,7 @@ 66EE9BD624DCEC3D00A81C19 /* LinkTextView.swift */, 66483F3A24D7A164000BE6B5 /* PriceBreakdownView.swift */, 66639B5324D2619200C68558 /* SVGView.swift */, + 661CFDB52570E7F000D8A1E8 /* PaymentButton.swift */, ); path = Views; sourceTree = ""; @@ -438,6 +441,7 @@ 6689536C24C96CB5005090B4 /* Configuration.swift in Sources */, 15F7DDB725393BD30011EC25 /* CurrencyFormatter.swift in Sources */, 66DAAC8B24E0CF0100127460 /* PriceBreakdown.swift in Sources */, + 661CFDB62570E7F000D8A1E8 /* PaymentButton.swift in Sources */, 662A3AED24A999A500EFD826 /* CheckoutResult.swift in Sources */, 667AD3542497121200BF94E5 /* CheckoutWebViewController.swift in Sources */, 66F9767C2499A11A001D38FA /* Afterpay.swift in Sources */, diff --git a/Configurations/Afterpay-Shared.xcconfig b/Configurations/Afterpay-Shared.xcconfig index c5bc493d..c7989288 100644 --- a/Configurations/Afterpay-Shared.xcconfig +++ b/Configurations/Afterpay-Shared.xcconfig @@ -169,4 +169,4 @@ TARGETED_DEVICE_FAMILY = 1,2 // This setting defines the user-visible version of the project. The value corresponds to // the `CFBundleShortVersionString` key in your app's Info.plist. -MARKETING_VERSION = 1.3.0 +MARKETING_VERSION = 1.4.0 diff --git a/Example/Example/Purchase/CartViewController.swift b/Example/Example/Purchase/CartViewController.swift index b8f306f7..50145715 100644 --- a/Example/Example/Purchase/CartViewController.swift +++ b/Example/Example/Purchase/CartViewController.swift @@ -6,6 +6,7 @@ // Copyright © 2020 Afterpay. All rights reserved. // +import Afterpay import Foundation final class CartViewController: UIViewController, UITableViewDataSource { @@ -44,9 +45,8 @@ final class CartViewController: UIViewController, UITableViewDataSource { tableView.register(ProductCell.self, forCellReuseIdentifier: productCellIdentifier) tableView.register(TitleSubtitleCell.self, forCellReuseIdentifier: titleSubtitleCellIdentifier) - let payButton: UIButton = .primaryButton + let payButton: UIButton = PaymentButton() payButton.isEnabled = cart.payEnabled - payButton.setTitle("Pay with Afterpay", for: .normal) payButton.addTarget(self, action: #selector(didTapPay), for: .touchUpInside) view.addSubview(tableView) @@ -57,9 +57,9 @@ final class CartViewController: UIViewController, UITableViewDataSource { tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor), tableView.bottomAnchor.constraint(equalTo: payButton.topAnchor), - payButton.leadingAnchor.constraint(equalTo: view.leadingAnchor), - payButton.trailingAnchor.constraint(equalTo: view.trailingAnchor), - payButton.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor), + payButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), + payButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16), + payButton.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor, constant: -16), ]) } diff --git a/Images/button_black_on_mint.png b/Images/button_black_on_mint.png new file mode 100644 index 00000000..2b884033 Binary files /dev/null and b/Images/button_black_on_mint.png differ diff --git a/Images/button_black_on_white.png b/Images/button_black_on_white.png new file mode 100644 index 00000000..7e81a1c7 Binary files /dev/null and b/Images/button_black_on_white.png differ diff --git a/Images/button_mint_on_black.png b/Images/button_mint_on_black.png new file mode 100644 index 00000000..bc71f308 Binary files /dev/null and b/Images/button_mint_on_black.png differ diff --git a/Images/button_white_on_black.png b/Images/button_white_on_black.png new file mode 100644 index 00000000..09a2903f Binary files /dev/null and b/Images/button_white_on_black.png differ diff --git a/Package.resolved b/Package.resolved index 6ff3d42d..8871298e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -2,12 +2,21 @@ "object": { "pins": [ { - "package": "SwiftSVG", - "repositoryURL": "https://github.com/mchoe/SwiftSVG.git", + "package": "Macaw", + "repositoryURL": "https://github.com/exyte/Macaw.git", "state": { "branch": null, - "revision": "c3a8866a25ace169ee8e5c037670ba14aa59606f", - "version": "2.3.2" + "revision": "7cb4f5876423435e1a41628417230accc37284c6", + "version": "0.9.7" + } + }, + { + "package": "SWXMLHash", + "repositoryURL": "https://github.com/drmohundro/SWXMLHash", + "state": { + "branch": null, + "revision": "a4931e5c3bafbedeb1601d3bb76bbe835c6d475a", + "version": "5.0.1" } } ] diff --git a/README.md b/README.md index 036e4cff..69dff386 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Add the Afterpay SDK as a [git submodule][git-submodule] by navigating to the ro ``` git submodule add https://github.com/afterpay/sdk-ios.git Afterpay cd Afterpay -git checkout 1.3.0 +git checkout 1.4.0 ``` #### Project / Workspace Integration @@ -163,18 +163,11 @@ BOOL (^challengeHandler)(NSURLAuthenticationChallenge *, CompletionHandler) = ^B [APAfterpay setAuthenticationChallengeHandler:challengeHandler]; ``` -## Badge +## Views -The Afterpay badge is a simple UIView that can be scaled to suit the needs of your app. As per branding guidelines it has a minimum width constraint of 64 points. +### Color Schemes -```swift -let badgeView = BadgeView() -``` - -The badge has four styles to fit light and dark themes: -![Black on Mint badge][badge-black-on-mint] ![Mint on Black badge][badge-mint-on-black] ![White on Black badge][badge-white-on-black] ![Black on White badge][badge-black-on-white] - -Color schemes can be set on the badge view to have a single style in both light and dark mode or to change automatically. +Color schemes can be set on the badge view or payment button to either have a single style in both light and dark mode or to change automatically. ```swift // Always black on mint @@ -184,6 +177,27 @@ badgeView.colorScheme = .static(.blackOnMint) badgeView.colorScheme = .dynamic(lightPalette: .whiteOnBlack, darkPalette: .blackOnWhite) ``` +### Badge + +The Afterpay badge is a simple `UIView` that can be scaled to suit the needs of your app. As per branding guidelines it has a minimum width constraint of 64 points. + +```swift +let badgeView = BadgeView() +``` + +Below are examples of the badge in each of the color schemes: +![Black on Mint badge][badge-black-on-mint] ![Mint on Black badge][badge-mint-on-black] ![White on Black badge][badge-white-on-black] ![Black on White badge][badge-black-on-white] + +### Payment Button + +The Afterpay Payment Button is a subclass of `UIButton` that can be scaled to suit your layout, to guarantee legibility it has a maximum width constraint of 256 points. + +Below are examples of the button in each of the color schemes: +| Mint and Black | Black and White | +| -- | -- | +| ![Black on Mint button][button-black-on-mint] | ![White on Black button][button-white-on-black] | +| ![Mint on Black button][button-mint-on-black] | ![Black on White button][button-black-on-white] | + ## Price Breakdown The price breakdown component displays information about Afterpay instalments and handles a number of common scenarios. @@ -351,6 +365,10 @@ This project is licensed under the terms of the Apache 2.0 license. See the [LIC [badge-mint-on-black]: Images/badge_mint_on_black.png [badge-white-on-black]: Images/badge_white_on_black.png [badge-black-on-white]: Images/badge_black_on_white.png +[button-black-on-mint]: Images/button_black_on_mint.png +[button-mint-on-black]: Images/button_mint_on_black.png +[button-white-on-black]: Images/button_white_on_black.png +[button-black-on-white]: Images/button_black_on_white.png [bootstrap]: Scripts/bootstrap [carthage]: https://github.com/Carthage/Carthage [ccp]: https://cocoapods.org/pods/Afterpay diff --git a/Sources/Afterpay/Afterpay.swift b/Sources/Afterpay/Afterpay.swift index ff8b8906..844a397d 100644 --- a/Sources/Afterpay/Afterpay.swift +++ b/Sources/Afterpay/Afterpay.swift @@ -94,3 +94,7 @@ public func setConfiguration(_ configuration: Configuration?) { notificationCenter.post(name: .configurationUpdated, object: previousConfiguration) } + +func getLocale() -> Locale { + getConfiguration()?.locale ?? Locales.unitedStates +} diff --git a/Sources/Afterpay/Resources/SVG.swift b/Sources/Afterpay/Resources/SVG.swift index 0128383a..ba34c343 100644 --- a/Sources/Afterpay/Resources/SVG.swift +++ b/Sources/Afterpay/Resources/SVG.swift @@ -14,7 +14,7 @@ import Macaw #endif import UIKit -// swiftlint:disable line_length +// swiftlint:disable line_length file_length type_body_length struct SVG: Equatable { let size: CGSize @@ -30,7 +30,7 @@ struct SVG: Equatable { self.svgString = svgString } - static let afterpayBlackOnMint = SVG( + static let afterpayBadgeBlackOnMint = SVG( size: CGSize(width: 1582, height: 551), minimumWidth: 64, svgString: """ @@ -55,7 +55,7 @@ struct SVG: Equatable { """ ) - static let clearpayBlackOnMint = SVG( + static let clearpayBadgeBlackOnMint = SVG( size: CGSize(width: 1620, height: 551), minimumWidth: 64, svgString: """ @@ -74,7 +74,7 @@ struct SVG: Equatable { """ ) - static let afterpayMintOnBlack = SVG( + static let afterpayBadgeMintOnBlack = SVG( size: CGSize(width: 1582, height: 551), minimumWidth: 64, svgString: """ @@ -99,7 +99,7 @@ struct SVG: Equatable { """ ) - static let clearpayMintOnBlack = SVG( + static let clearpayBadgeMintOnBlack = SVG( size: CGSize(width: 1620, height: 551), minimumWidth: 64, svgString: """ @@ -118,7 +118,7 @@ struct SVG: Equatable { """ ) - static let afterpayWhiteOnBlack: SVG = SVG( + static let afterpayBadgeWhiteOnBlack: SVG = SVG( size: CGSize(width: 1582, height: 551), minimumWidth: 64, svgString: """ @@ -143,7 +143,7 @@ struct SVG: Equatable { """ ) - static let clearpayWhiteOnBlack = SVG( + static let clearpayBadgeWhiteOnBlack = SVG( size: CGSize(width: 1620, height: 551), minimumWidth: 64, svgString: """ @@ -162,7 +162,7 @@ struct SVG: Equatable { """ ) - static let afterpayBlackOnWhite: SVG = SVG( + static let afterpayBadgeBlackOnWhite: SVG = SVG( size: CGSize(width: 1582, height: 551), minimumWidth: 64, svgString: """ @@ -187,7 +187,7 @@ struct SVG: Equatable { """ ) - static let clearpayBlackOnWhite = SVG( + static let clearpayBadgeBlackOnWhite = SVG( size: CGSize(width: 1620, height: 551), minimumWidth: 64, svgString: """ @@ -206,5 +206,289 @@ struct SVG: Equatable { """ ) + static let afterpayPayNowBlackOnMint = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let clearpayPayNowBlackOnMint = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let afterpayPayNowMintOnBlack = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let clearpayPayNowMintOnBlack = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let afterpayPayNowWhiteOnBlack = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let clearpayPayNowWhiteOnBlack = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let afterpayPayNowBlackOnWhite = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + + static let clearpayPayNowBlackOnWhite = SVG( + size: CGSize(width: 1200, height: 180), + minimumWidth: 256, + svgString: """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """ + ) + } -// swiftlint:enable line_length +// swiftlint:enable line_length file_length type_body_length diff --git a/Sources/Afterpay/Resources/SVGConfiguration.swift b/Sources/Afterpay/Resources/SVGConfiguration.swift index 3555c865..c1de543f 100644 --- a/Sources/Afterpay/Resources/SVGConfiguration.swift +++ b/Sources/Afterpay/Resources/SVGConfiguration.swift @@ -14,6 +14,7 @@ protocol SVGConfiguration { var colorScheme: ColorScheme { get set } func svg(localizedFor locale: Locale, withTraits traitCollection: UITraitCollection) -> SVG + func accessibilityLabel(localizedFor locale: Locale) -> String } @@ -25,21 +26,21 @@ struct BadgeConfiguration: SVGConfiguration { let svgForPalette: (ColorPalette) -> SVG = { palette in switch (palette, locale) { case (.blackOnMint, Locales.greatBritain): - return .clearpayBlackOnMint + return .clearpayBadgeBlackOnMint case (.mintOnBlack, Locales.greatBritain): - return .clearpayMintOnBlack + return .clearpayBadgeMintOnBlack case (.whiteOnBlack, Locales.greatBritain): - return .clearpayWhiteOnBlack + return .clearpayBadgeWhiteOnBlack case (.blackOnWhite, Locales.greatBritain): - return .clearpayBlackOnWhite + return .clearpayBadgeBlackOnWhite case (.blackOnMint, _): - return .afterpayBlackOnMint + return .afterpayBadgeBlackOnMint case (.mintOnBlack, _): - return .afterpayMintOnBlack + return .afterpayBadgeMintOnBlack case (.whiteOnBlack, _): - return .afterpayWhiteOnBlack + return .afterpayBadgeWhiteOnBlack case (.blackOnWhite, _): - return .afterpayBlackOnWhite + return .afterpayBadgeBlackOnWhite } } @@ -57,4 +58,58 @@ struct BadgeConfiguration: SVGConfiguration { return svg } + func accessibilityLabel(localizedFor locale: Locale) -> String { + locale == Locales.greatBritain ? Strings.accessibleClearpay : Strings.accessibleAfterpay + } + +} + +struct PaymentButtonConfiguration: SVGConfiguration { + + var colorScheme: ColorScheme + + func svg(localizedFor locale: Locale, withTraits traitCollection: UITraitCollection) -> SVG { + let svgForPalette: (ColorPalette) -> SVG = { palette in + switch (palette, locale) { + case (.blackOnMint, Locales.greatBritain): + return .clearpayPayNowBlackOnMint + case (.mintOnBlack, Locales.greatBritain): + return .clearpayPayNowMintOnBlack + case (.whiteOnBlack, Locales.greatBritain): + return .clearpayPayNowWhiteOnBlack + case (.blackOnWhite, Locales.greatBritain): + return .clearpayPayNowBlackOnWhite + case (.blackOnMint, _): + return .afterpayPayNowBlackOnMint + case (.mintOnBlack, _): + return .afterpayPayNowMintOnBlack + case (.whiteOnBlack, _): + return .afterpayPayNowWhiteOnBlack + case (.blackOnWhite, _): + return .afterpayPayNowBlackOnWhite + } + } + + let svg: SVG = { + switch traitCollection.userInterfaceStyle { + case .dark: + return svgForPalette(colorScheme.darkPalette) + case .light, .unspecified: + fallthrough + @unknown default: + return svgForPalette(colorScheme.lightPalette) + } + }() + + return svg + } + + func accessibilityLabel(localizedFor locale: Locale) -> String { + let accessiblePaymentMethod = locale == Locales.greatBritain + ? Strings.accessibleClearpay + : Strings.accessibleAfterpay + + return "\(Strings.payNowWith) \(accessiblePaymentMethod)" + } + } diff --git a/Sources/Afterpay/Resources/Strings.swift b/Sources/Afterpay/Resources/Strings.swift index 4b60bc9c..66157345 100644 --- a/Sources/Afterpay/Resources/Strings.swift +++ b/Sources/Afterpay/Resources/Strings.swift @@ -16,6 +16,7 @@ enum Strings { static let info = "Info" static let orPayWith = "or pay with" + static let payNowWith = "pay now with" // MARK: - String Formats @@ -26,5 +27,6 @@ enum Strings { // MARK: - Accessible Strings static let accessibleAfterpay = "after pay" + static let accessibleClearpay = "clear pay" } diff --git a/Sources/Afterpay/Views/BadgeView.swift b/Sources/Afterpay/Views/BadgeView.swift index 8e830826..0dcd5d77 100644 --- a/Sources/Afterpay/Views/BadgeView.swift +++ b/Sources/Afterpay/Views/BadgeView.swift @@ -32,13 +32,15 @@ public final class BadgeView: UIView { } private func sharedInit() { + let configuration = BadgeConfiguration(colorScheme: colorScheme) + // Accessibility isAccessibilityElement = true accessibilityTraits = [.staticText] - accessibilityLabel = Strings.accessibleAfterpay + accessibilityLabel = configuration.accessibilityLabel(localizedFor: getLocale()) // SVG Layout - svgView = SVGView(svgConfiguration: BadgeConfiguration()) + svgView = SVGView(svgConfiguration: configuration) addSubview(svgView) diff --git a/Sources/Afterpay/Views/PaymentButton.swift b/Sources/Afterpay/Views/PaymentButton.swift new file mode 100644 index 00000000..e9ee5445 --- /dev/null +++ b/Sources/Afterpay/Views/PaymentButton.swift @@ -0,0 +1,83 @@ +// +// PaymentButton.swift +// Afterpay +// +// Created by Adam Campbell on 27/11/20. +// Copyright © 2020 Afterpay. All rights reserved. +// + +import Foundation +import UIKit + +public final class PaymentButton: UIButton { + + public var colorScheme: ColorScheme = .static(.blackOnMint) { + didSet { updateImage() } + } + + private var configuration: SVGConfiguration { + PaymentButtonConfiguration(colorScheme: colorScheme) + } + + public init(colorScheme: ColorScheme = .static(.blackOnMint)) { + self.colorScheme = colorScheme + + super.init(frame: .zero) + + sharedInit() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + + sharedInit() + } + + private func sharedInit() { + let locale = getLocale() + let svg = configuration.svg(localizedFor: locale, withTraits: traitCollection) + + NSLayoutConstraint.activate([ + heightAnchor.constraint(equalTo: widthAnchor, multiplier: svg.aspectRatio), + widthAnchor.constraint(greaterThanOrEqualToConstant: svg.minimumWidth), + ]) + + accessibilityLabel = configuration.accessibilityLabel(localizedFor: locale) + translatesAutoresizingMaskIntoConstraints = false + adjustsImageWhenHighlighted = true + adjustsImageWhenDisabled = true + } + + public override func layoutSubviews() { + super.layoutSubviews() + + if image(for: .normal)?.size != bounds.size { + updateImage() + } + } + + public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + let svgForTraits = { [configuration] traitCollection in + configuration.svg(localizedFor: getLocale(), withTraits: traitCollection) + } + + if previousTraitCollection.map(svgForTraits) != svgForTraits(traitCollection) { + updateImage() + } + } + + private func updateImage() { + let svgView = SVGView(svgConfiguration: configuration) + svgView.frame = bounds + + let renderer = UIGraphicsImageRenderer(size: svgView.bounds.size) + let image = renderer.image { rendererContext in + svgView.layer.render(in: rendererContext.cgContext) + } + + setImage(image, for: .normal) + } + +} diff --git a/Sources/Afterpay/Views/PriceBreakdownView.swift b/Sources/Afterpay/Views/PriceBreakdownView.swift index a88e88b8..d7710ff9 100644 --- a/Sources/Afterpay/Views/PriceBreakdownView.swift +++ b/Sources/Afterpay/Views/PriceBreakdownView.swift @@ -52,7 +52,9 @@ public final class PriceBreakdownView: UIView { } }() - public var badgeColorScheme: ColorScheme = .static(.blackOnMint) + public var badgeColorScheme: ColorScheme = .static(.blackOnMint) { + didSet { updateAttributedText() } + } public var fontProvider: (UITraitCollection) -> UIFont = { traitCollection in .preferredFont(forTextStyle: .body, compatibleWith: traitCollection) @@ -105,7 +107,8 @@ public final class PriceBreakdownView: UIView { } @objc private func updateAttributedText() { - let badgeSVGView = SVGView(svgConfiguration: BadgeConfiguration()) + let configuration = BadgeConfiguration(colorScheme: badgeColorScheme) + let badgeSVGView = SVGView(svgConfiguration: configuration) let svg = badgeSVGView.svg let font: UIFont = fontProvider(traitCollection) @@ -138,7 +141,7 @@ public final class PriceBreakdownView: UIView { let attachment = NSTextAttachment() attachment.image = image attachment.bounds = CGRect(origin: .init(x: 0, y: font.descender), size: image.size) - attachment.accessibilityLabel = Strings.accessibleAfterpay + attachment.accessibilityLabel = configuration.accessibilityLabel(localizedFor: getLocale()) return .init(attachment: attachment) }() diff --git a/Sources/Afterpay/Views/SVGView.swift b/Sources/Afterpay/Views/SVGView.swift index c84242f4..a055e205 100644 --- a/Sources/Afterpay/Views/SVGView.swift +++ b/Sources/Afterpay/Views/SVGView.swift @@ -16,14 +16,12 @@ import UIKit final class SVGView: Macaw.SVGView { - var svg: SVG { svgConfiguration.svg(localizedFor: locale, withTraits: traitCollection) } + var svg: SVG { svgConfiguration.svg(localizedFor: getLocale(), withTraits: traitCollection) } var svgConfiguration: SVGConfiguration { didSet { svgDidChange() } } - private var locale: Locale { getConfiguration()?.locale ?? Locales.unitedStates } - init(svgConfiguration: SVGConfiguration) { self.svgConfiguration = svgConfiguration @@ -72,7 +70,7 @@ final class SVGView: Macaw.SVGView { svgConfiguration.svg(localizedFor: locale, withTraits: traitCollection) } - if svgForLocale(previousLocale) != svgForLocale(locale) { + if svgForLocale(previousLocale) != svgForLocale(getLocale()) { svgDidChange() } } @@ -80,8 +78,8 @@ final class SVGView: Macaw.SVGView { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) - let svgForTraits = { [locale, svgConfiguration] traitCollection in - svgConfiguration.svg(localizedFor: locale, withTraits: traitCollection) + let svgForTraits = { [svgConfiguration] traitCollection in + svgConfiguration.svg(localizedFor: getLocale(), withTraits: traitCollection) } if previousTraitCollection.map(svgForTraits) != svgForTraits(traitCollection) {