Skip to content

Commit f6d38f0

Browse files
Restore dual architecture support for 3.9
1 parent a349b97 commit f6d38f0

19 files changed

Lines changed: 396 additions & 103 deletions

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,21 @@ experiences.
6565

6666
## Platform Requirements
6767

68-
- **React Native** - Minimum version `0.76` (v4+) / `0.70` (v3 and earlier)
68+
- **React Native** - Minimum version `0.76` (`3.9.0+`) / `0.70` (`<=3.8.x`)
6969
- **iOS** - Minimum version iOS 13
7070
- **Android** - Minimum Java 11 & Android SDK version `23`
7171

7272
## Version Compatibility
7373

74-
Starting with **v4.0.0**, `@shopify/checkout-sheet-kit` requires the React Native
75-
**New Architecture** (TurboModules + Fabric). Apps on the old architecture must
76-
stay on the `v3.x` line until they migrate.
74+
The **v3.9.x** line keeps the v3 public async API while supporting both React
75+
Native architectures. Starting with **v4.0.0**, `@shopify/checkout-sheet-kit`
76+
requires the React Native **New Architecture** (TurboModules + Fabric).
7777

7878
| Package version | React Native | Architecture |
7979
| --------------- | -------------- | ------------------ |
8080
| `4.x` | `>= 0.76` | New Architecture |
81-
| `3.x` | `>= 0.70` | Old Architecture |
81+
| `3.9.x` | `>= 0.76` | Old + New |
82+
| `<=3.8.x` | `>= 0.70` | Old Architecture |
8283

