Skip to content

Commit

Permalink
Convert modules to use @ReactModule instead of getName()
Browse files Browse the repository at this point in the history
Reviewed By: astreet

Differential Revision: D3334273

fbshipit-source-id: a33bf72c5c184844885ef3ef610a05d9c102c8ea
  • Loading branch information
aaronechiu authored and Facebook Github Bot 2 committed Aug 11, 2016
1 parent 9965642 commit c642136
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;

Expand Down Expand Up @@ -45,6 +46,8 @@ protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
}

// See ScrollViewListenerModule.js
// Matches ScrollViewListenerModule.js
@ReactModule(name = "ScrollListener")
protected static class ScrollListenerModule extends BaseJavaModule {

private final ArrayList<Double> mXOffsets = new ArrayList<Double>();
Expand All @@ -54,12 +57,6 @@ protected static class ScrollListenerModule extends BaseJavaModule {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@

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;

/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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.
Expand All @@ -23,6 +24,7 @@
* 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;
Expand All @@ -31,11 +33,6 @@ public JSIntegrationTestChecker() {
mLatch = new CountDownLatch(1);
}

@Override
public String getName() {
return "TestModule";
}

@ReactMethod
public void markTestCompleted() {
mLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
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;
Expand Down Expand Up @@ -63,11 +65,6 @@ public void setRequestListener(RequestListener requestListener) {
mRequestListener = requestListener;
}

@Override
public final String getName() {
return "RCTNetworking";
}

private void fireReactCallback(
Callback callback,
int status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.annotations.ReactModule;
import com.facebook.react.modules.systeminfo.AndroidInfoModule;
import com.facebook.react.testing.FakeWebSocketModule;
import com.facebook.react.testing.ReactIntegrationTestCase;
Expand Down Expand Up @@ -668,17 +669,13 @@ private void mapGetByType(ReadableMap map, String key, String typeToAskFor) {
}
}

@ReactModule(name = "Recording")
private class RecordingTestModule extends BaseJavaModule {

private final List<Object[]> mBasicTypesCalls = new ArrayList<Object[]>();
private final List<ReadableArray> mArrayCalls = new ArrayList<ReadableArray>();
private final List<ReadableMap> mMapCalls = new ArrayList<ReadableMap>();

@Override
public String getName() {
return "Recording";
}

@ReactMethod
public void receiveBasicTypes(String s, double d, boolean b, String nullableString) {
mBasicTypesCalls.add(new Object[]{s, d, b, nullableString});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import android.test.ActivityInstrumentationTestCase2;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.testing.FakeWebSocketModule;
import com.facebook.react.testing.ReactInstanceSpecForTest;
import com.facebook.react.bridge.annotations.ReactModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.testing.FakeWebSocketModule;
import com.facebook.react.testing.ReactAppTestActivity;
import com.facebook.react.testing.ReactInstanceSpecForTest;

/**
* Simple test case for passing initial props to the root React application.
Expand All @@ -27,15 +28,11 @@ public class InitialPropsTestCase extends

public static final String DEFAULT_JS_BUNDLE = "AndroidTestBundle.js";

@ReactModule(name = "InitialPropsRecordingModule")
private static class RecordingModule extends BaseJavaModule {
private int mCount = 0;
private ReadableMap mProps;

@Override
public String getName() {
return "InitialPropsRecordingModule";
}

@ReactMethod
public void recordProps(ReadableMap props) {
mProps = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.annotations.ReactModule;

@ReactModule(name = "JSCHeapCapture")
public class JSCHeapCapture extends ReactContextBaseJavaModule {
public interface HeapCapture extends JavaScriptModule {
void captureHeap(String path);
Expand Down Expand Up @@ -132,11 +134,6 @@ public synchronized void captureComplete(String path, String error) {
}
}

@Override
public String getName() {
return "JSCHeapCapture";
}

@Override
public void initialize() {
super.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

@ReactModule(name = "AppState")
public class AppStateModule extends ReactContextBaseJavaModule
implements LifecycleEventListener {

Expand All @@ -30,11 +32,6 @@ public AppStateModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "AppState";
}

@Override
public void initialize() {
getReactApplicationContext().addLifecycleEventListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.annotations.ReactModule;
import com.facebook.react.common.ReactConstants;

// TODO #6015104: rename to something less iOSish
/**
* {@link NativeModule} that allows JS to interact with the photos on the device (i.e.
* {@link MediaStore.Images}).
*/
@ReactModule(name = "RKCameraRollManager")
public class CameraRollManager extends ReactContextBaseJavaModule {

private static final String ERROR_UNABLE_TO_LOAD = "E_UNABLE_TO_LOAD";
Expand Down Expand Up @@ -98,11 +100,6 @@ public CameraRollManager(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "RKCameraRollManager";
}

@Override
public Map<String, Object> getConstants() {
return Collections.emptyMap();
Expand Down Expand Up @@ -440,5 +437,4 @@ private static void putLocationInfo(
node.putMap("location", location);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.annotations.ReactModule;
import com.facebook.react.common.ReactConstants;

/**
* Native module that provides image cropping functionality.
*/
@ReactModule(name = "RKImageEditingManager")
public class ImageEditingManager extends ReactContextBaseJavaModule {

private static final List<String> LOCAL_URI_PREFIXES = Arrays.asList(
Expand Down Expand Up @@ -89,17 +91,11 @@ public class ImageEditingManager extends ReactContextBaseJavaModule {
ExifInterface.TAG_WHITE_BALANCE
};


public ImageEditingManager(ReactApplicationContext reactContext) {
super(reactContext);
new CleanTask(getReactApplicationContext()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

@Override
public String getName() {
return "RKImageEditingManager";
}

@Override
public Map<String, Object> getConstants() {
return Collections.emptyMap();
Expand Down Expand Up @@ -282,7 +278,6 @@ protected void doInBackgroundGuarded(Void... params) {
}

mSuccess.invoke(Uri.fromFile(tempFile).toString());

} catch (Exception e) {
mError.invoke(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.annotations.ReactModule;

@ReactModule(name = "ImageStoreManager")
public class ImageStoreManager extends ReactContextBaseJavaModule {

private static final int BUFFER_SIZE = 8192;
Expand All @@ -36,11 +38,6 @@ public ImageStoreManager(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "ImageStoreManager";
}

/**
* Calculate the base64 representation for an image. The "tag" comes from iOS naming.
*
Expand Down
Loading

0 comments on commit c642136

Please sign in to comment.