Java Code Examples for com.facebook.react.bridge.NativeModule

The following are top voted examples for showing how to use com.facebook.react.bridge.NativeModule. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: ModuleHolder.java   View source code 6 votes vote down vote up
private NativeModule create() {
  SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
  ReactMarker.logMarker(CREATE_MODULE_START, mName);
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createModule")
    .arg("name", mName)
    .flush();
  NativeModule module = assertNotNull(mProvider).get();
  mProvider = null;
  if (mInitializeNeeded) {
    doInitialize(module);
    mInitializeNeeded = false;
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(CREATE_MODULE_END);
  return module;
}
 
Example 2
Project: react-native-threads   File: ThreadBaseReactPackage.java   View source code 6 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext catalystApplicationContext) {
    return Arrays.<NativeModule>asList(
            // Core list
            new AndroidInfoModule(),
            new ExceptionsManagerModule(reactInstanceManager.getDevSupportManager()),
            new AppStateModule(catalystApplicationContext),
            new Timing(catalystApplicationContext, reactInstanceManager.getDevSupportManager()),
            new UIManagerStubModule(catalystApplicationContext),
            new SourceCodeModule(catalystApplicationContext),
            new JSCHeapCapture(catalystApplicationContext),

            // Main list
            new AsyncStorageModule(catalystApplicationContext),
            new IntentModule(catalystApplicationContext),
            new LocationModule(catalystApplicationContext),
            new NetworkingModule(catalystApplicationContext),
            new NetInfoModule(catalystApplicationContext),
            new VibrationModule(catalystApplicationContext),
            new WebSocketModule(catalystApplicationContext),
            new ThreadSelfModule(catalystApplicationContext)
    );
}
 
Example 3
Project: RNLearn_Project1   File: CompositeReactPackage.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<NativeModule> createNativeModules(
    ReactApplicationContext reactContext,
    ReactInstanceManager reactInstanceManager) {
  final Map<String, NativeModule> moduleMap = new HashMap<>();
  for (ReactPackage reactPackage: mChildReactPackages) {
    List<NativeModule> nativeModules;
    if (reactPackage instanceof ReactInstancePackage) {
      ReactInstancePackage reactInstancePackage = (ReactInstancePackage) reactPackage;
      nativeModules = reactInstancePackage.createNativeModules(
          reactContext,
          reactInstanceManager);
    } else {
      nativeModules = reactPackage.createNativeModules(reactContext);
    }
    for (NativeModule nativeModule: nativeModules) {
      moduleMap.put(nativeModule.getName(), nativeModule);
    }
  }
  return new ArrayList(moduleMap.values());
}
 
Example 4
Project: react-native-sweet-alert   File: RNSweetAlertPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();
  modules.add(new RNSweetAlertModule(reactContext));

  return modules;
}
 
Example 5
Project: React-Native-Music-Player   File: MusicPlayerModulePackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();
    modules.add(new MusicPlayerModule(reactContext));
    return modules;
}
 
Example 6
Project: react-native-webrtc   File: WebRTCModulePackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new WebRTCModule(reactContext));
    return modules;
}
 
Example 7
Project: react-native-stt   File: RNSpeechToTextPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new RNSpeechToText(reactApplicationContext));

  return modules;
}
 
Example 8
Project: react-native-download-manager   File: DownloadFilePackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new DownloadFileManager(reactContext));

    return modules;
}
 
Example 9
Project: RNLearn_Project1   File: ModuleHolder.java   View source code 5 votes vote down vote up
public ModuleHolder(NativeModule nativeModule) {
  mName = nativeModule.getName();
  mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
  mSupportsWebWorkers = nativeModule.supportsWebWorkers();
  mHasConstants = true;
  mModule = nativeModule;
}
 
Example 10
Project: react-native-nfc-manager   File: NfcManagerPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new NfcManager(reactApplicationContext));
    return modules;
}
 
Example 11
Project: nfc-react-native-simple   File: NfcReactNativeSimplePackage.java   View source code 5 votes vote down vote up
/**
 * @param reactContext react application context that can be used to create modules
 * @return list of native modules to register with the newly created catalyst instance
 */
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();
    modules.add(new NfcReactNativeSimpleModule(reactContext));

    return modules;
}
 
Example 12
Project: react-native-system-setting   File: SystemSettingPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new SystemSetting(reactContext));

    return modules;
}
 
Example 13
Project: react-native-background-task   File: BackgroundTaskPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new BackgroundTaskModule(reactContext));

    return modules;
}
 
Example 14
Project: RNLearn_Project1   File: ReactPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
    ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();
  modules.add(new SomeExampleModule(reactContext));
  return modules;
}
 
