Skip to content

Commit

Permalink
Add Android implementation for DevMenu Module (#46694)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46694

The DevMenu module was never implemented on Android. This adds its implementation by mirroring the iOS implementation.

Fixes #46679

Changelog:
[Android] [Fixed] - Add missing Android implementation for DevMenu Module

Reviewed By: cipolleschi

Differential Revision: D63535172

fbshipit-source-id: 791e72b46b7d3264b98e85a73f2d9025dc3a2c7d
  • Loading branch information
cortinico authored and facebook-github-bot committed Sep 27, 2024
1 parent 8bfd7e1 commit 1bdae07
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3310,6 +3310,15 @@ public final class com/facebook/react/modules/core/TimingModule : com/facebook/f
public final class com/facebook/react/modules/core/TimingModule$Companion {
}

public final class com/facebook/react/modules/debug/DevMenuModule : com/facebook/fbreact/specs/NativeDevMenuSpec {
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
public fun debugRemotely (Z)V
public fun reload ()V
public fun setHotLoadingEnabled (Z)V
public fun setProfilingEnabled (Z)V
public fun show ()V
}

public final class com/facebook/react/modules/debug/DevSettingsModule : com/facebook/fbreact/specs/NativeDevSettingsSpec {
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/devsupport/interfaces/DevSupportManager;)V
public fun addListener (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.facebook.react.modules.core.ExceptionsManagerModule;
import com.facebook.react.modules.core.HeadlessJsTaskSupportModule;
import com.facebook.react.modules.core.TimingModule;
import com.facebook.react.modules.debug.DevMenuModule;
import com.facebook.react.modules.debug.DevSettingsModule;
import com.facebook.react.modules.debug.SourceCodeModule;
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
Expand All @@ -49,6 +50,7 @@
AndroidInfoModule.class,
DeviceEventManagerModule.class,
DeviceInfoModule.class,
DevMenuModule.class,
DevSettingsModule.class,
ExceptionsManagerModule.class,
LogBoxModule.class,
Expand Down Expand Up @@ -108,6 +110,7 @@ private ReactModuleInfoProvider fallbackForMissingClass() {
AndroidInfoModule.class,
DeviceEventManagerModule.class,
DeviceInfoModule.class,
DevMenuModule.class,
DevSettingsModule.class,
ExceptionsManagerModule.class,
LogBoxModule.class,
Expand Down Expand Up @@ -142,6 +145,8 @@ public NativeModule getModule(String name, ReactApplicationContext reactContext)
return new AndroidInfoModule(reactContext);
case DeviceEventManagerModule.NAME:
return new DeviceEventManagerModule(reactContext, mHardwareBackBtnHandler);
case DevMenuModule.NAME:
return new DevMenuModule(reactContext, mReactInstanceManager.getDevSupportManager());
case DevSettingsModule.NAME:
return new DevSettingsModule(reactContext, mReactInstanceManager.getDevSupportManager());
case ExceptionsManagerModule.NAME:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.modules.debug

import com.facebook.fbreact.specs.NativeDevMenuSpec
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.module.annotations.ReactModule

/** Module that exposes the DevMenu to JS so that it can be used to programmatically open it. */
@ReactModule(name = NativeDevMenuSpec.NAME)
public class DevMenuModule(
reactContext: ReactApplicationContext?,
private val devSupportManager: DevSupportManager
) : NativeDevMenuSpec(reactContext) {

override fun show() {
if (devSupportManager.devSupportEnabled) {
devSupportManager.showDevOptionsDialog()
}
}

override fun reload() {
if (devSupportManager.devSupportEnabled) {
UiThreadUtil.runOnUiThread { devSupportManager.handleReloadJS() }
}
}

override fun debugRemotely(enableDebug: Boolean) {
devSupportManager.setRemoteJSDebugEnabled(enableDebug)
}

override fun setProfilingEnabled(enabled: Boolean) {
// iOS only
}

override fun setHotLoadingEnabled(enabled: Boolean) {
devSupportManager.setHotModuleReplacementEnabled(enabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.ExceptionsManagerModule;
import com.facebook.react.modules.debug.DevMenuModule;
import com.facebook.react.modules.debug.DevSettingsModule;
import com.facebook.react.modules.debug.SourceCodeModule;
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
Expand All @@ -35,6 +36,7 @@
nativeModules = {
AndroidInfoModule.class,
DeviceInfoModule.class,
DevMenuModule.class,
DevSettingsModule.class,
SourceCodeModule.class,
LogBoxModule.class,
Expand All @@ -61,6 +63,8 @@ public CoreReactPackage(
return new DeviceInfoModule(reactContext);
case SourceCodeModule.NAME:
return new SourceCodeModule(reactContext);
case DevMenuModule.NAME:
return new DevMenuModule(reactContext, mDevSupportManager);
case DevSettingsModule.NAME:
return new DevSettingsModule(reactContext, mDevSupportManager);
case DeviceEventManagerModule.NAME:
Expand Down Expand Up @@ -108,6 +112,7 @@ private ReactModuleInfoProvider fallbackForMissingClass() {
AndroidInfoModule.class,
DeviceInfoModule.class,
SourceCodeModule.class,
DevMenuModule.class,
DevSettingsModule.class,
DeviceEventManagerModule.class,
LogBoxModule.class,
Expand Down

0 comments on commit 1bdae07

Please sign in to comment.