mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 22:38:37 +08:00
Convert modules to use @ReactModule instead of getName()
Reviewed By: astreet Differential Revision: D3334273 fbshipit-source-id: a33bf72c5c184844885ef3ef610a05d9c102c8ea
This commit is contained in:
committed by
Facebook Github Bot 2
parent
9965642ebc
commit
c64213653e
@@ -15,6 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
import com.facebook.react.testing.ReactInstanceSpecForTest;
|
||||
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
|
||||
|
||||
@@ -45,6 +46,8 @@ public abstract class AbstractScrollViewTestCase extends ReactAppInstrumentation
|
||||
}
|
||||
|
||||
// See ScrollViewListenerModule.js
|
||||
// Matches ScrollViewListenerModule.js
|
||||
@ReactModule(name = "ScrollListener")
|
||||
protected static class ScrollListenerModule extends BaseJavaModule {
|
||||
|
||||
private final ArrayList<Double> mXOffsets = new ArrayList<Double>();
|
||||
@@ -54,12 +57,6 @@ public abstract class AbstractScrollViewTestCase extends ReactAppInstrumentation
|
||||
private boolean mScrollBeginDragCalled;
|
||||
private boolean mScrollEndDragCalled;
|
||||
|
||||
// Matches ScrollViewListenerModule.js
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ScrollListener";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void onScroll(double x, double y) {
|
||||
mXOffsets.add(x);
|
||||
|
||||
@@ -12,6 +12,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
@@ -19,17 +20,13 @@ import static junit.framework.Assert.assertTrue;
|
||||
/**
|
||||
* NativeModule for tests that allows assertions from JS to propagate to Java.
|
||||
*/
|
||||
@ReactModule(name = "Assert")
|
||||
public class AssertModule extends BaseJavaModule {
|
||||
|
||||
private boolean mGotSuccess;
|
||||
private boolean mGotFailure;
|
||||
private @Nullable String mFirstFailureStackTrace;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Assert";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void fail(String stackTrace) {
|
||||
if (!mGotFailure) {
|
||||
|
||||
@@ -14,10 +14,12 @@ import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
|
||||
/**
|
||||
* Dummy implementation of storage module, used for testing
|
||||
*/
|
||||
@ReactModule(name = "AsyncSQLiteDBStorage")
|
||||
public final class FakeAsyncLocalStorage extends BaseJavaModule {
|
||||
|
||||
private static WritableMap errorMessage;
|
||||
@@ -26,11 +28,6 @@ public final class FakeAsyncLocalStorage extends BaseJavaModule {
|
||||
errorMessage.putString("message", "Fake Async Local Storage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "AsyncSQLiteDBStorage";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void multiGet(final ReadableArray keys, final Callback callback) {
|
||||
callback.invoke(errorMessage, null);
|
||||
|
||||
@@ -15,21 +15,18 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
|
||||
/**
|
||||
* Native module provides single method {@link #record} which records its single int argument
|
||||
* in calls array
|
||||
*/
|
||||
@ReactModule(name = "Recording")
|
||||
public class IntRecordingModule extends BaseJavaModule {
|
||||
|
||||
private final List<Integer> mCalls = new ArrayList<>();
|
||||
private final CountDownLatch mCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Recording";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void record(int i) {
|
||||
mCalls.add(i);
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
|
||||
/**
|
||||
* This class is used to verify that some JS integration tests have completed successfully.
|
||||
@@ -23,6 +24,7 @@ import com.facebook.react.bridge.ReactMethod;
|
||||
* to wait for the test to run, and {#link JSIntegrationTestChecker#isTestDone()} to check if it
|
||||
* completed successfully.
|
||||
*/
|
||||
@ReactModule(name = "TestModule")
|
||||
public class JSIntegrationTestChecker extends BaseJavaModule {
|
||||
|
||||
private final CountDownLatch mLatch;
|
||||
@@ -31,11 +33,6 @@ public class JSIntegrationTestChecker extends BaseJavaModule {
|
||||
mLatch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TestModule";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void markTestCompleted() {
|
||||
mLatch.countDown();
|
||||
|
||||
@@ -19,12 +19,14 @@ import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
|
||||
/**
|
||||
* Mock Networking module that records last request received by {@link #sendRequest} method and
|
||||
* returns reponse code and body that should be set with {@link #setResponse}
|
||||
*/
|
||||
@ReactModule(name = "RCTNetworking")
|
||||
public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
|
||||
public int mRequestCount = 0;
|
||||
@@ -63,11 +65,6 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
mRequestListener = requestListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return "RCTNetworking";
|
||||
}
|
||||
|
||||
private void fireReactCallback(
|
||||
Callback callback,
|
||||
int status,
|
||||
|
||||
@@ -13,20 +13,17 @@ import java.util.List;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.annotations.ReactModule;
|
||||
|
||||
/**
|
||||
* Native module provides single method {@link #record} which records its single string argument
|
||||
* in calls array
|
||||
*/
|
||||
@ReactModule(name = "Recording")
|
||||
public class StringRecordingModule extends BaseJavaModule {
|
||||
|
||||
private final List<String> mCalls = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Recording";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void record(String text) {
|
||||
mCalls.add(text);
|
||||
|
||||
Reference in New Issue
Block a user