Last active
August 11, 2020 19:25
-
-
Save AlixBou/4b4e154a1ecc0bc6b2bba3cd5b707397 to your computer and use it in GitHub Desktop.
How to use turbo module within java code
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
import com.facebook.react.ReactApplication ; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.ReactPackage; | |
import com.facebook.react.TurboReactPackage; | |
import com.facebook.react.bridge.NativeModule; | |
import com.facebook.react.module.model.ReactModuleInfo; | |
import com.facebook.react.module.model.ReactModuleInfoProvider; | |
import com.facebook.react.shell.MainReactPackage; | |
public class MainApplication implements ReactApplication { | |
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { | |
@Override | |
protected String getJSBundleFile() { | |
return CodePush.getJSBundleFile(); | |
} | |
@Override | |
public boolean getUseDeveloperSupport() { | |
return BuildConfig.DEBUG; | |
} | |
@Override | |
protected List<ReactPackage> getPackages() { | |
return Arrays.<ReactPackage>asList( | |
new MainReactPackage(), | |
new TurboReactPackage() { | |
@Override | |
public abstract NativeModule getModule(String name, ReactApplicationContext : reactContext) { | |
switch(name) { | |
case MyCustomPackage.MODULE_NAME : | |
return MyCustomPackage(reactContext); | |
default : | |
throw IllegalArgumentException("Could not find module $name") | |
} | |
} | |
@Override | |
public abstract ReactModuleInfoProvider getReactModuleInfoProvider { | |
return ReactModuleInfoProvider { | |
Map<String, ReactModuleInfo> map = HashMap<String, ReactModuleInfo>() ; | |
map.put(MyCustomPackage.MODULE_NAME, new ReactModuleInfo(MyCustomPackage.MODULE_NAME, "com.mypackagename.MyCustomPackage", false, false, false, false, true)); | |
return map; } ; | |
} | |
} | |
@Override | |
protected String getJSMainModuleName() { | |
return "index"; | |
} | |
}; | |
@Override | |
public ReactNativeHost getReactNativeHost() { | |
return mReactNativeHost; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your code is not working.
It's half transform in Java.