Skip to content
Open
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
24 changes: 22 additions & 2 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,27 @@ const requireNativeComponent = (..._args: any[]) => {
});
};

const Text = (props: any) => {
const React = require('react');
return React.createElement('Text', props, props.children);
};

const StyleSheet = {
flatten: jest.fn(style => style),
};

const UIManager = {
getViewManagerConfig: jest.fn(() => ({
Commands: {
respondToEvent: 'respondToEvent',
reload: 'reload',
},
})),
dispatchViewManagerCommand: jest.fn(),
};

const findNodeHandle = jest.fn(() => 1);

const exampleConfig = {preloading: true};

const ShopifyCheckoutSheetKit = {
Expand All @@ -52,12 +69,12 @@ const ShopifyCheckoutSheetKit = {
dismiss: jest.fn(),
invalidateCache: jest.fn(),
getConfig: jest.fn(async () => exampleConfig),
setConfig: jest.fn(),
setConfig: jest.fn(async () => {}),
addEventListener: jest.fn(),
removeEventListeners: jest.fn(),
initiateGeolocationRequest: jest.fn(),
configureAcceleratedCheckouts: jest.fn(),
isAcceleratedCheckoutAvailable: jest.fn(),
isAcceleratedCheckoutAvailable: jest.fn(async () => false),
};

// CommonJS export for Jest manual mock resolution
Expand All @@ -75,4 +92,7 @@ module.exports = {
},
},
StyleSheet,
UIManager,
findNodeHandle,
Text,
};
17 changes: 10 additions & 7 deletions modules/@shopify/checkout-sheet-kit/package.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"lib/commonjs/index.d.js.map",
"lib/commonjs/index.js",
"lib/commonjs/index.js.map",
"lib/commonjs/ShopifyCheckoutEventProvider.js",
"lib/commonjs/ShopifyCheckoutEventProvider.js.map",
"lib/commonjs/native/RCTCheckoutWebView.js",
"lib/commonjs/native/RCTCheckoutWebView.js.map",
"lib/module/components/AcceleratedCheckoutButtons.js",
"lib/module/components/AcceleratedCheckoutButtons.js.map",
"lib/module/components/ShopifyCheckout.js",
Expand All @@ -56,8 +56,8 @@
"lib/module/index.d.js.map",
"lib/module/index.js",
"lib/module/index.js.map",
"lib/module/ShopifyCheckoutEventProvider.js",
"lib/module/ShopifyCheckoutEventProvider.js.map",
"lib/module/native/RCTCheckoutWebView.js",
"lib/module/native/RCTCheckoutWebView.js.map",
"lib/typescript/src/components/AcceleratedCheckoutButtons.d.ts",
"lib/typescript/src/components/AcceleratedCheckoutButtons.d.ts.map",
"lib/typescript/src/components/ShopifyCheckout.d.ts",
Expand All @@ -66,8 +66,10 @@
"lib/typescript/src/context.d.ts.map",
"lib/typescript/src/index.d.ts",
"lib/typescript/src/index.d.ts.map",
"lib/typescript/src/ShopifyCheckoutEventProvider.d.ts",
"lib/typescript/src/ShopifyCheckoutEventProvider.d.ts.map",
"lib/typescript/src/native/__mocks__/RCTCheckoutWebView.d.ts",
"lib/typescript/src/native/__mocks__/RCTCheckoutWebView.d.ts.map",
"lib/typescript/src/native/RCTCheckoutWebView.d.ts",
"lib/typescript/src/native/RCTCheckoutWebView.d.ts.map",
"package.json",
"src/components/AcceleratedCheckoutButtons.tsx",
"src/components/ShopifyCheckout.tsx",
Expand All @@ -76,5 +78,6 @@
"src/events.d.ts",
"src/index.d.ts",
"src/index.ts",
"src/ShopifyCheckoutEventProvider.tsx"
"src/native/__mocks__/RCTCheckoutWebView.ts",
"src/native/RCTCheckoutWebView.ts"
]

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,21 @@ import React, {
useCallback,
useImperativeHandle,
forwardRef,
useEffect,
} from 'react';
import {UIManager, findNodeHandle, type ViewStyle} from 'react-native';
import {useWebviewRegistration} from '../context';
import {
requireNativeComponent,
UIManager,
findNodeHandle,
type ViewStyle,
} from 'react-native';
import {useCheckoutEvents} from '../ShopifyCheckoutEventProvider';
RCTCheckoutWebView,
type NativeShopifyCheckoutWebViewProps,
} from '../native/RCTCheckoutWebView';
import type {
CheckoutAddressChangeStartEvent,
CheckoutCompleteEvent,
CheckoutPaymentMethodChangeStartEvent,
CheckoutStartEvent,
CheckoutSubmitStartEvent,
} from '../events.d';
import {
parseCheckoutError,
type CheckoutException,
type CheckoutNativeError,
} from '../errors.d';
import {parseCheckoutError, type CheckoutException} from '../errors.d';

export interface ShopifyCheckoutProps {
/**
Expand Down Expand Up @@ -123,30 +117,6 @@ export interface ShopifyCheckoutRef {
reload: () => void;
}

interface NativeShopifyCheckoutWebViewProps {
checkoutUrl: string;
auth?: string;
style?: ViewStyle;
testID?: string;
onStart?: (event: {nativeEvent: CheckoutStartEvent}) => void;
onFail?: (event: {nativeEvent: CheckoutNativeError}) => void;
onComplete?: (event: {nativeEvent: CheckoutCompleteEvent}) => void;
onCancel?: () => void;
onLinkClick?: (event: {nativeEvent: {url: string}}) => void;
onAddressChangeStart?: (event: {
nativeEvent: CheckoutAddressChangeStartEvent;
}) => void;
onSubmitStart?: (event: {nativeEvent: CheckoutSubmitStartEvent}) => void;
onPaymentMethodChangeStart?: (event: {
nativeEvent: CheckoutPaymentMethodChangeStartEvent;
}) => void;
}

const RCTCheckoutWebView =
requireNativeComponent<NativeShopifyCheckoutWebViewProps>(
'RCTCheckoutWebView',
);

/**
* Checkout provides a native webview component for displaying
* Shopify checkout pages directly within your React Native app.
Expand Down Expand Up @@ -211,16 +181,7 @@ export const ShopifyCheckout = forwardRef<
) => {
const webViewRef =
useRef<React.ComponentRef<typeof RCTCheckoutWebView>>(null);
const eventContext = useCheckoutEvents();

// Register webview reference with the event provider
useEffect(() => {
if (!eventContext) return;

eventContext.registerWebView(webViewRef);

return () => eventContext.unregisterWebView();
}, [eventContext]);
useWebviewRegistration(webViewRef);

const handleStart = useCallback<
Required<NativeShopifyCheckoutWebViewProps>['onStart']
Expand Down
Loading
Loading