Example 15
Project: RNLearn_Project1   File: NativeModuleRegistry.java   View source code 5 votes vote down vote up
Collection<JavaModuleWrapper> getJavaModules(
    JSInstance jsInstance) {
  ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
  for (Map.Entry<Class<? extends NativeModule>, ModuleHolder> entry : mModules.entrySet()) {
    Class<?> type = entry.getKey();
    if (!CxxModuleWrapper.class.isAssignableFrom(type)) {
      javaModules.add(new JavaModuleWrapper(jsInstance, entry.getValue()));
    }
  }
  return javaModules;
}
 
Example 16
Project: react-native-caller-id-android   File: CallerIDReactPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new AddPermissions(reactContext));
    modules.add(new UsersDB(reactContext));

    return modules;
}
 
Example 17
Project: react-native-alert   File: PLPAlertPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
                            ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new DialogModule(reactContext));

  return modules;
}
 
Example 18
Project: react-native-exit-app   File: RNExitAppPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new RNExitAppModule(reactContext));

    return modules;
}
 
Example 19
Project: RNLearn_Project1   File: ReactTestHelper.java   View source code 5 votes vote down vote up
@Override
public ReactInstanceEasyBuilder addNativeModule(NativeModule nativeModule) {
  if (mNativeModuleRegistryBuilder == null) {
    mNativeModuleRegistryBuilder = new NativeModuleRegistryBuilder(
      (ReactApplicationContext) mContext,
      null,
      false);
  }
  mNativeModuleRegistryBuilder.addNativeModule(nativeModule);
  return this;
}
 
Example 20
Project: react-native-key-value-storage   File: KeyValueStoragePackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new KeyValueStorageModule(reactContext));

    return modules;
}
 
Example 21
Project: react-native-threads   File: ReactContextBuilder.java   View source code 5 votes vote down vote up
private void addNativeModules(ReactApplicationContext reactContext, NativeModuleRegistryBuilder nativeRegistryBuilder) {
    for (int i = 0; i < reactPackages.size(); i++) {
        ReactPackage reactPackage = reactPackages.get(i);
        for (NativeModule nativeModule : reactPackage.createNativeModules(reactContext)) {
            nativeRegistryBuilder.addNativeModule(nativeModule);
        }
    }
}
 
Example 22
Project: RNLearn_Project1   File: JavaModuleWrapper.java   View source code 5 votes vote down vote up
public JavaModuleWrapper(JSInstance jsInstance, Class<? extends NativeModule> moduleClass, ModuleHolder moduleHolder) {
  mJSInstance = jsInstance;
  mModuleHolder = moduleHolder;
  mModuleClass = moduleClass;
  mMethods = new ArrayList<>();
  mDescs = new ArrayList();
}
 
Example 23
Project: onfido-sdk-react-native-sample-app   File: AppPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new OnfidoSDK(reactContext));

    return modules;
}
 
Example 24
Project: RNLearn_Project1   File: CompositeReactPackageTest.java   View source code 5 votes vote down vote up
@Test
public void testThatCompositeReturnsASumOfNativeModules() {
  // Given
  CompositeReactPackage composite = new CompositeReactPackage(packageNo1, packageNo2);

  NativeModule moduleNo1 = mock(NativeModule.class);
  when(moduleNo1.getName()).thenReturn("ModuleNo1");

  // module2 and module3 will share same name, composite should return only the latter one
  final String sameModuleName = "SameModuleName";

  NativeModule moduleNo2 = mock(NativeModule.class);
  when(moduleNo2.getName()).thenReturn(sameModuleName);

  NativeModule moduleNo3 = mock(NativeModule.class);
  when(moduleNo3.getName()).thenReturn(sameModuleName);

  NativeModule moduleNo4 = mock(NativeModule.class);
  when(moduleNo4.getName()).thenReturn("ModuleNo4");

  when(packageNo1.createNativeModules(reactContext)).thenReturn(
      Arrays.asList(new NativeModule[]{moduleNo1, moduleNo2}));

  when(packageNo2.createNativeModules(reactContext)).thenReturn(
      Arrays.asList(new NativeModule[]{moduleNo3, moduleNo4}));

  // When
  List<NativeModule> compositeModules = composite.createNativeModules(reactContext);

  // Then

  // Wrapping lists into sets to be order-independent.
  // Note that there should be no module2 returned.
  Set<NativeModule> expected = new HashSet<>(
      Arrays.asList(new NativeModule[]{moduleNo1, moduleNo3, moduleNo4}));
  Set<NativeModule> actual = new HashSet<>(compositeModules);

  assertEquals(expected, actual);
}
 
Example 25
Project: react-native-growingio   File: GrowingRnPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();
    modules.add(new GrowingIOModule(reactContext));
    return modules;
}
 
