|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.react.modules.debug; |
| 9 | + |
| 10 | +import com.facebook.react.bridge.BaseJavaModule; |
| 11 | +import com.facebook.react.bridge.ReactContextBaseJavaModule; |
| 12 | +import com.facebook.react.bridge.ReactMethod; |
| 13 | +import com.facebook.react.devsupport.interfaces.DevSupportManager; |
| 14 | +import com.facebook.react.module.annotations.ReactModule; |
| 15 | +import com.facebook.react.bridge.UiThreadUtil; |
| 16 | + |
| 17 | +/** |
| 18 | + * Module that exposes the URL to the source code map (used for exception stack trace parsing) to JS |
| 19 | + */ |
| 20 | +@ReactModule(name = DevSettingsModule.NAME) |
| 21 | +public class DevSettingsModule extends BaseJavaModule { |
| 22 | + |
| 23 | + public static final String NAME = "DevSettings"; |
| 24 | + |
| 25 | + private final DevSupportManager mDevSupportManager; |
| 26 | + |
| 27 | + public DevSettingsModule(DevSupportManager devSupportManager) { |
| 28 | + mDevSupportManager = devSupportManager; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public String getName() { |
| 33 | + return NAME; |
| 34 | + } |
| 35 | + |
| 36 | + @ReactMethod |
| 37 | + public void reload() { |
| 38 | + if (mDevSupportManager.getDevSupportEnabled()) { |
| 39 | + UiThreadUtil.runOnUiThread(new Runnable() { |
| 40 | + @Override |
| 41 | + public void run() { |
| 42 | + mDevSupportManager.handleReloadJS(); |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @ReactMethod |
| 49 | + public void setHotLoadingEnabled(boolean isHotLoadingEnabled) { |
| 50 | + mDevSupportManager.setHotModuleReplacementEnabled(isHotLoadingEnabled); |
| 51 | + } |
| 52 | + |
| 53 | + @ReactMethod |
| 54 | + public void setIsDebuggingRemotely(boolean isDebugginRemotelyEnabled) { |
| 55 | + mDevSupportManager.setRemoteJSDebugEnabled(isDebugginRemotelyEnabled); |
| 56 | + } |
| 57 | + |
| 58 | + @ReactMethod |
| 59 | + public void setLiveReloadEnabled(boolean isLiveReloadEnabled) { |
| 60 | + mDevSupportManager.setReloadOnJSChangeEnabled(isLiveReloadEnabled); |
| 61 | + } |
| 62 | + |
| 63 | + @ReactMethod |
| 64 | + public void setProfilingEnabled(boolean isProfilingEnabled) { |
| 65 | + mDevSupportManager.setFpsDebugEnabled(isProfilingEnabled); |
| 66 | + } |
| 67 | + |
| 68 | + @ReactMethod |
| 69 | + public void toggleElementInspector() { |
| 70 | + mDevSupportManager.toggleElementInspector(); |
| 71 | + } |
| 72 | +} |
0 commit comments