Advertisement
KingOfWesteros

MainActivity.java

Oct 1st, 2022 (edited)
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.42 KB | Fixit | 0 0
  1. package com.myapp;
  2.  
  3. import android.app.Application;
  4. import android.content.Context;
  5. import android.content.res.Configuration;
  6. import androidx.annotation.NonNull;
  7.  
  8. import com.facebook.react.PackageList;
  9. import com.facebook.react.ReactApplication;
  10. import com.facebook.react.ReactInstanceManager;
  11. import com.facebook.react.ReactNativeHost;
  12. import com.facebook.react.ReactPackage;
  13. import com.facebook.react.config.ReactFeatureFlags;
  14. import com.facebook.soloader.SoLoader;
  15. import com.myapp.newarchitecture.MainApplicationReactNativeHost;
  16.  
  17. import expo.modules.ApplicationLifecycleDispatcher;
  18. import expo.modules.ReactNativeHostWrapper;
  19.  
  20. import java.lang.reflect.InvocationTargetException;
  21. import java.util.List;
  22.  
  23. import androidx.annotation.Nullable; // <--- for JitsiMeetView
  24.  
  25. public class MainApplication extends Application implements ReactApplication {
  26.   private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
  27.     this,
  28.     new ReactNativeHost(this) {
  29.     @Override
  30.     public boolean getUseDeveloperSupport() {
  31.       return BuildConfig.DEBUG;
  32.     }
  33.  
  34.     @Override
  35.     protected List<ReactPackage> getPackages() {
  36.       @SuppressWarnings("UnnecessaryLocalVariable")
  37.       List<ReactPackage> packages = new PackageList(this).getPackages();
  38.       return packages;
  39.     }
  40.  
  41.     @Override
  42.     protected String getJSMainModuleName() {
  43.       return "index";
  44.     }
  45.  
  46.     @Override
  47.     protected @Nullable String getBundleAssetName() {
  48.       return "app.bundle";
  49.   });
  50.  
  51.   private final ReactNativeHost mNewArchitectureNativeHost =
  52.       new ReactNativeHostWrapper(this, new MainApplicationReactNativeHost(this));
  53.  
  54.   @Override
  55.   public ReactNativeHost getReactNativeHost() {
  56.     if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
  57.       return mNewArchitectureNativeHost;
  58.     } else {
  59.       return mReactNativeHost;
  60.     }
  61.   }
  62.  
  63.   @Override
  64.   public void onCreate() {
  65.     super.onCreate();
  66.     // If you opted-in for the New Architecture, we enable the TurboModule system
  67.     ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
  68.     SoLoader.init(this, /* native exopackage */ false);
  69.  
  70.     initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  71.     ApplicationLifecycleDispatcher.onApplicationCreate(this);
  72.   }
  73.  
  74.   @Override
  75.   public void onConfigurationChanged(@NonNull Configuration newConfig) {
  76.     super.onConfigurationChanged(newConfig);
  77.     ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
  78.   }
  79.  
  80.   implementation(project(':react-native-jitsi-meet')) {   // <--- for JitsiMeetView
  81.       exclude group: 'com.facebook.react',module:'react-native-locale-detector'
  82.       exclude group: 'com.facebook.react',module:'react-native-vector-icons'
  83.       // Un-comment below if using hermes
  84.       exclude group: 'com.facebook',module:'hermes'
  85.       // Un-comment any packages below that you have added to your project to prevent `duplicate_classes` errors
  86.       //exclude group: 'com.facebook.react',module:'react-native-community-async-storage'
  87.       //exclude group: 'com.facebook.react',module:'react-native-community_netinfo'
  88.       //exclude group: 'com.facebook.react',module:'react-native-svg'
  89.       //exclude group: 'com.facebook.react',module:'react-native-fetch-blob'
  90.       //exclude group: 'com.facebook.react',module:'react-native-webview'
  91.       //exclude group: 'com.facebook.react',module:'react-native-linear-gradient'
  92.       //exclude group: 'com.facebook.react',module:'react-native-sound'
  93.     }
  94.   /**
  95.    * Loads Flipper in React Native templates. Call this in the onCreate method with something like
  96.    * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  97.    *
  98.    * @param context
  99.    * @param reactInstanceManager
  100.    */
  101.   private static void initializeFlipper(
  102.       Context context, ReactInstanceManager reactInstanceManager) {
  103.     if (BuildConfig.DEBUG) {
  104.       try {
  105.         Class<?> aClass = Class.forName("com.myapp.ReactNativeFlipper");
  106.         aClass
  107.             .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
  108.             .invoke(null, context, reactInstanceManager);
  109.       } catch (ClassNotFoundException e) {
  110.         e.printStackTrace();
  111.       } catch (NoSuchMethodException e) {
  112.         e.printStackTrace();
  113.       } catch (IllegalAccessException e) {
  114.         e.printStackTrace();
  115.       } catch (InvocationTargetException e) {
  116.         e.printStackTrace();
  117.       }
  118.     }
  119.   }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement