Last active
March 31, 2020 10:38
-
-
Save mczernek/ae776a50159f4b021309924f2b150436 to your computer and use it in GitHub Desktop.
MainApplication.java changes to support unimodules for RN>=0.60
This file contains 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.doingmything; | |
// "com.doingmything" should be your app package name | |
import com.doingmything.generated.BasePackageList; | |
import android.app.Application; | |
import android.util.Log; | |
import org.unimodules.adapters.react.ModuleRegistryAdapter; | |
import org.unimodules.adapters.react.ReactModuleRegistryProvider; | |
import org.unimodules.core.interfaces.SingletonModule; | |
import com.facebook.react.PackageList; | |
import com.facebook.hermes.reactexecutor.HermesExecutorFactory; | |
import com.facebook.react.bridge.JavaScriptExecutorFactory; | |
import com.facebook.react.ReactApplication; | |
import com.facebook.react.ReactNativeHost; | |
import com.facebook.react.ReactPackage; | |
import com.facebook.soloader.SoLoader; | |
import java.util.Arrays; | |
import java.util.List; | |
public class MainApplication extends Application implements ReactApplication { | |
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList()); | |
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()); | |
// Add unimodules | |
List<ReactPackage> unimodules = Arrays.<ReactPackage>asList( | |
new ModuleRegistryAdapter(mModuleRegistryProvider) | |
); | |
packages.addAll(unimodules); | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are right. I've linked incorrect gist, which will be wrking once we publish next version of
react-native-unimodules
. Here's the correct one:https://gist.github.com/mczernek/9de9e184abc430e9e3508d26738c8a14/revisions#diff-a2e7ff8a82f1c4be06f8b8163f2afefa