Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- run: |
pnpm module clean
pnpm module build
pnpm module api:check
pnpm compare-snapshot
Comment thread
kieran-osgood-shopify marked this conversation as resolved.

lint:
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ experiences.

## Platform Requirements

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

## Version Compatibility

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

| Package version | React Native | Architecture |
| --------------- | -------------- | ------------------ |
| `4.x` | `>= 0.76` | New Architecture |
| `3.x` | `>= 0.70` | Old Architecture |
| `3.9.x` | `>= 0.76` | Old + New |
| `<=3.8.x` | `>= 0.70` | Old Architecture |

See the [React Native upgrade guide](https://reactnative.dev/docs/the-new-architecture/use-the-new-architecture)
for help enabling the New Architecture in your app.
Expand Down
6 changes: 6 additions & 0 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ module.exports = {
requireNativeComponent,
codegenNativeComponent,
TurboModuleRegistry: {
get: jest.fn((name: string) => {
if (name === 'ShopifyCheckoutSheetKit') {
return ShopifyCheckoutSheetKit;
}
return null;
}),
getEnforcing: jest.fn((name: string) => {
if (name === 'ShopifyCheckoutSheetKit') {
return ShopifyCheckoutSheetKit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require "json"

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

new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"

Pod::Spec.new do |s|
s.name = "RNShopifyCheckoutSheetKit"
s.version = package["version"]
Expand All @@ -16,8 +18,8 @@ Pod::Spec.new do |s|
s.source_files = "ios/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency "ShopifyCheckoutSheetKit", "~> 3.8.0"
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.8.0"
s.dependency "ShopifyCheckoutSheetKit", "= 3.8.2"
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "= 3.8.2"

install_modules_dependencies(s)
install_modules_dependencies(s) if new_arch_enabled
end
21 changes: 19 additions & 2 deletions modules/@shopify/checkout-sheet-kit/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ buildscript {
}

apply plugin: "com.android.library"
apply plugin: "com.facebook.react"

def isNewArchitectureEnabled() {
def newArchEnabled = project.hasProperty("newArchEnabled")
? project.property("newArchEnabled")
: rootProject.hasProperty("newArchEnabled")
? rootProject.property("newArchEnabled")
: "false"

return newArchEnabled.toString() == "true"
}

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

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

buildFeatures {
buildConfig true
}

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
Expand All @@ -50,6 +67,7 @@ android {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

buildTypes {
Expand Down Expand Up @@ -93,4 +111,3 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.5")
debugImplementation("com.shopify:checkout-sheet-kit:${SHOPIFY_CHECKOUT_SDK_VERSION}")
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ndkVersion=23.1.7779620
buildToolsVersion = "35.0.0"

# Version of Shopify Checkout SDK to use with React Native
SHOPIFY_CHECKOUT_SDK_VERSION=3.6.0
SHOPIFY_CHECKOUT_SDK_VERSION=3.6.3
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,26 @@ of this software and associated documentation files (the "Software"), to deal
import android.content.Context;
import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.shopify.checkoutsheetkit.NativeShopifyCheckoutSheetKitSpec;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.shopify.checkoutsheetkit.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {
@ReactModule(name = ShopifyCheckoutSheetKitModule.NAME)
public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule implements TurboModule {

public static final String NAME = "ShopifyCheckoutSheetKit";

public static Configuration checkoutConfig = new Configuration();

Expand All @@ -62,8 +67,14 @@ public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
});
}

@NonNull
@Override
public String getName() {
return NAME;
}

@Override
protected Map<String, Object> getTypedExportedConstants() {
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("version", ShopifyCheckoutSheetKit.version);
return constants;
Expand All @@ -81,7 +92,7 @@ public void removeListeners(double count) {

@ReactMethod
public void present(String checkoutURL) {
Activity currentActivity = getCurrentActivity();
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
if (currentActivity instanceof ComponentActivity) {
checkoutEventProcessor = new CustomCheckoutEventProcessor(currentActivity, this.reactContext);
currentActivity.runOnUiThread(() -> {
Expand All @@ -101,7 +112,7 @@ public void dismiss() {

@ReactMethod
public void preload(String checkoutURL) {
Activity currentActivity = getCurrentActivity();
Activity currentActivity = getReactApplicationContext().getCurrentActivity();

if (currentActivity instanceof ComponentActivity) {
ShopifyCheckoutSheetKit.preload(checkoutURL, (ComponentActivity) currentActivity);
Expand All @@ -113,15 +124,15 @@ public void invalidateCache() {
ShopifyCheckoutSheetKit.invalidate();
}

@ReactMethod(isBlockingSynchronousMethod = true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI These all exist as turbo module plumbing - the typescript spec includes them modules/@shopify/checkout-sheet-kit/src/specs/NativeShopifyCheckoutSheetKit.ts but they're not actually run at runtime because we noop as we guard accelerated checkouts in JS via Platform.OS === 'ios'

public WritableMap getConfig() {
@ReactMethod
public void getConfig(Promise promise) {
WritableMap resultConfig = Arguments.createMap();

resultConfig.putBoolean("preloading", checkoutConfig.getPreloading().getEnabled());
resultConfig.putString("colorScheme", colorSchemeToString(checkoutConfig.getColorScheme()));
resultConfig.putString("logLevel", logLevelToString(checkoutConfig.getLogLevel()));

return resultConfig;
promise.resolve(resultConfig);
}

@ReactMethod
Expand Down Expand Up @@ -165,30 +176,31 @@ public void setConfig(ReadableMap config) {
});
}

@ReactMethod(isBlockingSynchronousMethod = true)
public boolean configureAcceleratedCheckouts(
@ReactMethod
public void configureAcceleratedCheckouts(
String storefrontDomain,
String storefrontAccessToken,
String customerEmail,
String customerPhoneNumber,
String customerAccessToken,
String applePayMerchantIdentifier,
ReadableArray applyPayContactFields,
ReadableArray supportedShippingCountries) {
ReadableArray supportedShippingCountries,
Promise promise) {
// Accelerated checkouts not supported on Android
return false;
promise.resolve(false);
}

@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isAcceleratedCheckoutAvailable() {
@ReactMethod
public void isAcceleratedCheckoutAvailable(Promise promise) {
// Accelerated checkouts not supported on Android
return false;
promise.resolve(false);
}

@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isApplePayAvailable() {
@ReactMethod
public void isApplePayAvailable(Promise promise) {
// Apple Pay not available on Android
return false;
promise.resolve(false);
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

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

public class ShopifyCheckoutSheetKitPackage extends TurboReactPackage {
public class ShopifyCheckoutSheetKitPackage extends BaseReactPackage {

@NonNull
@Override
Expand Down Expand Up @@ -67,7 +67,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
false, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
true // isTurboModule
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED // isTurboModule
));
return moduleInfos;
};
Expand Down
47 changes: 47 additions & 0 deletions modules/@shopify/checkout-sheet-kit/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/lib/typescript/src/index.d.ts",
"compiler": {
"tsconfigFilePath": "<projectFolder>/tsconfig.build.json"
},
"newlineKind": "lf",
"apiReport": {
"enabled": true,
"reportFolder": "<projectFolder>/api/",
"reportFileName": "checkout-sheet-kit.api.md"
},
"docModel": {
"enabled": false
},
"dtsRollup": {
"enabled": false
},
"tsdocMetadata": {
"enabled": false
},
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning"
},
"ae-missing-release-tag": {
"logLevel": "none"
},
"ae-forgotten-export": {
"logLevel": "none",
"addToApiReportFile": false
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "none"
}
}
}
}
Loading
Loading