Example 26
Project: RNLearn_Project1   File: NativeModuleRegistry.java   View source code 5 votes vote down vote up
Collection<JavaModuleWrapper> getJavaModules(
    JSInstance jsInstance) {
  ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
  for (Map.Entry<Class<? extends NativeModule>, ModuleHolder> entry : mModules.entrySet()) {
    Class<? extends NativeModule> type = entry.getKey();
    if (!CxxModuleWrapperBase.class.isAssignableFrom(type)) {
      javaModules.add(new JavaModuleWrapper(jsInstance, type, entry.getValue()));
    }
  }
  return javaModules;
}
 
Example 27
Project: RNLearn_Project1   File: NativeModuleRegistryBuilder.java   View source code 5 votes vote down vote up
public NativeModuleRegistry build() {
  ArrayList<ModuleHolder> batchCompleteListenerModules = new ArrayList<>();
  for (Map.Entry<Class<? extends NativeModule>, ModuleHolder> entry : mModules.entrySet()) {
    if (OnBatchCompleteListener.class.isAssignableFrom(entry.getKey())) {
      batchCompleteListenerModules.add(entry.getValue());
    }
  }

  return new NativeModuleRegistry(
    mReactApplicationContext,
    mModules,
    batchCompleteListenerModules);
}
 
Example 28
Project: rn-crash-reporter   File: RNCrashReporterModule.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {

    return Arrays.<NativeModule>asList(
        new RNCrashReporter(reactContext, currentActivity)
    );
}
 
Example 29
Project: react-native-call-log   File: CallLogPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
                            ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new CallLogModule(reactContext));

  return modules;
}
 
Example 30
Project: react-native-sunmi-inner-printer   File: SunmiInnerPrinterPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
                            ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new SunmiInnerPrinterModule(reactContext));

  return modules;
}
 
Example 31
Project: react-native-call-events   File: ReactNativeCallEventsPackageTest.java   View source code 5 votes vote down vote up
@Test
public void testCreateNativeModules() throws Exception {
    ReactNativeCallEventsPackage instance = new ReactNativeCallEventsPackage();
    List<NativeModule> results = instance.createNativeModules(reactContext);
    ReactNativeCallEventsModule result = (ReactNativeCallEventsModule) results.get(0);
    assertThat(result, not(equalTo(null)));
}
 
Example 32
Project: react-native-screenshot-detect   File: ScreenShotDetectPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {

    List<NativeModule> modules = new ArrayList<>();
    modules.add(new ScreenShotDetectModule(reactContext));
    return modules;
}
 
Example 33
Project: RNLearn_Project1   File: ReactTestHelper.java   View source code 5 votes vote down vote up
@Override
public ReactInstanceEasyBuilder addNativeModule(NativeModule nativeModule) {
  if (mNativeModuleRegistryBuilder == null) {
    mNativeModuleRegistryBuilder = new NativeModuleRegistryBuilder(
      (ReactApplicationContext) mContext,
      null,
      false);
  }
  mNativeModuleRegistryBuilder.addNativeModule(nativeModule);
  return this;
}
 
Example 34
Project: react-native-icon-badge   File: RNIconBadge.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
                            ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new RNIconBadgeModule(reactContext));

  return modules;
}
 
Example 35
Project: RNLearn_Project1   File: ModuleHolder.java   View source code 5 votes vote down vote up
private void doInitialize(NativeModule module) {
  SystraceMessage.Builder section =
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "initialize");
  if (module instanceof CxxModuleWrapper) {
    section.arg("className", module.getClass().getSimpleName());
  } else {
    section.arg("name", mName);
  }
  section.flush();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName);
  module.initialize();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_END);
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 36
Project: RNLearn_Project1   File: NativeModuleRegistry.java   View source code 5 votes vote down vote up
public NativeModuleRegistry(
  ReactApplicationContext reactApplicationContext,
  Map<Class<? extends NativeModule>, ModuleHolder> modules,
  ArrayList<ModuleHolder> batchCompleteListenerModules) {
  mReactApplicationContext = reactApplicationContext;
  mModules = modules;
  mBatchCompleteListenerModules = batchCompleteListenerModules;
}
 
Example 37
Project: react-native-async-storage-dev-menu-item   File: AsyncStorageDevMenuItemPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new AsyncStorageDevMenuItemModule(reactContext));

  return modules;
}
 
Example 38
Project: RNNavitiaSDK   File: RNNavitiaSDKPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
        ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new RNNavitiaSDK(reactContext));
    return modules;
}
 
Example 39
Project: react-native-forward-calls   File: RNForwardCallsPackage.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<NativeModule>();
  modules.add(new RNForwardCallsModule(reactContext));
  return modules;
}
 
Example 40
Project: react-native-device-brightness   File: RNDeviceBrightness.java   View source code 5 votes vote down vote up
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();

  modules.add(new RNDeviceBrightnessModule(reactContext));

  return modules;
}