diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons+Extensions.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons+Extensions.swift index 4d9865266..e16da2a5c 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons+Extensions.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons+Extensions.swift @@ -1,13 +1,11 @@ -import _PassKit_SwiftUI import Foundation import PassKit -import SwiftUI // MARK: - Apple Pay Button @available(iOS 16.0, *) -extension PayWithApplePayButtonLabel { - static func from(_ string: String?, fallback: PayWithApplePayButtonLabel = .plain) -> PayWithApplePayButtonLabel { +extension PKPaymentButtonType { + static func from(_ string: String?, fallback: PKPaymentButtonType = .plain) -> PKPaymentButtonType { guard let string, let value = map[string] else { return fallback } @@ -15,7 +13,7 @@ extension PayWithApplePayButtonLabel { return value } - private static let map: [String: PayWithApplePayButtonLabel] = [ + private static let map: [String: PKPaymentButtonType] = [ "addMoney": .addMoney, "book": .book, "buy": .buy, @@ -39,8 +37,8 @@ extension PayWithApplePayButtonLabel { // MARK: - Apple Pay Button Style @available(iOS 16.0, *) -extension PayWithApplePayButtonStyle { - static func from(_ string: String?, fallback: PayWithApplePayButtonStyle = .automatic) -> PayWithApplePayButtonStyle { +extension PKPaymentButtonStyle { + static func from(_ string: String?, fallback: PKPaymentButtonStyle = .automatic) -> PKPaymentButtonStyle { guard let string, let value = map[string] else { return fallback } @@ -48,7 +46,7 @@ extension PayWithApplePayButtonStyle { return value } - private static let map: [String: PayWithApplePayButtonStyle] = [ + private static let map: [String: PKPaymentButtonStyle] = [ "automatic": .automatic, "black": .black, "white": .white, diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift index 3dfa0eddd..ed8c631a4 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift @@ -207,18 +207,18 @@ class RCTAcceleratedCheckoutButtonsView: UIView { updateView() } - private func attachModifiers(to buttons: AcceleratedCheckoutButtons, wallets: [Wallet]?, applePayLabel: PayWithApplePayButtonLabel?, applePayStyle: PayWithApplePayButtonStyle) -> AcceleratedCheckoutButtons { + private func attachModifiers(to buttons: AcceleratedCheckoutButtons, wallets: [Wallet]?, applePayButtonType: PKPaymentButtonType?, applePayButtonStyle: PKPaymentButtonStyle) -> AcceleratedCheckoutButtons { var modifiedButtons = buttons if let wallets { modifiedButtons = modifiedButtons.wallets(wallets) } - if let applePayLabel { - modifiedButtons = modifiedButtons.applePayLabel(applePayLabel) + if let applePayButtonType { + modifiedButtons = modifiedButtons.applePayButtonType(applePayButtonType) } - modifiedButtons = modifiedButtons.applePayStyle(applePayStyle) + modifiedButtons = modifiedButtons.applePayButtonStyle(applePayButtonStyle) if let cornerRadius { modifiedButtons = modifiedButtons.cornerRadius(CGFloat(cornerRadius.doubleValue)) @@ -270,7 +270,7 @@ class RCTAcceleratedCheckoutButtonsView: UIView { } // Attach modifiers (wallets, applePayLabel, applePayStyle, cornerRadius) - buttons = attachModifiers(to: buttons, wallets: shopifyWallets, applePayLabel: PayWithApplePayButtonLabel.from(applePayLabel), applePayStyle: PayWithApplePayButtonStyle.from(applePayStyle)) + buttons = attachModifiers(to: buttons, wallets: shopifyWallets, applePayButtonType: PKPaymentButtonType.from(applePayLabel), applePayButtonStyle: PKPaymentButtonStyle.from(applePayStyle)) // Attach event handlers buttons = attachEventListeners(to: buttons) @@ -288,9 +288,18 @@ class RCTAcceleratedCheckoutButtonsView: UIView { // Attach config (and Apple Pay config if available) if let applePayConfig = AcceleratedCheckoutConfiguration.shared.applePayConfiguration { - view = AnyView(buttons.environmentObject(config).environmentObject(applePayConfig).environment(\.colorScheme, colorScheme)) + view = AnyView( + buttons + .environment(\.shopifyAcceleratedCheckoutsConfiguration, config) + .environment(\.shopifyApplePayConfiguration, applePayConfig) + .environment(\.colorScheme, colorScheme) + ) } else { - view = AnyView(buttons.environmentObject(config).environment(\.colorScheme, colorScheme)) + view = AnyView( + buttons + .environment(\.shopifyAcceleratedCheckoutsConfiguration, config) + .environment(\.colorScheme, colorScheme) + ) } if let hostingController { diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift index c26347c33..8665052f1 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift @@ -3,6 +3,8 @@ import WebKit @MainActor class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControllerDelegate { + private static let closeButtonAccessibilityLabel = "Close Checkout" + var onCancel: (() -> Void)? var onFail: ((CheckoutError) -> Void)? weak var delegate: (any CheckoutDelegate)? @@ -41,14 +43,17 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl } item.tintColor = closeButtonTintColor + item.accessibilityLabel = Self.closeButtonAccessibilityLabel return item } - return UIBarButtonItem( + let item = UIBarButtonItem( barButtonSystemItem: .close, target: self, action: #selector(close) ) + item.accessibilityLabel = Self.closeButtonAccessibilityLabel + return item }() var progressObserver: NSKeyValueObservation? diff --git a/platforms/swift/Tests/ShopifyCheckoutKitTests/CheckoutViewControllerTests.swift b/platforms/swift/Tests/ShopifyCheckoutKitTests/CheckoutViewControllerTests.swift index d39db8200..3f521231e 100644 --- a/platforms/swift/Tests/ShopifyCheckoutKitTests/CheckoutViewControllerTests.swift +++ b/platforms/swift/Tests/ShopifyCheckoutKitTests/CheckoutViewControllerTests.swift @@ -86,6 +86,7 @@ class CheckoutViewDelegateTests: XCTestCase { XCTAssertNotNil(closeButton) XCTAssertEqual(closeButton?.style, .plain) XCTAssertNil(closeButton?.image) + XCTAssertEqual(closeButton?.accessibilityLabel, "Close Checkout") } func testCloseButtonUsesCustomImageAndTintWhenColorIsSet() { @@ -98,6 +99,7 @@ class CheckoutViewDelegateTests: XCTestCase { XCTAssertEqual(closeButton?.style, .plain) XCTAssertNotNil(closeButton?.image) XCTAssertEqual(closeButton?.tintColor, customColor) + XCTAssertEqual(closeButton?.accessibilityLabel, "Close Checkout") } func testCloseButtonImageIsXMarkCircleFill() {