Skip to content

Commit 8e4f802

Browse files
committed
[Swift] Remove preload feature library and sample
1 parent d081d8e commit 8e4f802

28 files changed

Lines changed: 39 additions & 680 deletions

platforms/react-native/__mocks__/react-native.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ const StyleSheet = {
4545
flatten: jest.fn(style => style),
4646
};
4747

48-
const exampleConfig = {preloading: true};
48+
const exampleConfig = {
49+
colorScheme: 'automatic',
50+
logLevel: 'error',
51+
};
4952

5053
const ShopifyCheckoutKit = {
5154
version: '0.7.0',

platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class RCTShopifyCheckoutKit: RCTEventEmitter {
133133
}
134134

135135
@objc func invalidateCache() {
136-
invalidate()
136+
// Retained for compatibility with the generated native module interface.
137137
}
138138

139139
@objc func present(_ checkoutURL: String) {
@@ -146,9 +146,7 @@ class RCTShopifyCheckoutKit: RCTEventEmitter {
146146
}
147147
}
148148

149-
@objc func preload(_ checkoutURL: String) {
150-
// Public native preload support is not exposed by the local iOS SDK.
151-
}
149+
@objc func preload(_: String) {}
152150

153151
private func getColorScheme(_ colorScheme: String) -> Configuration.ColorScheme {
154152
switch colorScheme {
@@ -173,10 +171,6 @@ class RCTShopifyCheckoutKit: RCTEventEmitter {
173171
ShopifyCheckoutKit.configuration.title = title
174172
}
175173

176-
if let preloading = configuration["preloading"] as? Bool {
177-
ShopifyCheckoutKit.configuration.preloading.enabled = preloading
178-
}
179-
180174
if let colorScheme = configuration["colorScheme"] as? String {
181175
ShopifyCheckoutKit.configuration.colorScheme = getColorScheme(colorScheme)
182176
}
@@ -205,7 +199,6 @@ class RCTShopifyCheckoutKit: RCTEventEmitter {
205199
@objc func getConfig() -> NSDictionary {
206200
return [
207201
"title": ShopifyCheckoutKit.configuration.title,
208-
"preloading": ShopifyCheckoutKit.configuration.preloading.enabled,
209202
"colorScheme": ShopifyCheckoutKit.configuration.colorScheme.rawValue,
210203
"tintColor": ShopifyCheckoutKit.configuration.tintColor,
211204
"backgroundColor": ShopifyCheckoutKit.configuration.backgroundColor,

platforms/react-native/modules/@shopify/checkout-kit-react-native/src/context.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ interface Context {
4141
getConfig: () => Configuration | undefined;
4242
setConfig: (config: Configuration) => void;
4343
removeEventListeners: RemoveEventListeners;
44-
preload: (checkoutUrl: string) => void;
4544
present: (checkoutUrl: string) => void;
4645
dismiss: () => void;
47-
invalidate: () => void;
4846
version: Maybe<string>;
4947
}
5048

@@ -108,16 +106,6 @@ export function ShopifyCheckoutProvider({
108106
}
109107
}, []);
110108

111-
const preload = useCallback((checkoutUrl: string) => {
112-
if (checkoutUrl) {
113-
instance.current?.preload(checkoutUrl);
114-
}
115-
}, []);
116-
117-
const invalidate = useCallback(() => {
118-
instance.current?.invalidate();
119-
}, []);
120-
121109
const dismiss = useCallback(() => {
122110
instance.current?.dismiss();
123111
}, []);
@@ -137,9 +125,7 @@ export function ShopifyCheckoutProvider({
137125
dismiss,
138126
setConfig,
139127
getConfig,
140-
preload,
141128
present,
142-
invalidate,
143129
removeEventListeners,
144130
version: instance.current?.version,
145131
};
@@ -150,9 +136,7 @@ export function ShopifyCheckoutProvider({
150136
removeEventListeners,
151137
getConfig,
152138
setConfig,
153-
preload,
154139
present,
155-
invalidate,
156140
]);
157141

158142
return (

platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ export interface AndroidAutomaticColors {
111111
}
112112

113113
interface CommonConfiguration {
114-
/**
115-
* Enable/disable preloading for checkout. This option must be enabled for `.preload()` to work as expected.
116-
*/
117-
preloading?: boolean;
118114
/**
119115
* Sets the title of the Checkout sheet.
120116
*
@@ -282,15 +278,6 @@ export interface ShopifyCheckoutKit {
282278
* The version number of the Shopify Checkout SDK.
283279
*/
284280
readonly version: string;
285-
/**
286-
* Preload the checkout for faster presentation.
287-
*/
288-
preload(checkoutURL: string): void;
289-
290-
/**
291-
* Invalidate preload cache.
292-
*/
293-
invalidate(): void;
294281
/**
295282
* Present the checkout.
296283
*/

platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,6 @@ class ShopifyCheckout implements ShopifyCheckoutKit {
124124
RNShopifyCheckoutKit.dismiss();
125125
}
126126

127-
/**
128-
* Invalidates the checkout that was cached using preload
129-
*/
130-
public invalidate(): void {
131-
RNShopifyCheckoutKit.invalidateCache();
132-
}
133-
134-
/**
135-
* Preloads checkout for a given URL to improve performance
136-
* @param checkoutUrl The URL of the checkout to preload
137-
*/
138-
public preload(checkoutUrl: string): void {
139-
RNShopifyCheckoutKit.preload(checkoutUrl);
140-
}
141-
142127
/**
143128
* Presents the checkout sheet for a given checkout URL
144129
* @param checkoutUrl The URL of the checkout to display
@@ -395,7 +380,7 @@ class ShopifyCheckout implements ShopifyCheckoutKit {
395380
* literal unions and TypeScript enums collapse to plain `string` at the
396381
* bridge boundary. On the JS side consumers expect the typed `ColorScheme`
397382
* and `LogLevel` enums, so we coerce those two fields here. The rest of
398-
* the payload (preloading, title, nested colors) passes through unchanged.
383+
* the rest of the payload passes through unchanged.
399384
*/
400385
private coerceConfigurationResult(
401386
raw: ReturnType<typeof RNShopifyCheckoutKit.getConfig>,

platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/context.test.tsx

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -231,69 +231,6 @@ describe('useShopifyCheckout', () => {
231231
).not.toHaveBeenCalled();
232232
});
233233

234-
it('provides preload function and calls it with checkoutUrl', () => {
235-
let hookValue: any;
236-
const onHookValue = (value: any) => {
237-
hookValue = value;
238-
};
239-
240-
render(
241-
<Wrapper>
242-
<HookTestComponent onHookValue={onHookValue} />
243-
</Wrapper>,
244-
);
245-
246-
act(() => {
247-
hookValue.preload(checkoutUrl);
248-
});
249-
250-
expect(NativeModules.ShopifyCheckoutKit.preload).toHaveBeenCalledWith(
251-
checkoutUrl,
252-
);
253-
});
254-
255-
it('does not call preload with empty checkoutUrl', () => {
256-
let hookValue: any;
257-
const onHookValue = (value: any) => {
258-
hookValue = value;
259-
};
260-
261-
render(
262-
<Wrapper>
263-
<HookTestComponent onHookValue={onHookValue} />
264-
</Wrapper>,
265-
);
266-
267-
act(() => {
268-
hookValue.preload('');
269-
});
270-
271-
expect(
272-
NativeModules.ShopifyCheckoutKit.preload,
273-
).not.toHaveBeenCalled();
274-
});
275-
276-
it('provides invalidate function', () => {
277-
let hookValue: any;
278-
const onHookValue = (value: any) => {
279-
hookValue = value;
280-
};
281-
282-
render(
283-
<Wrapper>
284-
<HookTestComponent onHookValue={onHookValue} />
285-
</Wrapper>,
286-
);
287-
288-
act(() => {
289-
hookValue.invalidate();
290-
});
291-
292-
expect(
293-
NativeModules.ShopifyCheckoutKit.invalidateCache,
294-
).toHaveBeenCalled();
295-
});
296-
297234
it('provides dismiss function', () => {
298235
let hookValue: any;
299236
const onHookValue = (value: any) => {
@@ -350,7 +287,6 @@ describe('useShopifyCheckout', () => {
350287

351288
const config = hookValue.getConfig();
352289
expect(config).toEqual({
353-
preloading: true,
354290
colorScheme: 'automatic',
355291
logLevel: 'error',
356292
});

platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,6 @@ describe('ShopifyCheckoutKit', () => {
113113
});
114114
});
115115

116-
describe('preload', () => {
117-
it('calls `preload` with a checkout URL', () => {
118-
const instance = new ShopifyCheckout();
119-
instance.preload(checkoutUrl);
120-
expect(
121-
NativeModule.preload,
122-
).toHaveBeenCalledTimes(1);
123-
expect(
124-
NativeModule.preload,
125-
).toHaveBeenCalledWith(checkoutUrl);
126-
});
127-
});
128-
129-
describe('invalidate', () => {
130-
it('calls `invalidateCache`', () => {
131-
const instance = new ShopifyCheckout();
132-
instance.invalidate();
133-
expect(
134-
NativeModule.invalidateCache,
135-
).toHaveBeenCalledTimes(1);
136-
});
137-
});
138-
139116
describe('present', () => {
140117
it('calls `present` with a checkout URL', () => {
141118
const instance = new ShopifyCheckout();
@@ -163,7 +140,6 @@ describe('ShopifyCheckoutKit', () => {
163140
it('returns the parsed config from the Native Module', () => {
164141
const instance = new ShopifyCheckout();
165142
expect(instance.getConfig()).toStrictEqual({
166-
preloading: true,
167143
colorScheme: ColorScheme.automatic,
168144
logLevel: LogLevel.error,
169145
});

platforms/react-native/sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
5757
}
5858

5959
private func resetCheckoutKitDefaults() {
60-
ShopifyCheckoutKit.configuration.preloading = Configuration.Preloading(enabled: true)
6160
ShopifyCheckoutKit.configuration.colorScheme = .automatic
6261
ShopifyCheckoutKit.configuration.closeButtonTintColor = nil
6362
}

platforms/react-native/sample/ios/ReactNativeTests/CheckoutDidFailTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CheckoutDidFailTests: XCTestCase {
4040
}
4141

4242
private func resetShopifyCheckoutKitDefaults() {
43-
ShopifyCheckoutSheetKit.configuration.preloading = Configuration.Preloading(enabled: true)
4443
ShopifyCheckoutSheetKit.configuration.colorScheme = .automatic
4544
}
4645

platforms/react-native/sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class ShopifyCheckoutKitTests: XCTestCase {
4141
}
4242

4343
private func resetShopifyCheckoutKitDefaults() {
44-
ShopifyCheckoutKit.configuration.preloading.enabled = true
4544
ShopifyCheckoutKit.configuration.colorScheme = .automatic
4645
ShopifyCheckoutKit.configuration.closeButtonTintColor = nil
4746
ShopifyCheckoutKit.configuration.logLevel = LogLevel.error
@@ -57,14 +56,12 @@ class ShopifyCheckoutKitTests: XCTestCase {
5756
let result = shopifyCheckoutKit.getConfig() as? [String: Any]
5857

5958
// Verify that getConfig returned the expected result
60-
XCTAssertEqual(result?["preloading"] as? Bool, true)
6159
XCTAssertEqual(result?["colorScheme"] as? String, "automatic")
6260
}
6361

6462
/// configure
6563
func testConfigure() {
6664
let configuration: [AnyHashable: Any] = [
67-
"preloading": true,
6865
"colorScheme": "dark",
6966
"colors": [
7067
"ios": [
@@ -76,22 +73,11 @@ class ShopifyCheckoutKitTests: XCTestCase {
7673

7774
shopifyCheckoutKit.setConfig(configuration)
7875

79-
XCTAssertTrue(ShopifyCheckoutKit.configuration.preloading.enabled)
8076
XCTAssertEqual(ShopifyCheckoutKit.configuration.colorScheme, .dark)
8177
XCTAssertEqual(ShopifyCheckoutKit.configuration.tintColor, UIColor(hex: "#FF0000"))
8278
XCTAssertEqual(ShopifyCheckoutKit.configuration.backgroundColor, UIColor(hex: "#0000FF"))
8379
}
8480

85-
func testConfigureWithPartialConfig() {
86-
let configuration: [AnyHashable: Any] = [
87-
"preloading": false
88-
]
89-
90-
shopifyCheckoutKit.setConfig(configuration)
91-
92-
XCTAssertFalse(ShopifyCheckoutKit.configuration.preloading.enabled)
93-
}
94-
9581
func testConfigureWithInvalidColors() {
9682
let configuration: [AnyHashable: Any] = [
9783
"colors": [
@@ -243,9 +229,7 @@ class ShopifyCheckoutKitTests: XCTestCase {
243229
}
244230

245231
func testSetConfigWithoutLogLevelDefaultsToError() {
246-
let configuration: [AnyHashable: Any] = [
247-
"preloading": true
248-
]
232+
let configuration: [AnyHashable: Any] = [:]
249233

250234
shopifyCheckoutKit.setConfig(configuration)
251235

0 commit comments

Comments
 (0)