8384
See the [React Native upgrade guide](https://reactnative.dev/docs/the-new-architecture/use-the-new-architecture)
8485
for help enabling the New Architecture in your app.

__mocks__/react-native.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ module.exports = {
7676
requireNativeComponent,
7777
codegenNativeComponent,
7878
TurboModuleRegistry: {
79+
get: jest.fn((name: string) => {
80+
if (name === 'ShopifyCheckoutSheetKit') {
81+
return ShopifyCheckoutSheetKit;
82+
}
83+
return null;
84+
}),
7985
getEnforcing: jest.fn((name: string) => {
8086
if (name === 'ShopifyCheckoutSheetKit') {
8187
return ShopifyCheckoutSheetKit;

modules/@shopify/checkout-sheet-kit/RNShopifyCheckoutSheetKit.podspec

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ require "json"
22

33
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
44

5+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
6+
7+
new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"
8+
59
Pod::Spec.new do |s|
610
s.name = "RNShopifyCheckoutSheetKit"
711
s.version = package["version"]
@@ -19,5 +23,23 @@ Pod::Spec.new do |s|
1923
s.dependency "ShopifyCheckoutSheetKit", "~> 3.8.0"
2024
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.8.0"
2125

22-
install_modules_dependencies(s)
26+
if new_arch_enabled
27+
if defined?(install_modules_dependencies)
28+
install_modules_dependencies(s)
29+
else
30+
s.dependency "React-Codegen"
31+
s.dependency "RCT-Folly", :modular_headers => true
32+
s.dependency "RCTRequired"
33+
s.dependency "RCTTypeSafety"
34+
s.dependency "ReactCommon/turbomodule/core"
35+
end
36+
37+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
38+
39+
s.pod_target_xcconfig = {
40+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
41+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
42+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
43+
}
44+
end
2345
end

modules/@shopify/checkout-sheet-kit/android/build.gradle

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@ buildscript {
1010
}
1111

1212
apply plugin: "com.android.library"
13-
apply plugin: "com.facebook.react"
13+
14+
def isNewArchitectureEnabled() {
15+
def newArchEnabled = project.hasProperty("newArchEnabled")
16+
? project.property("newArchEnabled")
17+
: rootProject.hasProperty("newArchEnabled")
18+
? rootProject.property("newArchEnabled")
19+
: "false"
20+
21+
return newArchEnabled.toString() == "true"
22+
}
23+
24+
if (isNewArchitectureEnabled()) {
25+
apply plugin: "com.facebook.react"
26+
}
1427

1528
def getExtOrIntegerDefault(name) {
1629
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[name]).toInteger()
@@ -37,6 +50,10 @@ android {
3750
if (supportsNamespace()) {
3851
namespace "com.shopify.reactnative.checkoutsheetkit"
3952

53+
buildFeatures {
54+
buildConfig true
55+
}
56+
4057
sourceSets {
4158
main {
4259
manifest.srcFile "src/main/AndroidManifestNew.xml"
@@ -50,6 +67,7 @@ android {
5067
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
5168
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
5269

70+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
5371
}
5472

5573
buildTypes {
@@ -93,4 +111,3 @@ dependencies {
93111
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.5")
94112
debugImplementation("com.shopify:checkout-sheet-kit:${SHOPIFY_CHECKOUT_SDK_VERSION}")
95113
}
96-

modules/@shopify/checkout-sheet-kit/android/src/main/java/com/shopify/reactnative/checkoutsheetkit/ShopifyCheckoutSheetKitModule.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,25 @@ of this software and associated documentation files (the "Software"), to deal
2727
import android.content.Context;
2828
import androidx.activity.ComponentActivity;
2929
import androidx.annotation.NonNull;
30-
import com.facebook.react.bridge.Promise;
3130
import com.facebook.react.bridge.ReactApplicationContext;
31+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
3232
import com.facebook.react.bridge.ReactMethod;
3333
import com.facebook.react.bridge.Arguments;
3434
import com.facebook.react.bridge.ReadableArray;
3535
import com.facebook.react.bridge.ReadableMap;
3636
import com.facebook.react.bridge.WritableMap;
37-
import com.shopify.checkoutsheetkit.NativeShopifyCheckoutSheetKitSpec;
37+
import com.facebook.react.module.annotations.ReactModule;
38+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
3839
import com.shopify.checkoutsheetkit.*;
3940

4041
import java.util.HashMap;
4142
import java.util.Map;
4243
import java.util.Objects;
4344

44-
public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {
45+
@ReactModule(name = ShopifyCheckoutSheetKitModule.NAME)
46+
public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule implements TurboModule {
47+
48+
public static final String NAME = "ShopifyCheckoutSheetKit";
4549

4650
public static Configuration checkoutConfig = new Configuration();
4751

@@ -62,8 +66,14 @@ public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
6266
});
6367
}
6468

69+
@NonNull
70+
@Override
71+
public String getName() {
72+
return NAME;
73+
}
74+
6575
@Override
66-
protected Map<String, Object> getTypedExportedConstants() {
76+
public Map<String, Object> getConstants() {
6777
final Map<String, Object> constants = new HashMap<>();
6878
constants.put("version", ShopifyCheckoutSheetKit.version);
6979
return constants;

modules/@shopify/checkout-sheet-kit/android/src/main/java/com/shopify/reactnative/checkoutsheetkit/ShopifyCheckoutSheetKitPackage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626
import androidx.annotation.NonNull;
2727
import androidx.annotation.Nullable;
2828

29-
import com.facebook.react.TurboReactPackage;
29+
import com.facebook.react.BaseReactPackage;
3030
import com.facebook.react.bridge.NativeModule;
3131
import com.facebook.react.bridge.ReactApplicationContext;
3232
import com.facebook.react.module.model.ReactModuleInfo;
@@ -38,7 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
3838
import java.util.List;
3939
import java.util.Map;
4040

41-
public class ShopifyCheckoutSheetKitPackage extends TurboReactPackage {
41+
public class ShopifyCheckoutSheetKitPackage extends BaseReactPackage {
4242

4343
@NonNull
4444
@Override
@@ -67,7 +67,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
6767
false, // canOverrideExistingModule
6868
false, // needsEagerInit
6969
false, // isCxxModule
70-
true // isTurboModule
70+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED // isTurboModule
7171
));
7272
return moduleInfos;
7373
};

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ of this software and associated documentation files (the "Software"), to deal
2424

2525
#import <React/RCTBridgeModule.h>
2626
#import <React/RCTViewManager.h>
27+
28+
#if RCT_NEW_ARCH_ENABLED
2729
#import <RNShopifyCheckoutSheetKitSpec/RNShopifyCheckoutSheetKitSpec.h>
2830

2931
// Registers the Swift module class (ShopifyCheckoutSheetKit.swift) with the RN
@@ -61,6 +63,61 @@ @implementation RCTShopifyCheckoutSheetKit (TurboModule)
6163
params);
6264
}
6365
@end
66+
#else
67+
@interface RCT_EXTERN_MODULE (RCTShopifyCheckoutSheetKit, NSObject)
68+
69+
/**
70+
* Present checkout
71+
*/
72+
RCT_EXTERN_METHOD(present : (NSString*)checkoutURLString);
73+
74+
/**
75+
* Preload checkout
76+
*/
77+
RCT_EXTERN_METHOD(preload : (NSString*)checkoutURLString);
78+
79+
/**
80+
* Dismiss checkout
81+
*/
82+
RCT_EXTERN_METHOD(dismiss);
83+
84+
/**
85+
* Invalidate preload cache
86+
*/
87+
RCT_EXTERN_METHOD(invalidateCache);
88+
89+
/**
90+
* Set configuration for checkout
91+
*/
92+
RCT_EXTERN_METHOD(setConfig : (NSDictionary*)configuration);
93+
94+
/**
95+
* Return configuration for checkout
96+
*/
97+
RCT_EXTERN_METHOD(getConfig : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
98+
99+
/**
100+
* Configure AcceleratedCheckouts
101+
*/
102+
RCT_EXTERN_METHOD(configureAcceleratedCheckouts : (NSString*)storefrontDomain storefrontAccessToken : (
103+
NSString*)storefrontAccessToken customerEmail : (NSString*)customerEmail customerPhoneNumber : (NSString*)
104+
customerPhoneNumber customerAccessToken : (NSString*)customerAccessToken applePayMerchantIdentifier : (NSString*)
105+
applePayMerchantIdentifier applyPayContactFields : (NSArray*)applyPayContactFields supportedShippingCountries : (NSArray*)supportedShippingCountries resolve : (
106+
RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
107+
108+
/**
109+
* Check if accelerated checkout is available
110+
*/
111+
RCT_EXTERN_METHOD(
112+
isAcceleratedCheckoutAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
113+
114+
/**
115+
* Check if Apple Pay is available
116+
*/
117+
RCT_EXTERN_METHOD(isApplePayAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
118+
119+
@end
120+
#endif
64121

65122
/**
66123
* AcceleratedCheckoutButtons View Manager

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
225225
]
226226
}
227227

228+
@objc func getConfig(
229+
_ resolve: @escaping RCTPromiseResolveBlock,
230+
reject _: @escaping RCTPromiseRejectBlock
231+
) {
232+
resolve(getConfig())
233+
}
234+
228235
@objc func configureAcceleratedCheckouts(
229236
_ storefrontDomain: String,
230237
storefrontAccessToken: String,
@@ -274,6 +281,30 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
274281
return NSNumber(value: true)
275282
}
276283

284+
@objc func configureAcceleratedCheckouts(
285+
_ storefrontDomain: String,
286+
storefrontAccessToken: String,
287+
customerEmail: String?,
288+
customerPhoneNumber: String?,
289+
customerAccessToken: String?,
290+
applePayMerchantIdentifier: String?,
291+
applyPayContactFields: [String]?,
292+
supportedShippingCountries: [String]?,
293+
resolve: @escaping RCTPromiseResolveBlock,
294+
reject _: @escaping RCTPromiseRejectBlock
295+
) {
296+
resolve(configureAcceleratedCheckouts(
297+
storefrontDomain,
298+
storefrontAccessToken: storefrontAccessToken,
299+
customerEmail: customerEmail,
300+
customerPhoneNumber: customerPhoneNumber,
301+
customerAccessToken: customerAccessToken,
302+
applePayMerchantIdentifier: applePayMerchantIdentifier,
303+
applyPayContactFields: applyPayContactFields,
304+
supportedShippingCountries: supportedShippingCountries
305+
))
306+
}
307+
277308
@objc func isAcceleratedCheckoutAvailable() -> NSNumber {
278309
guard #available(iOS 16.0, *) else {
279310
return NSNumber(value: false)
@@ -282,6 +313,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
282313
return NSNumber(value: AcceleratedCheckoutConfiguration.shared.available)
283314
}
284315

316+
@objc func isAcceleratedCheckoutAvailable(
317+
_ resolve: @escaping RCTPromiseResolveBlock,
318+
reject _: @escaping RCTPromiseRejectBlock
319+
) {
320+
resolve(isAcceleratedCheckoutAvailable())
321+
}
322+
285323
@objc func isApplePayAvailable() -> NSNumber {
286324
guard #available(iOS 16.0, *) else {
287325
return NSNumber(value: false)
@@ -292,6 +330,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
292330
return NSNumber(value: available)
293331
}
294332

333+
@objc func isApplePayAvailable(
334+
_ resolve: @escaping RCTPromiseResolveBlock,
335+
reject _: @escaping RCTPromiseRejectBlock
336+
) {
337+
resolve(isApplePayAvailable())
338+
}
339+
295340
@objc func initiateGeolocationRequest(_ allow: Bool) {
296341
// No-op on iOS — geolocation permission is handled natively
297342
}

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "4.0.0",
4+
"version": "3.9.0",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

0 commit comments

Comments
 (0)