Package 

Class BaseJavaModule

  • All Implemented Interfaces:
    com.facebook.react.bridge.NativeModule

    
    public abstract class BaseJavaModule
     implements NativeModule
                        

    Base class for Catalyst native modules whose implementations are written in Java. Default implementations for initialize and onCatalystInstanceDestroy are provided for convenience. Subclasses which override these don't need to call {@code super} in case of overriding those methods as implementation of those methods is empty.

    BaseJavaModules can be linked to Fragments' lifecycle events, CatalystInstance creation and destruction, by being called on the appropriate method when a life cycle event occurs.

    Native methods can be exposed to JS with ReactMethod annotation. Those methods may only use limited number of types for their arguments:

    • primitives (boolean, int, float, double
    • String mapped from JS string
    • ReadableArray mapped from JS Array
    • ReadableMap mapped from JS Object
    • Callback mapped from js function and can be used only as a last parameter or in the case when it express success & error callback pair as two last arguments respectively.

    All methods exposed as native to JS with ReactMethod annotation must return {@code * void}.

    Please note that it is not allowed to have multiple methods annotated with ReactMethod with the same name.

    • Method Summary

      Modifier and Type Method Description
      Map<String, Object> getConstants()
      void initialize() This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules.
      boolean canOverrideExistingModule() Return true if you intend to override some other native module that was registered e.g.
      void onCatalystInstanceDestroy() Allow NativeModule to clean up.
      boolean hasConstants()
      void invalidate() The CatalystInstance is going away with Venice.
      • Methods inherited from class com.facebook.react.bridge.NativeModule

        getName
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • initialize

         void initialize()

        This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules.

      • canOverrideExistingModule

         boolean canOverrideExistingModule()

        Return true if you intend to override some other native module that was registered e.g. as partof a different package (such as the core one). Trying to override without returning true fromthis method is considered an error and will throw an exception during initialization. Bydefault all modules return false.

      • onCatalystInstanceDestroy

         void onCatalystInstanceDestroy()

        Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy}

      • invalidate

         void invalidate()

        The CatalystInstance is going away with Venice. Therefore, the TurboModule infra introduces theinvalidate() method to allow NativeModules to clean up after themselves.