ThinkAndCode
ThinkAndCode

Reputation: 1667

React-Native: Where the index.js file is called from?

App initialisation and SplashScreen rendering executes form Mainactivity.java. Once this native part is over then React-Native comes into the picture. index.js is base file to execute all the React-Native code.

May I know how come control is coming to index.js?

Is there any file which calls index.js explicitly for further React-Native code execution?

Upvotes: 1

Views: 979

Answers (1)

Abd
Abd

Reputation: 568

And since 0.70 react native hermes engine by facebook is responsible to run javascript not v8 by google you are able to see binaries also in react-native module

      java public class MainApplication extends Application implements ReactApplication {
        
          private final ReactNativeHost mReactNativeHost =
              new ReactNativeHost(this) {
                @Override
                public boolean getUseDeveloperSupport() {
                  return BuildConfig.DEBUG;
                }
        
                @Override
                protected List<ReactPackage> getPackages() {
                  @SuppressWarnings("UnnecessaryLocalVariable")
                  List<ReactPackage> packages = new PackageList(this).getPackages();
                  // Packages that cannot be autolinked yet can be added manually here, for example:
                  // packages.add(new MyReactNativePackage());
                  return packages;
                }
        //here
                @Override
                protected String getJSMainModuleName() {
                  return "index";
                }
              };

  @Override
  public void onCreate() {
    super.onCreate();
    // If you opted-in for the New Architecture, we enable the TurboModule system
    ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
    SoLoader.init(this, /* native exopackage */ false);
//-- more specifically  exactly here
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }

and in react native module in node modules react.gradle

*
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

    import org.apache.tools.ant.taskdefs.condition.Os
    import org.gradle.internal.jvm.Jvm
    
    def config = project.hasProperty("react") ? project.react : [:];
    
    def detectEntryFile(config) {
        if (System.getenv('ENTRY_FILE')) {
            return System.getenv('ENTRY_FILE')
        } else if (config.entryFile) {
            return config.entryFile
        } else if ((new File("${projectDir}/../../index.android.js")).exists()) {
            return "index.android.js"
        }
    //here
        return "index.js";
    }

Upvotes: 1

Related Questions