Move interfaces from Bridge to a new buck target
Reviewed By: achen1 Differential Revision: D9513130 fbshipit-source-id: f23e3274eed5f0adcffdc3e10d20a4d49e81bca5
This commit is contained in:
parent
f8f1870248
commit
01580de613
|
@ -1,8 +1,24 @@
|
|||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_dep", "react_native_target", "rn_android_library")
|
||||
|
||||
INTERFACES = [
|
||||
"Dynamic.java",
|
||||
"ReadableMap.java",
|
||||
"ReadableMapKeySetIterator.java",
|
||||
"WritableArray.java",
|
||||
"WritableMap.java",
|
||||
"NativeModule.java",
|
||||
"JSInstance.java",
|
||||
"ReadableArray.java",
|
||||
"ReadableType.java",
|
||||
"NativeArrayInterface.java",
|
||||
]
|
||||
|
||||
rn_android_library(
|
||||
name = "bridge",
|
||||
srcs = glob(["**/*.java"]),
|
||||
srcs = glob(
|
||||
["**/*.java"],
|
||||
exclude = INTERFACES,
|
||||
),
|
||||
proguard_config = "reactnative.pro",
|
||||
provided_deps = [
|
||||
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
||||
|
@ -28,5 +44,28 @@ rn_android_library(
|
|||
react_native_dep("java/com/facebook/jni:jni"),
|
||||
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
|
||||
react_native_dep("third-party/java/jsr-330:jsr-330"),
|
||||
react_native_target("java/com/facebook/react/bridge:interfaces"),
|
||||
],
|
||||
)
|
||||
|
||||
rn_android_library(
|
||||
name = "interfaces",
|
||||
srcs = glob(INTERFACES),
|
||||
proguard_config = "reactnative.pro",
|
||||
provided_deps = [
|
||||
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
||||
],
|
||||
required_for_source_only_abi = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_target("java/com/facebook/debug/tags:tags"),
|
||||
],
|
||||
exported_deps = [
|
||||
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
|
||||
react_native_dep("third-party/java/jsr-330:jsr-330"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -38,7 +38,7 @@ public interface CatalystInstance
|
|||
@Override @DoNotStrip
|
||||
void invokeCallback(
|
||||
int callbackID,
|
||||
NativeArray arguments);
|
||||
NativeArrayInterface arguments);
|
||||
@DoNotStrip
|
||||
void callFunction(
|
||||
String module,
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.facebook.react.common.ReactConstants;
|
|||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.TraceListener;
|
||||
import java.lang.annotation.Native;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -306,13 +307,13 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
private native void jniCallJSCallback(int callbackID, NativeArray arguments);
|
||||
|
||||
@Override
|
||||
public void invokeCallback(final int callbackID, final NativeArray arguments) {
|
||||
public void invokeCallback(final int callbackID, final NativeArrayInterface arguments) {
|
||||
if (mDestroyed) {
|
||||
FLog.w(ReactConstants.TAG, "Invoking JS callback after bridge has been destroyed.");
|
||||
return;
|
||||
}
|
||||
|
||||
jniCallJSCallback(callbackID, arguments);
|
||||
jniCallJSCallback(callbackID, (NativeArray) arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ package com.facebook.react.bridge;
|
|||
public interface JSInstance {
|
||||
void invokeCallback(
|
||||
int callbackID,
|
||||
NativeArray arguments);
|
||||
NativeArrayInterface arguments);
|
||||
// TODO if this interface survives refactoring, think about adding
|
||||
// callFunction.
|
||||
}
|
||||
|
|
|
@ -26,14 +26,14 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
}
|
||||
|
||||
public abstract @Nullable T extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex);
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex);
|
||||
}
|
||||
|
||||
static final private ArgumentExtractor<Boolean> ARGUMENT_EXTRACTOR_BOOLEAN =
|
||||
new ArgumentExtractor<Boolean>() {
|
||||
@Override
|
||||
public Boolean extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return jsArguments.getBoolean(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -42,7 +42,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<Double>() {
|
||||
@Override
|
||||
public Double extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return jsArguments.getDouble(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<Float>() {
|
||||
@Override
|
||||
public Float extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return (float) jsArguments.getDouble(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -60,7 +60,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<Integer>() {
|
||||
@Override
|
||||
public Integer extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return (int) jsArguments.getDouble(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -69,16 +69,16 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<String>() {
|
||||
@Override
|
||||
public String extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return jsArguments.getString(atIndex);
|
||||
}
|
||||
};
|
||||
|
||||
static final private ArgumentExtractor<ReadableNativeArray> ARGUMENT_EXTRACTOR_ARRAY =
|
||||
new ArgumentExtractor<ReadableNativeArray>() {
|
||||
static final private ArgumentExtractor<ReadableArray> ARGUMENT_EXTRACTOR_ARRAY =
|
||||
new ArgumentExtractor<ReadableArray>() {
|
||||
@Override
|
||||
public ReadableNativeArray extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
public ReadableArray extractArgument(
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return jsArguments.getArray(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -87,7 +87,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<Dynamic>() {
|
||||
@Override
|
||||
public Dynamic extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return DynamicFromArray.create(jsArguments, atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -96,7 +96,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<ReadableMap>() {
|
||||
@Override
|
||||
public ReadableMap extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
return jsArguments.getMap(atIndex);
|
||||
}
|
||||
};
|
||||
|
@ -105,7 +105,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
new ArgumentExtractor<Callback>() {
|
||||
@Override
|
||||
public @Nullable Callback extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
if (jsArguments.isNull(atIndex)) {
|
||||
return null;
|
||||
} else {
|
||||
|
@ -124,7 +124,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
|
||||
@Override
|
||||
public Promise extractArgument(
|
||||
JSInstance jsInstance, ReadableNativeArray jsArguments, int atIndex) {
|
||||
JSInstance jsInstance, ReadableArray jsArguments, int atIndex) {
|
||||
Callback resolve = ARGUMENT_EXTRACTOR_CALLBACK
|
||||
.extractArgument(jsInstance, jsArguments, atIndex);
|
||||
Callback reject = ARGUMENT_EXTRACTOR_CALLBACK
|
||||
|
@ -328,7 +328,7 @@ public class JavaMethodWrapper implements NativeModule.NativeMethod {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void invoke(JSInstance jsInstance, ReadableNativeArray parameters) {
|
||||
public void invoke(JSInstance jsInstance, ReadableArray parameters) {
|
||||
String traceName = mModuleWrapper.getName() + "." + mMethod.getName();
|
||||
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "callJavaModuleMethod")
|
||||
.arg("method", traceName)
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
|||
* Base class for an array whose members are stored in native code (C++).
|
||||
*/
|
||||
@DoNotStrip
|
||||
public abstract class NativeArray {
|
||||
public abstract class NativeArray implements NativeArrayInterface{
|
||||
static {
|
||||
ReactBridge.staticInit();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.facebook.react.bridge;
|
||||
|
||||
public interface NativeArrayInterface {
|
||||
@Override
|
||||
String toString();
|
||||
}
|
|
@ -20,7 +20,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
|||
@DoNotStrip
|
||||
public interface NativeModule {
|
||||
interface NativeMethod {
|
||||
void invoke(JSInstance jsInstance, ReadableNativeArray parameters);
|
||||
void invoke(JSInstance jsInstance, ReadableArray parameters);
|
||||
String getType();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@ rn_android_library(
|
|||
deps = [
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/bridge:interfaces"),
|
||||
],
|
||||
)
|
||||
|
|
|
@ -7,16 +7,14 @@
|
|||
|
||||
package com.facebook.react.module.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation for use on {@link BaseJavaModule}s to describe properties for that module.
|
||||
* Annotation for use on {@link com.facebook.react.bridge.BaseJavaModule}s to describe properties for that module.
|
||||
*/
|
||||
@Retention(RUNTIME)
|
||||
@Target(TYPE)
|
||||
|
|
Loading…
Reference in New Issue