-
- 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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringMETHOD_TYPE_ASYNCpublic final static StringMETHOD_TYPE_PROMISEpublic final static StringMETHOD_TYPE_SYNC
-
Method Summary
Modifier and Type Method Description Map<String, Object>getConstants()voidinitialize()This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules. booleancanOverrideExistingModule()Return true if you intend to override some other native module that was registered e.g. voidonCatalystInstanceDestroy()Allow NativeModule to clean up. booleanhasConstants()voidinvalidate()The CatalystInstance is going away with Venice. -
-
Method Detail
-
getConstants
@Nullable() Map<String, Object> getConstants()
-
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}
-
hasConstants
boolean hasConstants()
-
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.
-
-
-
-