Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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
}

return value
}

private static let map: [String: PayWithApplePayButtonLabel] = [
private static let map: [String: PKPaymentButtonType] = [
"addMoney": .addMoney,
"book": .book,
"buy": .buy,
Expand All @@ -39,16 +37,16 @@ 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
}

return value
}

private static let map: [String: PayWithApplePayButtonStyle] = [
private static let map: [String: PKPaymentButtonStyle] = [
"automatic": .automatic,
"black": .black,
"white": .white,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CheckoutViewDelegateTests: XCTestCase {
XCTAssertNotNil(closeButton)
XCTAssertEqual(closeButton?.style, .plain)
XCTAssertNil(closeButton?.image)
XCTAssertEqual(closeButton?.accessibilityLabel, "Close Checkout")
}

func testCloseButtonUsesCustomImageAndTintWhenColorIsSet() {
Expand All @@ -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() {
Expand Down
Loading