public abstract class BaseJavaModule extends java.lang.Object implements NativeModule
initialize()
and onCatalystInstanceDestroy()
are provided for
convenience. Subclasses which override these don't need to call 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:
1/ primitives (boolean, int, float, double
2/ String
mapped from JS string
3/ ReadableArray
mapped from JS Array
4/ ReadableMap
mapped from JS Object
5/ 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 respecively.
All methods exposed as native to JS with ReactMethod
annotation must return
void
.
Please note that it is not allowed to have multiple methods annotated with ReactMethod
with the same name.NativeModule.NativeMethod
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
METHOD_TYPE_REMOTE |
static java.lang.String |
METHOD_TYPE_REMOTE_ASYNC |
Constructor and Description |
---|
BaseJavaModule() |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
getConstants() |
java.util.Map<java.lang.String,NativeModule.NativeMethod> |
getMethods() |
void |
initialize()
This is called at the end of
CatalystApplicationFragment#createCatalystInstance()
after the CatalystInstance has been created, in order to initialize NativeModules that require
the CatalystInstance or JS modules. |
void |
onCatalystInstanceDestroy()
Called before {CatalystInstance#onHostDestroy}
|
void |
writeConstantsField(com.fasterxml.jackson.core.JsonGenerator jg,
java.lang.String fieldName)
Append a field which represents the constants this module exports
to JS.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName
public static final java.lang.String METHOD_TYPE_REMOTE
public static final java.lang.String METHOD_TYPE_REMOTE_ASYNC
public final java.util.Map<java.lang.String,NativeModule.NativeMethod> getMethods()
getMethods
in interface NativeModule
@Nullable public java.util.Map<java.lang.String,java.lang.Object> getConstants()
public final void writeConstantsField(com.fasterxml.jackson.core.JsonGenerator jg, java.lang.String fieldName) throws java.io.IOException
NativeModule
writeConstantsField
in interface NativeModule
java.io.IOException
public void initialize()
NativeModule
CatalystApplicationFragment#createCatalystInstance()
after the CatalystInstance has been created, in order to initialize NativeModules that require
the CatalystInstance or JS modules.initialize
in interface NativeModule
public void onCatalystInstanceDestroy()
NativeModule
onCatalystInstanceDestroy
in interface NativeModule