Skip to content

Commit 42eabd7

Browse files
committed
fix: Ensure compatibility with new React Native version
1 parent 1c5ef8d commit 42eabd7

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

android/src/main/java/in/juspay/hypersdkreact/HyperSdkReactModule.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ public View getMerchantView(ViewGroup viewGroup, MerchantViewType merchantViewTy
370370
}
371371
}
372372

373+
private ReactInstanceManager getReactInstanceManagerFromHost(Object reactHost) {
374+
if (reactHost == null) {
375+
return null;
376+
}
377+
try {
378+
Method getReactInstanceManagerMethod = reactHost.getClass().getMethod("getReactInstanceManager");
379+
return (ReactInstanceManager) getReactInstanceManagerMethod.invoke(reactHost);
380+
} catch (Exception e) {
381+
return null;
382+
}
383+
}
384+
373385
private void createHyperService(@Nullable String tenantId, @Nullable String clientId) {
374386
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
375387
if (activity == null) {
@@ -381,11 +393,22 @@ private void createHyperService(@Nullable String tenantId, @Nullable String clie
381393
"activity is null");
382394
return;
383395
}
384-
Application app = activity.getApplication();
385-
if (app instanceof ReactApplication) {
386-
this.app = ((ReactApplication) app);
387-
reactInstanceManager = ((ReactApplication) app).getReactNativeHost().getReactInstanceManager();
396+
Application application = activity.getApplication();
397+
if (application instanceof ReactApplication) {
398+
this.app = ((ReactApplication) application);
399+
if (newArchEnabled) {
400+
try {
401+
Method getReactHostMethod = app.getClass().getMethod("getReactHost");
402+
Object reactHost = getReactHostMethod.invoke(app);
403+
reactInstanceManager = getReactInstanceManagerFromHost(reactHost);
404+
} catch (Exception e) {
405+
reactInstanceManager = app.getReactNativeHost().getReactInstanceManager();
406+
}
407+
} else {
408+
reactInstanceManager = app.getReactNativeHost().getReactInstanceManager();
409+
}
388410
}
411+
389412
if (tenantId != null && clientId != null) {
390413
hyperServices = new HyperServices(activity, tenantId, clientId);
391414
} else {

0 commit comments

Comments
 (0)