Skip to content

Commit 48a428e

Browse files
committed
Refactor Android module to work across architectures
1 parent 08882f6 commit 48a428e

File tree

10 files changed

+409
-58
lines changed

10 files changed

+409
-58
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ jobs:
9191
fail-fast: false
9292
matrix:
9393
include:
94-
- arch: Legacy Arch
94+
- arch: Legacy arch
9595
new_arch_enabled: 'false'
96-
- arch: New Arch
96+
- arch: New arch
9797
new_arch_enabled: 'true'
9898
steps:
9999
- name: Checkout
@@ -132,9 +132,9 @@ jobs:
132132
fail-fast: false
133133
matrix:
134134
include:
135-
- arch: legacy
135+
- arch: Legacy arch
136136
new_arch_enabled: 'false'
137-
- arch: new-arch
137+
- arch: New arch
138138
new_arch_enabled: 'true'
139139
steps:
140140
- name: Checkout

modules/@shopify/checkout-sheet-kit/android/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ android {
8080
sourceCompatibility JavaVersion.VERSION_1_8
8181
targetCompatibility JavaVersion.VERSION_1_8
8282
}
83+
84+
// Note: this is where the module class is chosen, based on the RN architecture
85+
sourceSets {
86+
main.java.srcDirs += ["src/shared/java"]
87+
88+
if (isNewArchitectureEnabled()) {
89+
main.java.srcDirs += ["src/newarch/java"]
90+
} else {
91+
main.java.srcDirs += ["src/legacy/java"]
92+
}
93+
}
8394
}
8495

