Skip to content

Commit 1e00235

Browse files
committed
Support apple pay button styling
1 parent 7787e18 commit 1e00235

File tree

8 files changed

+75
-2
lines changed

8 files changed

+75
-2
lines changed

modules/@shopify/checkout-sheet-kit/ios/AcceleratedCheckoutButtons+Extensions.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Foundation
2626
import PassKit
2727
import SwiftUI
2828

29-
// MARK: - Apple Pay Button
29+
// MARK: - Apple Pay Button Label
3030

3131
@available(iOS 16.0, *)
3232
extension PayWithApplePayButtonLabel {
@@ -58,3 +58,23 @@ extension PayWithApplePayButtonLabel {
5858
"topUp": .topUp
5959
]
6060
}
61+
62+
// MARK: - Apple Pay Button Style
63+
64+
@available(iOS 16.0, *)
65+
extension PayWithApplePayButtonStyle {
66+
static func from(_ string: String?) -> PayWithApplePayButtonStyle? {
67+
guard let string, let value = map[string] else {
68+
return nil
69+
}
70+
71+
return value
72+
}
73+
74+
private static let map: [String: PayWithApplePayButtonStyle] = [
75+
"automatic": .automatic,
76+
"black": .black,
77+
"white": .white,
78+
"whiteOutline": .whiteOutline
79+
]
80+
}

modules/@shopify/checkout-sheet-kit/ios/AcceleratedCheckoutButtons.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ class RCTAcceleratedCheckoutButtonsView: UIView {
120120
}
121121
}
122122

123+
@objc var applePayStyle: String? {
124+
didSet {
125+
updateView()
126+
}
127+
}
128+
123129
@objc var onFail: RCTBubblingEventBlock?
124130
@objc var onComplete: RCTBubblingEventBlock?
125131
@objc var onCancel: RCTBubblingEventBlock?
@@ -290,6 +296,10 @@ class RCTAcceleratedCheckoutButtonsView: UIView {
290296
view = AnyView(buttons.environmentObject(config))
291297
}
292298

299+
/// Apply Apple Pay button style (defaults to .automatic)
300+
let applePayButtonStyle = PayWithApplePayButtonStyle.from(applePayStyle) ?? .automatic
301+
view = AnyView(view.payWithApplePayButtonStyle(applePayButtonStyle))
302+
293303
if let hostingController {
294304
hostingController.rootView = view
295305
} else {

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ @interface RCT_EXTERN_MODULE (RCTAcceleratedCheckoutButtonsManager, RCTViewManag
106106
*/
107107
RCT_EXPORT_VIEW_PROPERTY(applePayLabel, NSString*)
108108

109+
/**
110+
* Style variant for the Apple Pay button (e.g., "automatic", "black", "white", "whiteOutline").
111+
*/
112+
RCT_EXPORT_VIEW_PROPERTY(applePayStyle, NSString*)
113+
109114
/**
110115
* Emitted when checkout fails. Payload contains a CheckoutException-like shape.
111116
*/

modules/@shopify/checkout-sheet-kit/src/components/AcceleratedCheckoutButtons.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export enum ApplePayLabel {
6161
topUp = 'topUp',
6262
}
6363

64+
export enum ApplePayStyle {
65+
automatic = 'automatic',
66+
black = 'black',
67+
white = 'white',
68+
whiteOutline = 'whiteOutline',
69+
}
70+
6471
type CheckoutIdentifier =
6572
| {
6673
cartId: string;
@@ -87,6 +94,12 @@ interface CommonAcceleratedCheckoutButtonsProps {
8794
*/
8895
applePayLabel?: ApplePayLabel;
8996

97+
/**
98+
* Style for the Apple Pay button (automatic, black, white, whiteOutline)
99+
* @default ApplePayStyle.automatic
100+
*/
101+
applePayStyle?: ApplePayStyle;
102+
90103
/**
91104
* Called when checkout fails
92105
*/
@@ -148,6 +161,7 @@ export type AcceleratedCheckoutButtonsProps = (CartProps | VariantProps) &
148161

149162
interface NativeAcceleratedCheckoutButtonsProps {
150163
applePayLabel?: string;
164+
applePayStyle?: string;
151165
style?: ViewStyle;
152166
checkoutIdentifier: CheckoutIdentifier;
153167
cornerRadius?: number;
@@ -193,6 +207,7 @@ export const AcceleratedCheckoutButtons: React.FC<
193207
AcceleratedCheckoutButtonsProps
194208
> = ({
195209
applePayLabel,
210+
applePayStyle,
196211
cornerRadius,
197212
wallets,
198213
onFail,
@@ -307,6 +322,7 @@ export const AcceleratedCheckoutButtons: React.FC<
307322
return (
308323
<RCTAcceleratedCheckoutButtons
309324
applePayLabel={applePayLabel}
325+
applePayStyle={applePayStyle}
310326
style={{...defaultStyles, height: dynamicHeight}}
311327
checkoutIdentifier={checkoutIdentifier}
312328
cornerRadius={cornerRadius}

modules/@shopify/checkout-sheet-kit/src/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ export enum ApplePayContactField {
189189
phone = 'phone',
190190
}
191191

192+
export enum ApplePayStyle {
193+
automatic = 'automatic',
194+
black = 'black',
195+
white = 'white',
196+
whiteOutline = 'whiteOutline',
197+
}
198+
192199
/**
193200
* Configuration for AcceleratedCheckouts
194201
*/

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ import {
5858
import {CheckoutErrorCode} from './errors.d';
5959
import type {CheckoutCompletedEvent} from './events.d';
6060
import type {CustomEvent, PixelEvent, StandardEvent} from './pixels.d';
61-
import {ApplePayLabel} from './components/AcceleratedCheckoutButtons';
61+
import {
62+
ApplePayLabel,
63+
ApplePayStyle,
64+
} from './components/AcceleratedCheckoutButtons';
6265
import type {
6366
AcceleratedCheckoutButtonsProps,
6467
RenderStateChangeEvent,
@@ -515,6 +518,7 @@ export {
515518
AcceleratedCheckoutWallet,
516519
ApplePayContactField,
517520
ApplePayLabel,
521+
ApplePayStyle,
518522
ColorScheme,
519523
ShopifyCheckoutSheet,
520524
ShopifyCheckoutSheetProvider,

sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
395395
XCTAssertTrue(PayWithApplePayButtonLabel.from("unknown", fallback: .buy) == .buy)
396396
}
397397

398+
func testApplePayStyleMapping_knownAndUnknownKeys() throws {
399+
XCTAssertEqual(PayWithApplePayButtonStyle.from("automatic"), .automatic)
400+
XCTAssertEqual(PayWithApplePayButtonStyle.from("black"), .black)
401+
XCTAssertEqual(PayWithApplePayButtonStyle.from("white"), .white)
402+
XCTAssertEqual(PayWithApplePayButtonStyle.from("whiteOutline"), .whiteOutline)
403+
XCTAssertNil(PayWithApplePayButtonStyle.from("unknown"))
404+
XCTAssertNil(PayWithApplePayButtonStyle.from(nil))
405+
}
406+
398407
func testConfigureAcceleratedCheckoutsResolvesFalseForInvalidApplePayContactField() throws {
399408
let expectation = self.expectation(description: "configureAcceleratedCheckouts invalid contact field resolves false")
400409
var resolved: Bool = true

sample/src/screens/CartScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
useShopifyCheckoutSheet,
4040
AcceleratedCheckoutButtons,
4141
ApplePayLabel,
42+
ApplePayStyle,
4243
AcceleratedCheckoutWallet,
4344
} from '@shopify/checkout-sheet-kit';
4445
import useShopify from '../hooks/useShopify';
@@ -167,6 +168,7 @@ function CartScreen(): React.JSX.Element {
167168
<AcceleratedCheckoutButtons
168169
{...eventHandlers}
169170
applePayLabel={ApplePayLabel.checkout}
171+
applePayStyle={ApplePayStyle.black}
170172
cartId={cartId}
171173
wallets={[
172174
AcceleratedCheckoutWallet.applePay,

0 commit comments

Comments
 (0)