-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShopifyCheckoutKit.mm
More file actions
141 lines (115 loc) · 4.85 KB
/
Copy pathShopifyCheckoutKit.mm
File metadata and controls
141 lines (115 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <RNShopifyCheckoutKitSpec/RNShopifyCheckoutKitSpec.h>
#import <objc/runtime.h>
// Registers the Swift module class (ShopifyCheckoutKit.swift) with the RN
// runtime under the name 'RCTShopifyCheckoutKit', extending the codegen
// base class so TurboModule dispatch can find it.
//
// Method declarations (`RCT_EXTERN_METHOD`) are intentionally absent for most
// methods: the codegen-generated `NativeShopifyCheckoutKitSpecJSI` invokes
// each method via its `@objc` selector directly (see ShopifyCheckoutKit.swift).
// `setConfig` is declared so ObjCTurboModule sees the Swift selector's
// NSDictionary argument and does not apply codegen's C++ struct conversion before
// invoking Swift.
@interface RCT_EXTERN_MODULE (RCTShopifyCheckoutKit, NativeShopifyCheckoutKitSpecBase)
RCT_EXTERN_METHOD(setConfig:(NSDictionary *)configuration)
RCT_EXTERN_METHOD(present:(NSString *)checkoutURL
subscribedMethods:(NSArray *)subscribedMethods)
@end
static const void *RCTShopifyCheckoutKitEventEmitterCallbackKey =
&RCTShopifyCheckoutKitEventEmitterCallbackKey;
// Swift cannot directly subclass/import the codegen-generated
// NativeShopifyCheckoutKitSpecBase in this CocoaPods setup. The TurboModule
// runtime still calls `setEventEmitterCallback:` on the module instance, so this
// Objective-C++ category stores that generated callback and exposes a small
// selector Swift can call to emit the typed `onDispatch` event.
@implementation RCTShopifyCheckoutKit (DispatchEmitter)
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
{
objc_setAssociatedObject(
self,
RCTShopifyCheckoutKitEventEmitterCallbackKey,
eventEmitterCallbackWrapper,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)emitOnDispatchFromSwift:(NSString *)value
{
EventEmitterCallbackWrapper *eventEmitterCallbackWrapper =
(EventEmitterCallbackWrapper *)objc_getAssociatedObject(
self, RCTShopifyCheckoutKitEventEmitterCallbackKey);
if (eventEmitterCallbackWrapper == nil) {
return;
}
eventEmitterCallbackWrapper->_eventEmitterCallback("onDispatch", value);
}
@end
// TurboModule registration. `RCTModuleProviders` (generated by codegen from
// `package.json → codegenConfig.ios.modulesProvider`) looks up classes that
// `respondsToSelector:@selector(getTurboModule:)`. Without this category,
// our Swift class would not appear in the providers map and JS calls would
// fall back to the legacy bridge — which has no methods declared here and
// no sync support.
@interface RCTShopifyCheckoutKit (TurboModule) <RCTTurboModule>
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params;
@end
@implementation RCTShopifyCheckoutKit (TurboModule)
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeShopifyCheckoutKitSpecJSI>(
params);
}
@end
/**
* AcceleratedCheckoutButtons View Manager
*/
@interface RCT_EXTERN_MODULE (RCTAcceleratedCheckoutButtonsManager, RCTViewManager)
/**
* Unified checkout identifier payload.
* Accepts either { cartId } or { variantId, quantity }.
*/
RCT_EXPORT_VIEW_PROPERTY(checkoutIdentifier, NSDictionary*)
/**
* Corner radius for rendered buttons, in points. Defaults to 8.
*/
RCT_EXPORT_VIEW_PROPERTY(cornerRadius, NSNumber*)
/**
* Wallets to render. Accepts an array of identifiers such as "shopPay" and "applePay".
* If omitted, native defaults are used.
*/
RCT_EXPORT_VIEW_PROPERTY(wallets, NSArray*)
/**
* Label variant for the Apple Pay button (e.g., "plain", "buy", "checkout").
*/
RCT_EXPORT_VIEW_PROPERTY(applePayLabel, NSString*)
/**
* Style variant for the Apple Pay button (e.g., "automatic", "black", "white", "whiteOutline").
*/
RCT_EXPORT_VIEW_PROPERTY(applePayStyle, NSString*)
/**
* Emitted when checkout fails. Payload contains a CheckoutException-like shape.
*/
RCT_EXPORT_VIEW_PROPERTY(onFail, RCTBubblingEventBlock)
/**
* Emitted when checkout is cancelled by the buyer.
*/
RCT_EXPORT_VIEW_PROPERTY(onCancel, RCTBubblingEventBlock)
/**
* Emitted when the native render state changes. Values: "loading", "rendered", "error".
*/
RCT_EXPORT_VIEW_PROPERTY(onRenderStateChange, RCTBubblingEventBlock)
/**
* Emitted when a link is clicked within the checkout experience. Payload contains the URL.
*/
RCT_EXPORT_VIEW_PROPERTY(onClickLink, RCTBubblingEventBlock)
/**
* Emitted when a subscribed Checkout Protocol event fires. Payload contains { value } where value is a JSON envelope.
*/
RCT_EXPORT_VIEW_PROPERTY(onDispatch, RCTDirectEventBlock)
/**
* Emitted when the intrinsic height of the native view changes. Payload contains { height }.
*/
RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTDirectEventBlock)
@end