Skip to content

Commit

Permalink
Use static constants instead of strings when referring to View Manage…
Browse files Browse the repository at this point in the history
…rs and Native Modules

Summary: Using strings to refer to Native Modules and View Managers in ReactPackages are prone to error. The compiler replaces the constants with the actual strings anyway, so using constants gives us  better type safety

Reviewed By: achen1

Differential Revision: D12843649

fbshipit-source-id: 7a7c6c854c8689193f40df92dc8426a3b37f82c8
  • Loading branch information
axe-fb authored and facebook-github-bot committed Nov 9, 2018
1 parent 28278e1 commit 803e993
Show file tree
Hide file tree
Showing 32 changed files with 64 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
LifecycleEventListener, UIManagerModuleListener {

protected static final String NAME = "NativeAnimatedModule";
public static final String NAME = "NativeAnimatedModule";

private interface UIThreadOperation {
void execute(NativeAnimatedNodesManager animatedNodesManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
* Module that monitors and provides information about the state of Touch Exploration service
* on the device. For API >= 19.
*/
@ReactModule(name = "AccessibilityInfo")
@ReactModule(name = AccessibilityInfoModule.NAME)
public class AccessibilityInfoModule extends ReactContextBaseJavaModule
implements LifecycleEventListener {

public static final String NAME = "AccessibilityInfo";

@TargetApi(19)
private class ReactTouchExplorationStateChangeListener
implements AccessibilityManager.TouchExplorationStateChangeListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@ReactModule(name = CameraRollManager.NAME)
public class CameraRollManager extends ReactContextBaseJavaModule {

protected static final String NAME = "CameraRollManager";
public static final String NAME = "CameraRollManager";

private static final String ERROR_UNABLE_TO_LOAD = "E_UNABLE_TO_LOAD";
private static final String ERROR_UNABLE_TO_LOAD_PERMISSION = "E_UNABLE_TO_LOAD_PERMISSION";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
/**
* A module that allows JS to get/set clipboard contents.
*/
@ReactModule(name = "Clipboard")
@ReactModule(name = ClipboardModule.NAME)
public class ClipboardModule extends ContextBaseJavaModule {

public ClipboardModule(Context context) {
super(context);
}

public static final String NAME = "Clipboard";

@Override
public String getName() {
return "Clipboard";
return ClipboardModule.NAME;
}

private ClipboardManager getClipboardService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

package com.facebook.react.modules.datepicker;

import javax.annotation.Nullable;

import java.util.Map;

import android.app.Activity;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.DialogFragment;
Expand All @@ -19,23 +15,17 @@
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.widget.DatePicker;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.*;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.module.annotations.ReactModule;

import javax.annotation.Nullable;

/**
* {@link NativeModule} that allows JS to show a native date picker dialog and get called back when
* the user selects a date.
*/
@ReactModule(name = "DatePickerAndroid")
@ReactModule(name = DatePickerDialogModule.FRAGMENT_TAG)
public class DatePickerDialogModule extends ReactContextBaseJavaModule {

@VisibleForTesting
Expand All @@ -57,7 +47,7 @@ public DatePickerDialogModule(ReactApplicationContext reactContext) {

@Override
public String getName() {
return "DatePickerAndroid";
return DatePickerDialogModule.FRAGMENT_TAG;
}

private class DatePickerDialogListener implements OnDateSetListener, OnDismissListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DialogModule extends ReactContextBaseJavaModule implements Lifecycl
/* package */ static final String FRAGMENT_TAG =
"com.facebook.catalyst.react.dialog.DialogModule";

/* package */ static final String NAME = "DialogManagerAndroid";
public static final String NAME = "DialogManagerAndroid";

/* package */ static final String ACTION_BUTTON_CLICKED = "buttonClicked";
/* package */ static final String ACTION_DISMISSED = "dismissed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
*
* <p>Does not expose any methods to JavaScript code. For initialization and cleanup only.
*/
@ReactModule(name = "FrescoModule", needsEagerInit = true)
@ReactModule(name = FrescoModule.NAME, needsEagerInit = true)
public class FrescoModule extends ReactContextBaseJavaModule implements
ModuleDataCleaner.Cleanable, LifecycleEventListener {

public static final String NAME = "FrescoModule";
private final boolean mClearOnDestroy;
private @Nullable ImagePipelineConfig mConfig;

Expand Down Expand Up @@ -114,7 +115,7 @@ public void initialize() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.module.annotations.ReactModule;

@ReactModule(name = "ImageLoader")
@ReactModule(name = ImageLoaderModule.NAME)
public class ImageLoaderModule extends ReactContextBaseJavaModule implements
LifecycleEventListener {

private static final String ERROR_INVALID_URI = "E_INVALID_URI";
private static final String ERROR_PREFETCH_FAILURE = "E_PREFETCH_FAILURE";
private static final String ERROR_GET_SIZE_FAILURE = "E_GET_SIZE_FAILURE";
public static final String NAME = "ImageLoader";

private final Object mCallerContext;
private final Object mEnqueuedRequestMonitor = new Object();
Expand All @@ -57,7 +58,7 @@ public ImageLoaderModule(ReactApplicationContext reactContext, Object callerCont

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
/**
* Intent module. Launch other activities or open URLs.
*/
@ReactModule(name = "IntentAndroid")
@ReactModule(name = IntentModule.NAME)
public class IntentModule extends ReactContextBaseJavaModule {

public static final String NAME = "IntentAndroid";

public IntentModule(ReactApplicationContext reactContext) {
super(reactContext);
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
/**
* Native module that exposes Geolocation to JS.
*/
@ReactModule(name = "LocationObserver")
@ReactModule(name = LocationModule.NAME)
public class LocationModule extends ReactContextBaseJavaModule {

public static final String NAME = "LocationObserver";
private @Nullable String mWatchedProvider;
private static final float RCT_DEFAULT_LOCATION_ACCURACY = 100;

Expand Down Expand Up @@ -66,7 +67,7 @@ public LocationModule(ReactApplicationContext reactContext) {

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

private static class LocationOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Module that monitors and provides information about the connectivity state of the device.
*/
@ReactModule(name = "NetInfo")
@ReactModule(name = NetInfoModule.NAME)
public class NetInfoModule extends ReactContextBaseJavaModule
implements LifecycleEventListener {

Expand Down Expand Up @@ -59,6 +59,7 @@ public class NetInfoModule extends ReactContextBaseJavaModule
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />";

private static final String ERROR_MISSING_PERMISSION = "E_MISSING_PERMISSION";
public static final String NAME = "NetInfo";

private final ConnectivityManager mConnectivityManager;
private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void initialize() {

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

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
/**
* Module that exposes the Android M Permission system to JS.
*/
@ReactModule(name = "PermissionsAndroid")
@ReactModule(name = PermissionsModule.NAME)
public class PermissionsModule extends ReactContextBaseJavaModule implements PermissionListener {

private static final String ERROR_INVALID_ACTIVITY = "E_INVALID_ACTIVITY";
public static final String NAME = "PermissionsAndroid";
private final SparseArray<Callback> mCallbacks;
private int mRequestCode = 0;
private final String GRANTED = "granted";
Expand All @@ -46,7 +47,7 @@ public PermissionsModule(ReactApplicationContext reactContext) {

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
/**
* {@link NativeModule} that allows changing the appearance of the status bar.
*/
@ReactModule(name = "StatusBarManager")
@ReactModule(name = StatusBarModule.NAME)
public class StatusBarModule extends ReactContextBaseJavaModule {

private static final String HEIGHT_KEY = "HEIGHT";
public static final String NAME = "StatusBarManager";

public StatusBarModule(ReactApplicationContext reactContext) {
super(reactContext);
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public final class AsyncStorageModule
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable {

protected static final String NAME = "AsyncSQLiteDBStorage";
public static final String NAME = "AsyncSQLiteDBStorage";

// SQL variable number limit, defined by SQLITE_LIMIT_VARIABLE_NUMBER:
// https://raw.githubusercontent.com/android/platform_external_sqlite/master/dist/sqlite3.c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* {@link NativeModule} that allows JS to show a native time picker dialog and get called back when
* the user selects a time.
*/
@ReactModule(name = "TimePickerAndroid")
@ReactModule(name = TimePickerDialogModule.FRAGMENT_TAG)
public class TimePickerDialogModule extends ReactContextBaseJavaModule {

@VisibleForTesting
Expand All @@ -54,7 +54,7 @@ public TimePickerDialogModule(ReactApplicationContext reactContext) {

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

private class TimePickerDialogListener implements OnTimeSetListener, OnDismissListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* {@link NativeModule} that allows JS to show an Android Toast.
*/
@ReactModule(name = "ToastAndroid")
@ReactModule(name = ToastModule.NAME)
public class ToastModule extends ReactContextBaseJavaModule {

private static final String DURATION_SHORT_KEY = "SHORT";
Expand All @@ -30,14 +30,15 @@ public class ToastModule extends ReactContextBaseJavaModule {
private static final String GRAVITY_TOP_KEY = "TOP";
private static final String GRAVITY_BOTTOM_KEY = "BOTTOM";
private static final String GRAVITY_CENTER = "CENTER";
public static final String NAME = "ToastAndroid";

public ToastModule(ReactApplicationContext reactContext) {
super(reactContext);
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.module.annotations.ReactModule;

@ReactModule(name = "Vibration")
@ReactModule(name = VibrationModule.NAME)
public class VibrationModule extends ReactContextBaseJavaModule {

public static final String NAME = "Vibration";

public VibrationModule(ReactApplicationContext reactContext) {
super(reactContext);
}

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

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
*/
public class ARTRenderableViewManager extends ViewManager<View, ReactShadowNode> {

/* package */ static final String CLASS_GROUP = "ARTGroup";
/* package */ static final String CLASS_SHAPE = "ARTShape";
/* package */ static final String CLASS_TEXT = "ARTText";
public static final String CLASS_GROUP = "ARTGroup";
public static final String CLASS_SHAPE = "ARTShape";
public static final String CLASS_TEXT = "ARTText";

private final String mClassName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class ARTSurfaceViewManager extends
BaseViewManager<ARTSurfaceView, ARTSurfaceViewShadowNode> {

protected static final String REACT_CLASS = "ARTSurfaceView";
public static final String REACT_CLASS = "ARTSurfaceView";

private static final YogaMeasureFunction MEASURE_FUNCTION = new YogaMeasureFunction() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@ReactModule(name = ReactImageManager.REACT_CLASS)
public class ReactImageManager extends SimpleViewManager<ReactImageView> {

protected static final String REACT_CLASS = "RCTImageView";
public static final String REACT_CLASS = "RCTImageView";

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@ReactModule(name = ReactModalHostManager.REACT_CLASS)
public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView> {

protected static final String REACT_CLASS = "RCTModalHostView";
public static final String REACT_CLASS = "RCTModalHostView";

@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@ReactModule(name = ReactDialogPickerManager.REACT_CLASS)
public class ReactDialogPickerManager extends ReactPickerManager {

protected static final String REACT_CLASS = "AndroidDialogPicker";
public static final String REACT_CLASS = "AndroidDialogPicker";

@Override
public String getName() {
Expand Down
Loading

0 comments on commit 803e993

Please sign in to comment.