diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDateTimePickerPackage.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDateTimePickerPackage.java index ceafa6ba..e688c952 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDateTimePickerPackage.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDateTimePickerPackage.java @@ -1,58 +1,80 @@ package com.reactcommunity.rndatetimepicker; - import androidx.annotation.Nullable; import com.facebook.react.TurboReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.module.annotations.ReactModule; +import com.facebook.react.module.annotations.ReactModuleList; import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.turbomodule.core.interfaces.TurboModule; +import com.facebook.react.uimanager.ViewManager; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; +@ReactModuleList( + nativeModules = { + DatePickerModule.class, + TimePickerModule.class, + } +) public class RNDateTimePickerPackage extends TurboReactPackage { + + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Arrays.asList( + new DatePickerModule(reactContext), + new TimePickerModule(reactContext) + ); + } + @Nullable @Override public NativeModule getModule(String name, ReactApplicationContext reactContext) { - if (name.equals(DatePickerModule.NAME)) { - return new DatePickerModule(reactContext); - } else if (name.equals(TimePickerModule.NAME)) { - return new TimePickerModule(reactContext); - } else { - return null; + switch (name) { + case DatePickerModule.NAME: + return new DatePickerModule(reactContext); + case TimePickerModule.NAME: + return new TimePickerModule(reactContext); + default: + return null; } } @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { - return () -> { - boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - final Map moduleInfos = new HashMap<>(); - moduleInfos.put( - DatePickerModule.NAME, - new ReactModuleInfo( - DatePickerModule.NAME, - DatePickerModule.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - false, // hasConstants - false, // isCxxModule - isTurboModule // isTurboModule - )); - moduleInfos.put( - TimePickerModule.NAME, - new ReactModuleInfo( - TimePickerModule.NAME, - TimePickerModule.NAME, - false, // canOverrideExistingModule - false, // needsEagerInit - false, // hasConstants - false, // isCxxModule - isTurboModule // isTurboModule - )); - return moduleInfos; + return new ReactModuleInfoProvider() { + @Override + public Map getReactModuleInfos() { + final Map reactModuleInfoMap = new HashMap<>(); + Class[] moduleList = new Class[] { + DatePickerModule.class, + TimePickerModule.class, + }; + + for (Class 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(), + TurboModule.class.isAssignableFrom(moduleClass) + ) + ); + } + return reactModuleInfoMap; + } }; } }