mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Cleanup and document native module configuration
Summary: Get rid of the old behaviour of JSON encoding in `nativeRequireModuleConfig` and consistently use the same names for function types "async/promise/sync" Reviewed By: lexs Differential Revision: D3819348 fbshipit-source-id: fc798a5abcaf6a3ef9d95bd8654afa7825c83967
This commit is contained in:
committed by
Facebook Github Bot 8
parent
28ba749ba0
commit
99e0267c25
@@ -50,9 +50,9 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
*/
|
||||
public abstract class BaseJavaModule implements NativeModule {
|
||||
// taken from Libraries/Utilities/MessageQueue.js
|
||||
static final public String METHOD_TYPE_REMOTE = "remote";
|
||||
static final public String METHOD_TYPE_REMOTE_ASYNC = "remoteAsync";
|
||||
static final public String METHOD_TYPE_SYNC_HOOK = "syncHook";
|
||||
static final public String METHOD_TYPE_ASYNC = "async";
|
||||
static final public String METHOD_TYPE_PROMISE= "promise";
|
||||
static final public String METHOD_TYPE_SYNC = "sync";
|
||||
|
||||
private static abstract class ArgumentExtractor<T> {
|
||||
public int getJSArgumentsNeeded() {
|
||||
@@ -164,7 +164,7 @@ public abstract class BaseJavaModule implements NativeModule {
|
||||
private final ArgumentExtractor[] mArgumentExtractors;
|
||||
private final String mSignature;
|
||||
private final Object[] mArguments;
|
||||
private String mType = METHOD_TYPE_REMOTE;
|
||||
private String mType = METHOD_TYPE_ASYNC;
|
||||
private final int mJSArgumentsNeeded;
|
||||
private final String mTraceName;
|
||||
|
||||
@@ -203,7 +203,7 @@ public abstract class BaseJavaModule implements NativeModule {
|
||||
} else if (paramClass == Promise.class) {
|
||||
Assertions.assertCondition(
|
||||
i == paramTypes.length - 1, "Promise must be used as last parameter only");
|
||||
mType = METHOD_TYPE_REMOTE_ASYNC;
|
||||
mType = METHOD_TYPE_PROMISE;
|
||||
}
|
||||
builder.append(paramTypeToChar(paramClass));
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public abstract class BaseJavaModule implements NativeModule {
|
||||
argumentExtractors[i] = ARGUMENT_EXTRACTOR_PROMISE;
|
||||
Assertions.assertCondition(
|
||||
paramIndex == paramTypes.length - 1, "Promise must be used as last parameter only");
|
||||
mType = METHOD_TYPE_REMOTE_ASYNC;
|
||||
mType = METHOD_TYPE_PROMISE;
|
||||
} else if (argumentClass == ReadableMap.class) {
|
||||
argumentExtractors[i] = ARGUMENT_EXTRACTOR_MAP;
|
||||
} else if (argumentClass == ReadableArray.class) {
|
||||
@@ -339,8 +339,8 @@ public abstract class BaseJavaModule implements NativeModule {
|
||||
|
||||
/**
|
||||
* Determines how the method is exported in JavaScript:
|
||||
* METHOD_TYPE_REMOTE for regular methods
|
||||
* METHOD_TYPE_REMOTE_ASYNC for methods that return a promise object to the caller.
|
||||
* METHOD_TYPE_ASYNC for regular methods
|
||||
* METHOD_TYPE_PROMISE for methods that return a promise object to the caller.
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.annotation.Nullable;
|
||||
* method parameter.
|
||||
*
|
||||
* Methods annotated with {@link ReactMethod} that use {@link Promise} as type of the last parameter
|
||||
* will be marked as "remoteAsync" and will return a promise when invoked from JavaScript.
|
||||
* will be marked as "promise" and will return a promise when invoked from JavaScript.
|
||||
*/
|
||||
public interface Promise {
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
mModule.getSyncHooks().entrySet()) {
|
||||
MethodDescriptor md = new MethodDescriptor();
|
||||
md.name = entry.getKey();
|
||||
md.type = BaseJavaModule.METHOD_TYPE_SYNC_HOOK;
|
||||
md.type = BaseJavaModule.METHOD_TYPE_SYNC;
|
||||
|
||||
BaseJavaModule.SyncJavaHook method = (BaseJavaModule.SyncJavaHook) entry.getValue();
|
||||
md.method = method.getMethod();
|
||||
|
||||
Reference in New Issue
Block a user