Skip to content

Commit 46ef472

Browse files
committed
Codegen, upgrade gesture handler
1 parent 2a33a92 commit 46ef472

File tree

8 files changed

+165
-95
lines changed

8 files changed

+165
-95
lines changed

modules/@shopify/checkout-sheet-kit/android/src/main/java/com/shopify/reactnative/checkoutsheetkit/ShopifyCheckoutSheetKitModule.java

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -30,69 +30,18 @@ of this software and associated documentation files (the "Software"), to deal
3030
import com.facebook.react.bridge.Promise;
3131
import com.facebook.react.bridge.ReactApplicationContext;
3232
import com.facebook.react.bridge.ReactContextBaseJavaModule;
33-
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
34-
#if RCT_NEW_ARCH_ENABLED
35-
import com.facebook.react.bridge.ReactApplicationContext;
33+
import com.shopify.reactnative.checkoutsheetkit.NativeShopifyCheckoutSheetKitSpec;
3634
import com.facebook.react.bridge.ReactMethod;
37-
import com.facebook.react.bridge.Promise;
38-
import com.facebook.react.module.annotations.ReactModule;
3935
import com.facebook.react.bridge.ReadableMap;
40-
import com.facebook.react.bridge.WritableNativeMap;
41-
import com.facebook.react.bridge.UiThreadUtil;
4236
import com.facebook.react.bridge.ReadableArray;
43-
import com.facebook.react.bridge.ReactNoCrashSoftException;
44-
import com.facebook.react.module.annotations.ReactModuleList;
45-
import com.facebook.react.bridge.NativeModule;
46-
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
47-
import com.facebook.react.fabric.events.EventDispatcher;
48-
import com.facebook.react.uimanager.events.EventDispatcherImpl;
49-
import com.facebook.react.codegen.module.JavaModuleWrapper;
50-
import com.facebook.react.bridge.ReactMarker;
51-
import com.facebook.react.modules.core.DeviceEventManagerModule;
52-
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
53-
import com.facebook.react.bridge.NoSuchKeyException;
54-
import com.facebook.react.module.model.ReactModuleInfo;
55-
import com.facebook.react.module.model.ReactModuleInfoProvider;
56-
import com.facebook.jni.HybridData;
57-
import com.facebook.proguard.annotations.DoNotStrip;
58-
import com.facebook.react.bridge.JavaScriptContextHolder;
59-
import com.facebook.proguard.annotations.DoNotStripAny;
60-
import com.facebook.react.bridge.queue.MessageQueueThread;
61-
import com.facebook.react.bridge.Dynamic;
62-
import com.facebook.react.bridge.Arguments;
63-
import com.facebook.react.common.MapBuilder;
64-
import com.facebook.react.codegen.ReactNativeFeatureFlags;
65-
import com.facebook.react.bridge.WritableMap;
66-
import com.facebook.react.bridge.ReactSoftExceptionLogger;
67-
import com.facebook.react.bridge.Callback;
68-
import com.facebook.react.modules.core.DeviceEventManagerModule;
69-
import com.facebook.react.bridge.ActivityEventListener;
70-
import com.facebook.react.bridge.BaseJavaModule;
71-
import com.facebook.react.bridge.LifecycleEventListener;
72-
// Generated spec
73-
import com.facebook.react.bridge.ReactContext;
74-
import com.facebook.react.module.annotations.ReactModule;
75-
import com.facebook.react.module.annotations.ReactModuleList;
76-
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
77-
import com.facebook.react.bridge.WritableMap;
78-
import com.facebook.react.bridge.arguments;
79-
import com.facebook.react.module.model.ReactModuleInfo;
80-
import com.facebook.react.module.model.ReactModuleInfoProvider;
81-
import com.facebook.react.module.annotations.ReactModule;
82-
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
83-
#endif
84-
import com.facebook.react.bridge.ReactMethod;
85-
import com.facebook.react.bridge.ReadableMap;
8637
import com.facebook.react.bridge.WritableNativeMap;
8738
import com.shopify.checkoutsheetkit.*;
8839

8940
import java.util.HashMap;
9041
import java.util.Map;
9142
import java.util.Objects;
9243

