Skip to content

Commit

Permalink
Android
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jul 28, 2019
1 parent 7dd6dee commit 7d0964c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public NativeModule getModule(String name, ReactApplicationContext reactContext)
case DeviceEventManagerModule.NAME:
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
case DevSettingsModule.NAME:
return new DevSettingsModule(mReactInstanceManager.getDevSupportManager());
return new DevSettingsModule(reactContext, mReactInstanceManager.getDevSupportManager());
case ExceptionsManagerModule.NAME:
return new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager());
case HeadlessJsTaskSupportModule.NAME:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) {
mPreferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply();
}

@Override
public void addMenuItem(String title) {
// Not supported.
}

public interface Listener {
void onInternalSettingsChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@
*/
package com.facebook.react.modules.debug;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

/**
* Module that exposes the URL to the source code map (used for exception stack trace parsing) to JS
*/
@ReactModule(name = DevSettingsModule.NAME)
public class DevSettingsModule extends BaseJavaModule {
public class DevSettingsModule extends ReactContextBaseJavaModule {

public static final String NAME = "DevSettings";

private final DevSupportManager mDevSupportManager;

public DevSettingsModule(DevSupportManager devSupportManager) {
public DevSettingsModule(ReactApplicationContext reactContext, DevSupportManager devSupportManager) {
super(reactContext);

mDevSupportManager = devSupportManager;
}

Expand Down Expand Up @@ -68,4 +75,18 @@ public void setProfilingEnabled(boolean isProfilingEnabled) {
public void toggleElementInspector() {
mDevSupportManager.toggleElementInspector();
}

@ReactMethod
public void addMenuItem(String title) {
mDevSupportManager.addCustomDevOption(title, new DevOptionHandler() {
@Override
public void onOptionSelected() {
WritableMap data = Arguments.createMap();
data.putString("title", title);
getReactApplicationContext()
.getJSModule(RCTDeviceEventEmitter.class)
.emit("didPressMenuItem", data);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ public interface DeveloperSettings {

/** Enable/Disable remote JS debugging. */
void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled);

/** Add an item to the dev menu. */
void addMenuItem(String title);
}

0 comments on commit 7d0964c

Please sign in to comment.