8596
repositories {
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
MIT License
3+
4+
Copyright 2023 - Present, Shopify Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package com.shopify.reactnative.checkoutsheetkit;
24+
25+
import com.facebook.react.bridge.Promise;
26+
import com.facebook.react.bridge.ReactApplicationContext;
27+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
28+
import com.facebook.react.bridge.ReactMethod;
29+
import com.facebook.react.bridge.ReadableArray;
30+
import com.facebook.react.bridge.ReadableMap;
31+
32+
import java.util.Map;
33+
34+
/**
35+
* @note
36+
*
37+
* This is the legacy module class for the ShopifyCheckoutSheetKit module.
38+
* It is used to support applications using React Native with the old
39+
* legacy architecture.
40+
*/
41+
42+
public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule {
43+
private final CheckoutKitModule common;
44+
public static com.shopify.checkoutsheetkit.Configuration checkoutConfig;
45+
46+
public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
47+
super(reactContext);
48+
this.common = new CheckoutKitModule(reactContext);
49+
ShopifyCheckoutSheetKitModule.checkoutConfig = CheckoutKitModule.checkoutConfig;
50+
}
51+
52+
@Override
53+
public String getName() {
54+
return common.getName();
55+
}
56+
57+
@Override
58+
public Map<String, Object> getConstants() {
59+
return common.getConstants();
60+
}
61+
62+
@ReactMethod
63+
public void addListener(String eventName) {
64+
common.addListener(eventName);
65+
}
66+
67+
@ReactMethod
68+
public void configureAcceleratedCheckouts(
69+
String storefrontDomain,
70+
String storefrontAccessToken,
71+
String customerEmail,
72+
String customerPhoneNumber,
73+
String customerAccessToken,
74+
String applePayMerchantIdentifier,
75+
ReadableArray applePayContactFields,
76+
Promise promise) {
77+
common.configureAcceleratedCheckouts(
78+
storefrontDomain,
79+
storefrontAccessToken,
80+
customerEmail,
81+
customerPhoneNumber,
82+
customerAccessToken,
83+
applePayMerchantIdentifier,
84+
applePayContactFields,
85+
promise);
86+
}
87+
88+
@ReactMethod
89+
public void dismiss() {
90+
common.dismiss();
91+
}
92+
93+
@ReactMethod
94+
public void getConfig(Promise promise) {
95+
common.getConfig(promise);
96+
}
97+
98+
public String getVersion() {
99+
return common.getVersion();
100+
}
101+
102+
@ReactMethod
103+
public void initiateGeolocationRequest(boolean allow) {
104+
common.initiateGeolocationRequest(allow);
105+
}
106+
107+
@ReactMethod
108+
public void invalidateCache() {
109+
common.invalidateCache();
110+
}
111+
112+
@ReactMethod
113+
public void isAcceleratedCheckoutAvailable(Promise promise) {
114+
common.isAcceleratedCheckoutAvailable(promise);
115+
}
116+
117+
@ReactMethod
118+
public void isApplePayAvailable(Promise promise) {
119+
common.isApplePayAvailable(promise);
120+
}
121+
122+
@ReactMethod
123+
public void preload(String checkoutURL) {
124+
common.preload(checkoutURL);
125+
}
126+
127+
@ReactMethod
128+
public void present(String checkoutURL) {
129+
common.present(checkoutURL);
130+
}
131+
132+
@ReactMethod
133+
public void removeListeners(double count) {
134+
common.removeListeners(count);
135+
}
136+
137+
@ReactMethod
138+
public void setConfig(ReadableMap config) {
139+
common.setConfig(config);
140+
ShopifyCheckoutSheetKitModule.checkoutConfig = CheckoutKitModule.checkoutConfig;
141+
}
142+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
MIT License
3+
4+
Copyright 2023 - Present, Shopify Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package com.shopify.reactnative.checkoutsheetkit;
24+
25+
import com.facebook.react.bridge.Promise;
26+
import com.facebook.react.bridge.ReactApplicationContext;
27+
import com.facebook.react.bridge.ReadableArray;
28+
import com.facebook.react.bridge.ReadableMap;
29+
30+
import java.util.Map;
31+
32+
/**
33+
* @note
34+
*
35+
* This is the new architecture module class for the
36+
* ShopifyCheckoutSheetKit module.
37+
* It is used to support applications using React Native with the new
38+
* new architecture.
39+
*/
40+
41+
public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {
42+
private final CheckoutKitModule common;
43+
public static com.shopify.checkoutsheetkit.Configuration checkoutConfig;
44+
45+
public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
46+
super(reactContext);
47+
this.common = new CheckoutKitModule(reactContext);
48+
ShopifyCheckoutSheetKitModule.checkoutConfig = CheckoutKitModule.checkoutConfig;
49+
}
50+
51+
@Override
52+
public Map<String, Object> getConstants() {
53+
return common.getConstants();
54+
}
55+
56+
@Override
57+
public void addListener(String eventName) {
58+
common.addListener(eventName);
59+
}
60+
61+
@Override
62+
public void removeListeners(double count) {
63+
common.removeListeners(count);
64+
}
65+
66+
@Override
67+
public void present(String checkoutURL) {
68+
common.present(checkoutURL);
69+
}
70+
71+
@Override
72+
public void dismiss() {
73+
common.dismiss();
74+
}
75+
76+
@Override
77+
public void preload(String checkoutURL) {
78+
common.preload(checkoutURL);
79+
}
80+
81+
@Override
82+
public void invalidateCache() {
83+
common.invalidateCache();
84+
}
85+
86+
@Override
87+
public void getConfig(Promise promise) {
88+
common.getConfig(promise);
89+
}
90+
91+
@Override
92+
public void setConfig(ReadableMap config) {
93+
common.setConfig(config);
94+
ShopifyCheckoutSheetKitModule.checkoutConfig = CheckoutKitModule.checkoutConfig;
95+
}
96+
97+
@Override
98+
public void isApplePayAvailable(Promise promise) {
99+
common.isApplePayAvailable(promise);
100+
}
101+
102+
@Override
103+
public void isAcceleratedCheckoutAvailable(Promise promise) {
104+
common.isAcceleratedCheckoutAvailable(promise);
105+
}
106+
107+
@Override
108+
public void configureAcceleratedCheckouts(
109+
String storefrontDomain,
110+
String storefrontAccessToken,
111+
String customerEmail,
112+
String customerPhoneNumber,
113+
String customerAccessToken,
114+
String applePayMerchantIdentifier,
115+
ReadableArray applePayContactFields,
116+
Promise promise) {
117+
common.configureAcceleratedCheckouts(
118+
storefrontDomain,
119+
storefrontAccessToken,
120+
customerEmail,
121+
customerPhoneNumber,
122+
customerAccessToken,
123+
applePayMerchantIdentifier,
124+
applePayContactFields,
125+
promise);
126+
}
127+
128+
@Override
129+
public void initiateGeolocationRequest(boolean allow) {
130+
common.initiateGeolocationRequest(allow);
131+
}
132+
133+
@Override
134+
public String getVersion() {
135+
return common.getVersion();
136+
}
137+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
MIT License
3+
4+
Copyright 2023 - Present, Shopify Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package com.shopify.reactnative.checkoutsheetkit;
24+
25+
import com.facebook.react.bridge.Promise;
26+
import com.facebook.react.bridge.ReadableArray;
27+
import com.facebook.react.bridge.ReadableMap;
28+
29+
import java.util.Map;
30+
31+
public interface CheckoutKitDelegate {
32+
void addListener(String eventName);
33+
34+
void configureAcceleratedCheckouts(String domain, String token, String email, String phone, String customerToken,
35+
String applePayMerchantId, ReadableArray contactFields, Promise promise);
36+
37+
void dismiss();
38+
39+
void getConfig(Promise promise);
40+
41+
String getName();
42+
43+
Map<String, Object> getConstants();
44+
45+
String getVersion();
46+
47+
void initiateGeolocationRequest(boolean allow);
48+
49+
void invalidateCache();
50+
51+
void isAcceleratedCheckoutAvailable(Promise promise);
52+
53+
void isApplePayAvailable(Promise promise);
54+
55+
void preload(String checkoutUrl);
56+
57+
void present(String checkoutUrl);
58+
59+
void removeListeners(double count);
60+
61+
void setConfig(ReadableMap config);
62+
}

0 commit comments

Comments
 (0)