93-
public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule implements TurboModule {
94-
private static final String MODULE_NAME = "ShopifyCheckoutSheetKit";
95-
44+
public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {
9645
public static Configuration checkoutConfig = new Configuration();
9746

9847
private final ReactApplicationContext reactContext;
@@ -112,12 +61,6 @@ public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
11261
});
11362
}
11463

115-
@NonNull
116-
@Override
117-
public String getName() {
118-
return MODULE_NAME;
119-
}
120-
12164
@Override
12265
public Map<String, Object> getConstants() {
12366
final Map<String, Object> constants = new HashMap<>();
@@ -131,11 +74,12 @@ public void addListener(String eventName) {
13174
}
13275

13376
@ReactMethod
134-
public void removeListeners(Integer count) {
77+
public void removeListeners(double count) {
13578
// No-op but required for RN to register module
13679
}
13780

13881
@ReactMethod
82+
@Override
13983
public void present(String checkoutURL) {
14084
Activity currentActivity = getCurrentActivity();
14185
if (currentActivity instanceof ComponentActivity) {
@@ -148,6 +92,7 @@ public void present(String checkoutURL) {
14892
}
14993

15094
@ReactMethod
95+
@Override
15196
public void dismiss() {
15297
if (checkoutSheet != null) {
15398
checkoutSheet.dismiss();
@@ -156,6 +101,7 @@ public void dismiss() {
156101
}
157102

158103
@ReactMethod
104+
@Override
159105
public void preload(String checkoutURL) {
160106
Activity currentActivity = getCurrentActivity();
161107

@@ -165,11 +111,13 @@ public void preload(String checkoutURL) {
165111
}
166112

167113
@ReactMethod
114+
@Override
168115
public void invalidateCache() {
169116
ShopifyCheckoutSheetKit.invalidate();
170117
}
171118

172119
@ReactMethod
120+
@Override
173121
public void getConfig(Promise promise) {
174122
WritableNativeMap resultConfig = new WritableNativeMap();
175123

@@ -180,6 +128,7 @@ public void getConfig(Promise promise) {
180128
}
181129

182130
@ReactMethod
131+
@Override
183132
public void setConfig(ReadableMap config) {
184133
Context context = getReactApplicationContext();
185134

@@ -213,13 +162,41 @@ public void setConfig(ReadableMap config) {
213162
});
214163
}
215164

165+
@Override
166+
public void isApplePayAvailable(Promise promise) {
167+
promise.resolve(false);
168+
}
169+
170+
@Override
171+
public void isAcceleratedCheckoutAvailable(Promise promise) {
172+
promise.resolve(false);
173+
}
174+
175+
@Override
176+
public void configureAcceleratedCheckouts(
177+
String storefrontDomain,
178+
String storefrontAccessToken,
179+
String customerEmail,
180+
String customerPhoneNumber,
181+
String customerAccessToken,
182+
String applePayMerchantIdentifier,
183+
ReadableArray applePayContactFields,
184+
Promise promise) {
185+
promise.resolve(false);
186+
}
187+
216188
@ReactMethod
217-
public void initiateGeolocationRequest(Boolean allow) {
189+
public void initiateGeolocationRequest(boolean allow) {
218190
if (checkoutEventProcessor != null) {
219191
checkoutEventProcessor.invokeGeolocationCallback(allow);
220192
}
221193
}
222194

195+
@Override
196+
public String getVersion() {
197+
return ShopifyCheckoutSheetKit.version;
198+
}
199+
223200
// Private
224201

225202
private ColorScheme getColorScheme(String colorScheme) {
@@ -308,10 +285,10 @@ private Colors createColorsFromConfig(ReadableMap config) {
308285
headerBackground,
309286
headerFont,
310287
progressIndicator,
311-
// Parameter allows passing a custom drawable, we'll just support custom color for now
288+
// Parameter allows passing a custom drawable, we'll just support custom color
289+
// for now
312290
null,
313-
closeButtonColor
314-
);
291+
closeButtonColor);
315292
}
316293

317294
return null;

modules/@shopify/checkout-sheet-kit/src/components/AcceleratedCheckoutButtons.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ interface NativeAcceleratedCheckoutButtonsProps {
163163
onSizeChange?: (event: {nativeEvent: {height: number}}) => void;
164164
}
165165

166-
const NativeAcceleratedCheckoutButtons =
166+
const LegacyAcceleratedCheckoutButtons =
167167
requireNativeComponent<NativeAcceleratedCheckoutButtonsProps>(
168168
'RCTAcceleratedCheckoutButtons',
169169
);
@@ -304,7 +304,8 @@ export const AcceleratedCheckoutButtons: React.FC<
304304
}
305305
}
306306

307-
const NativeComponent = NativeAcceleratedCheckoutButtons;
307+
// Use legacy view manager; RN 0.80 interop bridges it under Fabric when enabled
308+
const NativeComponent = LegacyAcceleratedCheckoutButtons;
308309

309310
return (
310311
<NativeComponent
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
24+
import type {TurboModule} from 'react-native';
25+
import {TurboModuleRegistry} from 'react-native';
26+
27+
export type AndroidColorOverrides = {
28+
backgroundColor?: string;
29+
headerBackgroundColor?: string;
30+
headerTextColor?: string;
31+
progressIndicator?: string;
32+
closeButtonColor?: string | null;
33+
};
34+
35+
export type AndroidAutomaticOverrides = {
36+
light?: AndroidColorOverrides | null;
37+
dark?: AndroidColorOverrides | null;
38+
};
39+
40+
export type IosColorOverrides = {
41+
tintColor?: string;
42+
backgroundColor?: string;
43+
closeButtonColor?: string;
44+
};
45+
46+
export type ConfigurationInput = {
47+
preloading?: boolean;
48+
title?: string;
49+
colorScheme?: 'automatic' | 'light' | 'dark' | 'web_default';
50+
colors?: {
51+
ios?: IosColorOverrides;
52+
// Superset shape that covers both direct overrides and automatic(light/dark)
53+
android?: AndroidColorOverrides & AndroidAutomaticOverrides;
54+
};
55+
};
56+
57+
export type ConfigurationOutput = {
58+
title?: string | null;
59+
preloading: boolean;
60+
colorScheme: 'automatic' | 'light' | 'dark' | 'web_default';
61+
tintColor?: string | null;
62+
backgroundColor?: string | null;
63+
closeButtonColor?: string | null;
64+
};
65+
66+
export interface Spec extends TurboModule {
67+
getVersion(): string;
68+
dismiss(): void;
69+
invalidateCache(): void;
70+
preload(checkoutUrl: string): void;
71+
present(checkoutUrl: string): void;
72+
getConfig(): Promise<ConfigurationOutput>;
73+
setConfig(configuration: ConfigurationInput): void;
74+
configureAcceleratedCheckouts(
75+
storefrontDomain: string,
76+
storefrontAccessToken: string,
77+
customerEmail: string | null,
78+
customerPhoneNumber: string | null,
79+
customerAccessToken: string | null,
80+
applePayMerchantIdentifier: string | null,
81+
applePayContactFields: ReadonlyArray<'email' | 'phone'>,
82+
): Promise<boolean>;
83+
isAcceleratedCheckoutAvailable(): Promise<boolean>;
84+
isApplePayAvailable(): Promise<boolean>;
85+
initiateGeolocationRequest(allow: boolean): void;
86+
addListener(eventName: string): void;
87+
removeListeners(count: number): void;
88+
}
89+
90+
export default TurboModuleRegistry.getEnforcing<Spec>(
91+
'ShopifyCheckoutSheetKit',
92+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"react": "19.1.0",
4949
"react-native": "0.80.2",
5050
"react-native-dotenv": "^3.4.9",
51-
"react-native-gesture-handler": "2.26.0",
51+
"react-native-gesture-handler": "2.28.0",
5252
"react-native-gradle-plugin": "^0.71.19",
5353
"react-test-renderer": "19.1.0",
5454
"ts-jest": "^29.4.1",

sample/Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ GEM
8181
mutex_m
8282
i18n (1.14.7)
8383
concurrent-ruby (~> 1.0)
84-
json (2.13.2)
84+
json (2.15.0)
8585
logger (1.7.0)
8686
minitest (5.25.5)
8787
molinillo (0.8.0)
@@ -91,7 +91,7 @@ GEM
9191
netrc (0.11.0)
9292
nkf (0.2.0)
9393
public_suffix (4.0.7)
94-
rexml (3.4.2)
94+
rexml (3.4.4)
9595
ruby-macho (2.5.1)
9696
securerandom (0.4.1)
9797
typhoeus (1.5.0)

0 commit comments

Comments
 (0)