MainApplication.java 2.76 KB
Newer Older
1
package com.dcv.invest;
Giang Tran committed
2 3 4 5 6

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
Giang Tran committed
7
import com.reactnativecommunity.netinfo.NetInfoPackage;
Giang Tran committed
8 9 10 11 12 13
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
14

Giang Tran committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

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());
Giang Tran committed
31
      // packages.add(new RNBootSplashPackage());
Nguyễn Thị Thúy committed
32
          packages.add(new InAppUpdatePackage());
Giang Tran committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
Giang Tran committed
52
    // RNBootSplash.init(R.drawable.bootsplash, MainActivity.this);
Giang Tran committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method with something like
   * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
70
        Class<?> aClass = Class.forName("com.dcv.invest.ReactNativeFlipper");
Giang Tran committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}