mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-30 14:02:44 +08:00
android: allow registering custom packager command handlers
Summary: @public Apps may need to listen for custom commands via the packager connection. This allows registering such listeners. Reviewed By: raluca-elena Differential Revision: D8654477 fbshipit-source-id: 5f17298a88fec31b8939236fef48ee46c0ba2ee8
This commit is contained in:
committed by
Facebook Github Bot
parent
bc2f12c68c
commit
b3ef1c3a56
@@ -81,6 +81,13 @@ public class DevServerHelper {
|
||||
void onPackagerReloadCommand();
|
||||
void onPackagerDevMenuCommand();
|
||||
void onCaptureHeapCommand(final Responder responder);
|
||||
|
||||
// Allow apps to provide listeners for custom packager commands.
|
||||
@Nullable Map<String, RequestHandler> customCommandHandlers();
|
||||
}
|
||||
|
||||
public interface PackagerCustomCommandProvider {
|
||||
|
||||
}
|
||||
|
||||
public interface SymbolicationListener {
|
||||
@@ -162,6 +169,10 @@ public class DevServerHelper {
|
||||
commandListener.onCaptureHeapCommand(responder);
|
||||
}
|
||||
});
|
||||
Map<String, RequestHandler> customHandlers = commandListener.customCommandHandlers();
|
||||
if (customHandlers != null) {
|
||||
handlers.putAll(customHandlers);
|
||||
}
|
||||
handlers.putAll(new FileIoHandler().handlers());
|
||||
|
||||
ConnectionCallback onPackagerConnectedCallback =
|
||||
|
||||
@@ -11,8 +11,10 @@ import android.content.Context;
|
||||
|
||||
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.packagerconnection.RequestHandler;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -41,7 +43,8 @@ public class DevSupportManagerFactory {
|
||||
enableOnCreate,
|
||||
null,
|
||||
null,
|
||||
minNumShakes);
|
||||
minNumShakes,
|
||||
null);
|
||||
}
|
||||
|
||||
public static DevSupportManager create(
|
||||
@@ -51,7 +54,8 @@ public class DevSupportManagerFactory {
|
||||
boolean enableOnCreate,
|
||||
@Nullable RedBoxHandler redBoxHandler,
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes) {
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
|
||||
if (!enableOnCreate) {
|
||||
return new DisabledDevSupportManager();
|
||||
}
|
||||
@@ -74,7 +78,8 @@ public class DevSupportManagerFactory {
|
||||
boolean.class,
|
||||
RedBoxHandler.class,
|
||||
DevBundleDownloadListener.class,
|
||||
int.class);
|
||||
int.class,
|
||||
Map.class);
|
||||
return (DevSupportManager) constructor.newInstance(
|
||||
applicationContext,
|
||||
reactInstanceManagerHelper,
|
||||
@@ -82,7 +87,8 @@ public class DevSupportManagerFactory {
|
||||
true,
|
||||
redBoxHandler,
|
||||
devBundleDownloadListener,
|
||||
minNumShakes);
|
||||
minNumShakes,
|
||||
customPackagerCommandHandlers);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found" +
|
||||
|
||||
@@ -60,6 +60,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -150,6 +151,8 @@ public class DevSupportManagerImpl implements
|
||||
|
||||
private InspectorPackagerConnection.BundleStatus mBundleStatus;
|
||||
|
||||
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
|
||||
|
||||
private static class JscProfileTask extends AsyncTask<String, Void, Void> {
|
||||
private static final MediaType JSON =
|
||||
MediaType.parse("application/json; charset=utf-8");
|
||||
@@ -196,7 +199,8 @@ public class DevSupportManagerImpl implements
|
||||
enableOnCreate,
|
||||
null,
|
||||
null,
|
||||
minNumShakes);
|
||||
minNumShakes,
|
||||
null);
|
||||
}
|
||||
|
||||
public DevSupportManagerImpl(
|
||||
@@ -206,7 +210,8 @@ public class DevSupportManagerImpl implements
|
||||
boolean enableOnCreate,
|
||||
@Nullable RedBoxHandler redBoxHandler,
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes) {
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers) {
|
||||
mReactInstanceManagerHelper = reactInstanceManagerHelper;
|
||||
mApplicationContext = applicationContext;
|
||||
mJSAppBundleName = packagerPathForJSBundleName;
|
||||
@@ -232,6 +237,8 @@ public class DevSupportManagerImpl implements
|
||||
}
|
||||
}, minNumShakes);
|
||||
|
||||
mCustomPackagerCommandHandlers = customPackagerCommandHandlers;
|
||||
|
||||
// Prepare reload APP broadcast receiver (will be registered/unregistered from #reload)
|
||||
mReloadAppBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -841,6 +848,11 @@ public class DevSupportManagerImpl implements
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Map<String, RequestHandler> customCommandHandlers() {
|
||||
return mCustomPackagerCommandHandlers;
|
||||
}
|
||||
|
||||
private void handleCaptureHeap(final Responder responder) {
|
||||
if (mCurrentContext == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user