Skip to content

Commit 1471bb3

Browse files
authored
Dedupe react-native versions, add jotai for global state (#39)
* Dedupe react-native versions, add jotai for global state * Update lockfile
1 parent 0d8e52d commit 1471bb3

File tree

16 files changed

+399
-567
lines changed

16 files changed

+399
-567
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const path = require('path');
22
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
33
const escape = require('escape-string-regexp');
44
const exclusionList = require('metro-config/src/defaults/exclusionList');
5-
const pkg = require('../package.json');
5+
const pkg = require('./package.json');
66

7-
const root = path.resolve(__dirname, '..');
7+
const root = path.resolve(__dirname);
88
const sample = path.resolve(root, 'sample');
99

1010
const modules = Object.keys({...pkg.peerDependencies});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ if (!('ShopifyCheckoutKit' in NativeModules)) {
4545
}
4646

4747
class ShopifyCheckoutKit implements ShopifyCheckout {
48-
private eventEmitter: NativeEventEmitter;
48+
private static eventEmitter: NativeEventEmitter = new NativeEventEmitter(
49+
RNShopifyCheckoutKit,
50+
);
4951

5052
constructor(configuration?: Configuration) {
5153
if (configuration != null) {
5254
this.setConfig(configuration);
5355
}
54-
55-
this.eventEmitter = new NativeEventEmitter(RNShopifyCheckoutKit);
5656
}
5757

5858
public readonly version: string = RNShopifyCheckoutKit.version;
@@ -77,11 +77,11 @@ class ShopifyCheckoutKit implements ShopifyCheckout {
7777
eventName: CheckoutEvent,
7878
callback: CheckoutEventCallback,
7979
): EmitterSubscription | undefined {
80-
return this.eventEmitter.addListener(eventName, callback);
80+
return ShopifyCheckoutKit.eventEmitter.addListener(eventName, callback);
8181
}
8282

8383
public removeEventListeners(event: CheckoutEvent) {
84-
this.eventEmitter.removeAllListeners(event);
84+
ShopifyCheckoutKit.eventEmitter.removeAllListeners(event);
8585
}
8686
}
8787

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jest.mock('react-native', () => {
2020
};
2121

2222
const ShopifyCheckoutKit = {
23+
eventEmitter: NativeEventEmitter(),
2324
version: '0.7.0',
2425
preload: jest.fn(),
2526
present: jest.fn(),
@@ -110,7 +111,7 @@ describe('ShopifyCheckoutKit', () => {
110111
const callback = jest.fn();
111112
instance.addEventListener(eventName, callback);
112113
// @ts-expect-error
113-
expect(instance.eventEmitter.addListener).toHaveBeenCalledWith(
114+
expect(ShopifyCheckoutKit.eventEmitter.addListener).toHaveBeenCalledWith(
114115
eventName,
115116
callback,
116117
);
@@ -123,10 +124,10 @@ describe('ShopifyCheckoutKit', () => {
123124
instance.addEventListener('close', () => {});
124125
instance.addEventListener('close', () => {});
125126
instance.removeEventListeners('close');
126-
// @ts-expect-error
127-
expect(instance.eventEmitter.removeAllListeners).toHaveBeenCalledWith(
128-
'close',
129-
);
127+
expect(
128+
// @ts-expect-error
129+
ShopifyCheckoutKit.eventEmitter.removeAllListeners,
130+
).toHaveBeenCalledWith('close');
130131
});
131132
});
132133
});

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
"turbo": "turbo",
2424
"test": "jest"
2525
},
26-
"dependencies": {
27-
"react": "^18.2.0"
28-
},
2926
"devDependencies": {
3027
"@babel/core": "^7.20.0",
3128
"@babel/preset-env": "^7.20.0",
@@ -34,15 +31,17 @@
3431
"@react-native/metro-config": "^0.72.11",
3532
"@tsconfig/react-native": "^3.0.0",
3633
"@types/jest": "^29.5.10",
37-
"@types/react": "^18.0.24",
34+
"@types/react": "^18",
35+
"@types/react-native": "0.72.7",
3836
"@types/react-native-dotenv": "^0.2.1",
3937
"@types/react-test-renderer": "^18.0.0",
4038
"babel-jest": "^29.7.0",
4139
"eslint": "^8.19.0",
4240
"jest": "^29.2.1",
4341
"pod-install": "^0.1.39",
4442
"prettier": "^2.4.1",
45-
"react-native": "^0.72.7",
43+
"react": "^18.2.0",
44+
"react-native": "0.72.7",
4645
"react-native-dotenv": "^3.4.9",
4746
"react-native-gradle-plugin": "^0.71.19",
4847
"react-test-renderer": "18.2.0",
@@ -76,5 +75,8 @@
7675
"no-console": "error"
7776
}
7877
},
79-
"packageManager": "[email protected]"
78+
"packageManager": "[email protected]",
79+
"dependencies": {
80+
"react-native-gesture-handler": "^2.14.0"
81+
}
8082
}

sample/android/app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
apply plugin: "com.android.application"
22
apply plugin: "com.facebook.react"
33

4+
project.ext["REACT_NATIVE_NODE_MODULES_DIR"] = file("../../../node_modules/react-native")
5+
46
/**
57
* This is the configuration block to customize your React Native Android app.
68
* By default you don't need to apply any configuration, just uncomment the lines you need.
79
*/
810
react {
911
/* Folders */
1012
// The root of your project, i.e. where "package.json" lives. Default is '..'
11-
root = file("../")
13+
root = file("../../")
1214
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
13-
reactNativeDir = file("../../node_modules/react-native")
15+
reactNativeDir = file("../../../node_modules/react-native")
1416
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
15-
codegenDir = file("../../node_modules/@react-native/codegen")
17+
codegenDir = file("../../../node_modules/@react-native/codegen")
1618
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
1719
cliFile = file("../../node_modules/react-native/cli.js")
1820

@@ -143,4 +145,4 @@ project.ext.vectoricons = [
143145

144146
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
145147

146-
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
148+
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

sample/android/gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ newArchEnabled=false
4343
# If set to false, you will be using JSC instead.
4444
hermesEnabled=true
4545

46-
4746
android.disableAutomaticComponentCreation=true
4847

4948
# Version of Shopify Checkout SDK to use with React Native

sample/android/settings.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
rootProject.name = 'ReactNative'
2-
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
2+
3+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
4+
35
include ':app'
4-
includeBuild('../node_modules/@react-native/gradle-plugin')
6+
7+
includeBuild('../../node_modules/@react-native/gradle-plugin')

sample/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require Pod::Executable.execute_command('node', ['-p',
55
{paths: [process.argv[1]]},
66
)', __dir__]).strip
77

8-
platform :ios, 13
8+
platform :ios, '13'
99

1010
prepare_react_native_project!
1111

0 commit comments

Comments
 (0)