2222import androidx .fragment .app .FragmentActivity ;
2323
2424import com .facebook .react .ReactApplication ;
25+ import com .facebook .react .ReactHost ;
2526import com .facebook .react .ReactInstanceManager ;
2627import com .facebook .react .ReactRootView ;
2728import com .facebook .react .bridge .ActivityEventListener ;
@@ -89,6 +90,8 @@ public class HyperSdkReactModule extends ReactContextBaseJavaModule implements A
8990
9091 private boolean wasProcessWithActivity = false ;
9192
93+ private boolean useNewApprochForMerchantView = false ;
94+
9295 private Set <String > registeredComponents = new HashSet <>();
9396
9497 @ NonNull
@@ -97,6 +100,7 @@ public class HyperSdkReactModule extends ReactContextBaseJavaModule implements A
97100 HyperSdkReactModule (ReactApplicationContext reactContext ) {
98101 super (reactContext );
99102 this .context = reactContext ;
103+ useNewApprochForMerchantView = setUseNewApprochForMerchantView ();
100104 reactContext .addActivityEventListener (this );
101105 }
102106
@@ -318,20 +322,47 @@ public View createReactSurfaceView(String viewName) {
318322 }
319323
320324 private View createMerchantView (String viewName ) {
321- if (newArchEnabled ) {
322- return createReactSurfaceView (viewName );
323- } else {
325+
326+ if (!useNewApprochForMerchantView ) {
327+ if (newArchEnabled ) {
328+ return createReactSurfaceView (viewName );
329+ }
324330 ReactRootView reactRootView = new ReactRootView (activity );
325331 reactRootView .startReactApplication (reactInstanceManager , viewName );
326332 return reactRootView ;
327333 }
334+ try {
335+ ReactHost reactHost = ((ReactApplication ) activity .getApplication ()).getReactHost ();
336+ if (reactHost != null ) {
337+ Object surface = reactHost .createSurface (
338+ activity ,
339+ viewName ,
340+ null
341+ );
342+ surface .getClass ().getMethod ("start" ).invoke (surface );
343+
344+ return (View ) surface .getClass ().getMethod ("getView" ).invoke (surface );
345+ }
346+ return null ;
347+ } catch (Exception e ) {
348+ SdkTracker .trackAndLogBootException (
349+ NAME ,
350+ LogConstants .CATEGORY_LIFECYCLE ,
351+ LogConstants .SUBCATEGORY_HYPER_SDK ,
352+ LogConstants .SDK_TRACKER_LABEL ,
353+ "Exception in createMerchantView" ,
354+ e
355+ );
356+ return null ;
357+ }
328358 }
329359
360+
330361 @ Nullable
331362 @ Override
332363 public View getMerchantView (ViewGroup viewGroup , MerchantViewType merchantViewType ) {
333364 Activity activity = (Activity ) getCurrentActivity ();
334- if (reactInstanceManager == null || activity == null ) {
365+ if (! useNewApprochForMerchantView && reactInstanceManager == null || activity == null ) {
335366 return super .getMerchantView (viewGroup , merchantViewType );
336367 } else {
337368 View merchantView = null ;
@@ -370,6 +401,17 @@ public View getMerchantView(ViewGroup viewGroup, MerchantViewType merchantViewTy
370401 }
371402 }
372403
404+ private Boolean setUseNewApprochForMerchantView () {
405+ String version = BuildConfig .REACT_NATIVE_VERSION ;
406+ String [] parts = version .split ("\\ ." );
407+ if (parts .length > 1 ) {
408+ int major = Integer .parseInt (parts [0 ]);
409+ int minor = Integer .parseInt (parts [1 ]);
410+ return major > 0 || (major == 0 && minor >= 82 );
411+ }
412+ return false ;
413+ }
414+
373415 private void createHyperService (@ Nullable String tenantId , @ Nullable String clientId ) {
374416 FragmentActivity activity = (FragmentActivity ) getCurrentActivity ();
375417 if (activity == null ) {
@@ -384,7 +426,12 @@ private void createHyperService(@Nullable String tenantId, @Nullable String clie
384426 Application app = activity .getApplication ();
385427 if (app instanceof ReactApplication ) {
386428 this .app = ((ReactApplication ) app );
387- reactInstanceManager = ((ReactApplication ) app ).getReactNativeHost ().getReactInstanceManager ();
429+ if (!useNewApprochForMerchantView ) {
430+ reactInstanceManager = ((ReactApplication ) app ).getReactNativeHost ().getReactInstanceManager ();
431+ }
432+ else {
433+ reactInstanceManager = null ;
434+ }
388435 }
389436 if (tenantId != null && clientId != null ) {
390437 hyperServices = new HyperServices (activity , tenantId , clientId );
0 commit comments