11package com .timelessco .adaptuireactnative ;
22
33import android .app .Application ;
4- import android .content .Context ;
54import android .content .res .Configuration ;
65import androidx .annotation .NonNull ;
76
87import com .facebook .react .PackageList ;
98import com .facebook .react .ReactApplication ;
10- import com .facebook .react .ReactInstanceManager ;
119import com .facebook .react .ReactNativeHost ;
1210import com .facebook .react .ReactPackage ;
13- import com .facebook .react .config .ReactFeatureFlags ;
11+ import com .facebook .react .defaults .DefaultNewArchitectureEntryPoint ;
12+ import com .facebook .react .defaults .DefaultReactNativeHost ;
1413import com .facebook .soloader .SoLoader ;
15- import com .timelessco .adaptuireactnative .newarchitecture .MainApplicationReactNativeHost ;
1614
1715import expo .modules .ApplicationLifecycleDispatcher ;
1816import expo .modules .ReactNativeHostWrapper ;
1917
20- import java .lang .reflect .InvocationTargetException ;
2118import java .util .List ;
2219
2320public class MainApplication extends Application implements ReactApplication {
24- private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper (
25- this ,
26- new ReactNativeHost (this ) {
27- @ Override
28- public boolean getUseDeveloperSupport () {
29- return BuildConfig .DEBUG ;
30- }
3121
32- @ Override
33- protected List <ReactPackage > getPackages () {
34- @ SuppressWarnings ("UnnecessaryLocalVariable" )
35- List <ReactPackage > packages = new PackageList (this ).getPackages ();
36- // Packages that cannot be autolinked yet can be added manually here, for example:
37- // packages.add(new MyReactNativePackage());
38- return packages ;
39- }
22+ private final ReactNativeHost mReactNativeHost =
23+ new ReactNativeHostWrapper (this , new DefaultReactNativeHost (this ) {
24+ @ Override
25+ public boolean getUseDeveloperSupport () {
26+ return BuildConfig .DEBUG ;
27+ }
4028
41- @ Override
42- protected String getJSMainModuleName () {
43- return "index" ;
44- }
45- });
29+ @ Override
30+ protected List <ReactPackage > getPackages () {
31+ @ SuppressWarnings ("UnnecessaryLocalVariable" )
32+ List <ReactPackage > packages = new PackageList (this ).getPackages ();
33+ // Packages that cannot be autolinked yet can be added manually here, for example:
34+ // packages.add(new MyReactNativePackage());
35+ return packages ;
36+ }
4637
47- private final ReactNativeHost mNewArchitectureNativeHost =
48- new ReactNativeHostWrapper (this , new MainApplicationReactNativeHost (this ));
38+ @ Override
39+ protected String getJSMainModuleName () {
40+ return "index" ;
41+ }
42+
43+ @ Override
44+ protected boolean isNewArchEnabled () {
45+ return BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ;
46+ }
47+
48+ @ Override
49+ protected Boolean isHermesEnabled () {
50+ return BuildConfig .IS_HERMES_ENABLED ;
51+ }
52+ });
4953
5054 @ Override
5155 public ReactNativeHost getReactNativeHost () {
52- if (BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
53- return mNewArchitectureNativeHost ;
54- } else {
55- return mReactNativeHost ;
56- }
56+ return mReactNativeHost ;
5757 }
5858
5959 @ Override
6060 public void onCreate () {
6161 super .onCreate ();
62- // If you opted-in for the New Architecture, we enable the TurboModule system
63- ReactFeatureFlags .useTurboModules = BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ;
6462 SoLoader .init (this , /* native exopackage */ false );
65-
66- initializeFlipper (this , getReactNativeHost ().getReactInstanceManager ());
63+ if (BuildConfig .IS_NEW_ARCHITECTURE_ENABLED ) {
64+ // If you opted-in for the New Architecture, we load the native entry point for this app.
65+ DefaultNewArchitectureEntryPoint .load ();
66+ }
67+ ReactNativeFlipper .initializeFlipper (this , getReactNativeHost ().getReactInstanceManager ());
6768 ApplicationLifecycleDispatcher .onApplicationCreate (this );
6869 }
6970
@@ -72,35 +73,4 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
7273 super .onConfigurationChanged (newConfig );
7374 ApplicationLifecycleDispatcher .onConfigurationChanged (this , newConfig );
7475 }
75-
76- /**
77- * Loads Flipper in React Native templates. Call this in the onCreate method with something like
78- * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
79- *
80- * @param context
81- * @param reactInstanceManager
82- */
83- private static void initializeFlipper (
84- Context context , ReactInstanceManager reactInstanceManager ) {
85- if (BuildConfig .DEBUG ) {
86- try {
87- /*
88- We use reflection here to pick up the class that initializes Flipper,
89- since Flipper library is not available in release mode
90- */
91- Class <?> aClass = Class .forName ("com.timelessco.adaptuireactnative.ReactNativeFlipper" );
92- aClass
93- .getMethod ("initializeFlipper" , Context .class , ReactInstanceManager .class )
94- .invoke (null , context , reactInstanceManager );
95- } catch (ClassNotFoundException e ) {
96- e .printStackTrace ();
97- } catch (NoSuchMethodException e ) {
98- e .printStackTrace ();
99- } catch (IllegalAccessException e ) {
100- e .printStackTrace ();
101- } catch (InvocationTargetException e ) {
102- e .printStackTrace ();
103- }
104- }
105- }
10676}
0 commit comments