Created
December 18, 2020 09:09
-
-
Save tomoima525/ab4252b9e3c72b0db1ae9fc25e00bd9c to your computer and use it in GitHub Desktop.
Replace ReactPackage with TurboReactPackage
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
// ReactModule annotation is required to create reactModuleInfoMap | |
@ReactModule(name = "CustomBackground") | |
class CustomBackgroundNativeModule(context: ReactApplicationContext): ReactContextBaseJavaModule(context) { | |
override fun getName(): String = "CustomBackground" | |
@ReactMethod | |
fun hide() {} | |
@ReactMethod | |
fun show() {} | |
} |
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
public class CustomTurboPackage extends TurboReactPackage { | |
@Override | |
public NativeModule getModule(String name, ReactApplicationContext reactContext) { | |
// name should be same as how it gets called from JS side | |
switch (name) { | |
case "CustomBackground": | |
return new CustomBackgroundNativeModule(reactContext); | |
case "CustomMessage": | |
return new CustomMessageModule(reactContext); | |
case "CustomLocalPushAndroid": | |
return new CustomLocalNotification(reactContext); | |
case "RNAnalytics": | |
return new RNAnalyticsModule(reactContext); | |
case "RNReactNativeHapticFeedback": | |
return new RNReactNativeHapticFeedbackModule(reactContext); | |
default: | |
return null; | |
} | |
} | |
@Override | |
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | |
List<ViewManager> viewManagers = new ArrayList<>(); | |
viewManagers.add(new CustomBackgroundViewManager()); | |
viewManagers.add(new ReactVideoViewManager()); | |
return viewManagers; | |
} | |
@Override | |
public ReactModuleInfoProvider getReactModuleInfoProvider() { | |
Class<? extends NativeModule>[] moduleList = | |
new Class[] { | |
CustomBackgroundNativeModule.class, | |
CustomMessageModule.class, | |
CustomLocalNotification.class, | |
}; | |
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>(); | |
for (Class<? extends NativeModule> moduleClass : moduleList) { | |
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class); | |
reactModuleInfoMap.put( | |
reactModule.name(), | |
new ReactModuleInfo( | |
reactModule.name(), | |
moduleClass.getName(), | |
reactModule.canOverrideExistingModule(), | |
reactModule.needsEagerInit(), | |
reactModule.hasConstants(), | |
reactModule.isCxxModule(), | |
false)); | |
} | |
// Third Party libraries can not have @ReactModule annotation | |
reactModuleInfoMap.put( | |
"RNAnalytics", | |
new ReactModuleInfo("RNAnalytics", "RNAnalytics", false, false, false,false, false) | |
); | |
reactModuleInfoMap.put( | |
"RNReactNativeHapticFeedback", | |
new ReactModuleInfo("RNReactNativeHapticFeedback", "RNReactNativeHapticFeedback", false, false, false,false, false) | |
); | |
return new ReactModuleInfoProvider() { | |
@Override | |
public Map<String, ReactModuleInfo> getReactModuleInfos() { | |
return reactModuleInfoMap; | |
} | |
}; | |
} | |
} |
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
class MainApplication { | |
@Override | |
public List<ReactPackage> getPackages() { | |
ArrayList<ReactPackage> packages = new PackageList(this).getPackages(); | |
// Add packages here that cannot yet be autolinked. | |
packages.add(new CustomTurboPackage()); | |
// packages.add(new CustomBackgroundPackage()); | |
// packages.add(new CustomMessagePackage()); | |
// packages.add(new CustomLocalNotificationPackage()); | |
// packages.add(new ReactVideoPackage()); | |
// packages.add(new RNAnalyticsPackage()); | |
// packages.add(new RNNotificationsPackage(MainApplication.this)); | |
// packages.add(new RNReactNativeHapticFeedbackPackage()); | |
return packages; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment