Last active
January 20, 2019 04:36
-
-
Save Salakar/91f0d52e77c984381ae787c2dcb0d685 to your computer and use it in GitHub Desktop.
Example injecting React Native module ReactPackages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.testing; | |
import android.app.Application; | |
import com.facebook.react.ReactApplication; | |
import com.facebook.react.ReactNativeHost; | |
import com.facebook.react.ReactPackage; | |
import com.facebook.react.shell.MainReactPackage; | |
import com.facebook.soloader.SoLoader; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage; | |
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() { | |
ReactPackage analytics = null; | |
String className = "io.invertase.firebase.analytics.ReactNativeFirebaseAnalyticsPackage"; | |
try { | |
analytics = (ReactPackage) Class.forName(className).getConstructors()[0].newInstance(); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} catch (InstantiationException e) { | |
e.printStackTrace(); | |
} catch (InvocationTargetException e) { | |
e.printStackTrace(); | |
} | |
List<ReactPackage> packages = new ArrayList<>(); | |
packages.add(new MainReactPackage()); | |
packages.add(new ReactNativeFirebaseAppPackage()); | |
if (analytics != null) { | |
packages.add(analytics); | |
} | |
return packages; | |
} | |
}; | |
@Override | |
public ReactNativeHost getReactNativeHost() { | |
return mReactNativeHost; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
SoLoader.init(this, /* native exopackage */ false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment