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
7 changes: 4 additions & 3 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ const ShopifyCheckoutSheetKit = {
present: jest.fn(),
dismiss: jest.fn(),
invalidateCache: jest.fn(),
getConfig: jest.fn(async () => exampleConfig),
getConfig: jest.fn(() => exampleConfig),
setConfig: jest.fn(),
addEventListener: jest.fn(),
removeEventListeners: jest.fn(),
initiateGeolocationRequest: jest.fn(),
configureAcceleratedCheckouts: jest.fn(),
isAcceleratedCheckoutAvailable: jest.fn(),
configureAcceleratedCheckouts: jest.fn(() => true),
isAcceleratedCheckoutAvailable: jest.fn(() => true),
isApplePayAvailable: jest.fn(() => true),
addListener: jest.fn(),
removeListeners: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ require "json"

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

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'

Pod::Spec.new do |s|
s.name = "RNShopifyCheckoutSheetKit"
s.version = package["version"]
Expand All @@ -19,29 +15,9 @@ 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"

if fabric_enabled
# Use React Native's helper if available, otherwise add dependencies directly
if defined?(install_modules_dependencies)
install_modules_dependencies(s)
else
# Fallback: manually specify dependencies for New Architecture
s.dependency "React-Codegen"
s.dependency "RCT-Folly", :modular_headers => true
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end

s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.dependency "React-Core"
s.dependency "ShopifyCheckoutSheetKit", "~> 3.8.0"
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.8.0"

s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
end
install_modules_dependencies(s)
end
9 changes: 1 addition & 8 deletions modules/@shopify/checkout-sheet-kit/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ buildscript {
}
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"

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

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[name]).toInteger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ of this software and associated documentation files (the "Software"), to deal
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.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.shopify.checkoutsheetkit.NativeShopifyCheckoutSheetKitSpec;
import com.shopify.checkoutsheetkit.*;

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

public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule {
private static final String MODULE_NAME = "ShopifyCheckoutSheetKit";
public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {

public static Configuration checkoutConfig = new Configuration();

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

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

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

@ReactMethod
public void removeListeners(Integer count) {
public void removeListeners(double count) {
// No-op but required for RN to register module
}

Expand Down Expand Up @@ -119,15 +113,15 @@ public void invalidateCache() {
ShopifyCheckoutSheetKit.invalidate();
}

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

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

promise.resolve(resultConfig);
return resultConfig;
}

@ReactMethod
Expand Down Expand Up @@ -171,8 +165,34 @@ public void setConfig(ReadableMap config) {
});
}

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

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

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

@ReactMethod
public void initiateGeolocationRequest(Boolean allow) {
public void initiateGeolocationRequest(boolean allow) {
if (checkoutEventProcessor != null) {
checkoutEventProcessor.invokeGeolocationCallback(allow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,52 @@ of this software and associated documentation files (the "Software"), to deal
package com.shopify.reactnative.checkoutsheetkit;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.ReactPackage;
import com.facebook.react.TurboReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopifyCheckoutSheetKitPackage implements ReactPackage {
public class ShopifyCheckoutSheetKitPackage extends TurboReactPackage {

@NonNull
@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@NonNull
@Nullable
@Override
public List<NativeModule> createNativeModules(
@NonNull ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new ShopifyCheckoutSheetKitModule(reactContext));

return modules;
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext) {
if (name.equals(ShopifyCheckoutSheetKitModule.NAME)) {
return new ShopifyCheckoutSheetKitModule(reactContext);
}
return null;
}

@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
moduleInfos.put(
ShopifyCheckoutSheetKitModule.NAME,
new ReactModuleInfo(
ShopifyCheckoutSheetKitModule.NAME,
ShopifyCheckoutSheetKitModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
true // isTurboModule
));
return moduleInfos;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,42 @@ of this software and associated documentation files (the "Software"), to deal

#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <RNShopifyCheckoutSheetKitSpec/RNShopifyCheckoutSheetKitSpec.h>

// Registers the Swift module class (ShopifyCheckoutSheetKit.swift) with the RN
// runtime under the name 'RCTShopifyCheckoutSheetKit', 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 `NativeShopifyCheckoutSheetKitSpecJSI` invokes
// each method via its `@objc` selector directly (see ShopifyCheckoutSheetKit.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 (RCTShopifyCheckoutSheetKit, NativeShopifyCheckoutSheetKitSpecBase)

RCT_EXTERN_METHOD(setConfig:(NSDictionary *)configuration)

@interface RCT_EXTERN_MODULE (RCTShopifyCheckoutSheetKit, NSObject)

/**
* Present checkout
*/
RCT_EXTERN_METHOD(present : (NSString*)checkoutURLString);

/**
* Preload checkout
*/
RCT_EXTERN_METHOD(preload : (NSString*)checkoutURLString);

/**
* Dismiss checkout
*/
RCT_EXTERN_METHOD(dismiss);

/**
* Invalidate preload cache
*/
RCT_EXTERN_METHOD(invalidateCache);

/**
* Set configuration for checkout
*/
RCT_EXTERN_METHOD(setConfig : (NSDictionary*)configuration);

/**
* Return configuration for checkout
*/
RCT_EXTERN_METHOD(getConfig : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject)

/**
* Configure AcceleratedCheckouts
*/
RCT_EXTERN_METHOD(configureAcceleratedCheckouts : (NSString*)storefrontDomain storefrontAccessToken : (
NSString*)storefrontAccessToken customerEmail : (NSString*)customerEmail customerPhoneNumber : (NSString*)
customerPhoneNumber customerAccessToken : (NSString*)customerAccessToken applePayMerchantIdentifier : (NSString*)
applePayMerchantIdentifier applyPayContactFields : (NSArray*)applyPayContactFields supportedShippingCountries : (NSArray*)supportedShippingCountries resolve : (
RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);

/**
* Check if accelerated checkout is available
*/
RCT_EXTERN_METHOD(
isAcceleratedCheckoutAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
@end

/**
* Check if Apple Pay is available
*/
RCT_EXTERN_METHOD(isApplePayAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
// 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 RCTShopifyCheckoutSheetKit (TurboModule) <RCTTurboModule>
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params;
@end

@implementation RCTShopifyCheckoutSheetKit (TurboModule)
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeShopifyCheckoutSheetKitSpecJSI>(
params);
}
@end

/**
Expand Down
Loading
Loading