mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Kotlinify DefaultDevSupportManagerFactory (#43960)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43960 ## Changelog: [Internal] - As in the title. Reviewed By: NickGerleman Differential Revision: D55865794 fbshipit-source-id: e109cd28735ce2125f599b01d11f3667e3c5b033
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3422dcf55c
commit
eae5d97113
@@ -2054,9 +2054,9 @@ public class com/facebook/react/devsupport/DefaultDevLoadingViewImplementation :
|
||||
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/devsupport/DefaultDevSupportManagerFactory : com/facebook/react/devsupport/DevSupportManagerFactory {
|
||||
public final class com/facebook/react/devsupport/DefaultDevSupportManagerFactory : com/facebook/react/devsupport/DevSupportManagerFactory {
|
||||
public fun <init> ()V
|
||||
public fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZI)Lcom/facebook/react/devsupport/interfaces/DevSupportManager;
|
||||
public final fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZI)Lcom/facebook/react/devsupport/interfaces/DevSupportManager;
|
||||
public fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZLcom/facebook/react/devsupport/interfaces/RedBoxHandler;Lcom/facebook/react/devsupport/interfaces/DevBundleDownloadListener;ILjava/util/Map;Lcom/facebook/react/common/SurfaceDelegateFactory;Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;)Lcom/facebook/react/devsupport/interfaces/DevSupportManager;
|
||||
}
|
||||
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.devsupport;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.common.SurfaceDelegateFactory;
|
||||
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
|
||||
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
|
||||
import com.facebook.react.packagerconnection.RequestHandler;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A simple factory that creates instances of {@link DevSupportManager} implementations. Uses
|
||||
* reflection to create BridgeDevSupportManager if it exists. This allows ProGuard to strip that
|
||||
* class and its dependencies in release builds. If the class isn't found, {@link
|
||||
* ReleaseDevSupportManager} is returned instead.
|
||||
*/
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory {
|
||||
|
||||
private static final String DEVSUPPORT_IMPL_PACKAGE = "com.facebook.react.devsupport";
|
||||
private static final String DEVSUPPORT_IMPL_CLASS = "BridgeDevSupportManager";
|
||||
|
||||
/**
|
||||
* @deprecated in favor of the customisable create for DevSupportManagerFactory
|
||||
*/
|
||||
@Deprecated
|
||||
public DevSupportManager create(
|
||||
Context applicationContext,
|
||||
ReactInstanceDevHelper reactInstanceDevHelper,
|
||||
@Nullable String packagerPathForJSBundleName,
|
||||
boolean enableOnCreate,
|
||||
int minNumShakes) {
|
||||
|
||||
return create(
|
||||
applicationContext,
|
||||
reactInstanceDevHelper,
|
||||
packagerPathForJSBundleName,
|
||||
enableOnCreate,
|
||||
null,
|
||||
null,
|
||||
minNumShakes,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DevSupportManager create(
|
||||
Context applicationContext,
|
||||
ReactInstanceDevHelper reactInstanceManagerHelper,
|
||||
@Nullable String packagerPathForJSBundleName,
|
||||
boolean enableOnCreate,
|
||||
@Nullable RedBoxHandler redBoxHandler,
|
||||
@Nullable DevBundleDownloadListener devBundleDownloadListener,
|
||||
int minNumShakes,
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager) {
|
||||
if (!enableOnCreate) {
|
||||
return new ReleaseDevSupportManager();
|
||||
}
|
||||
// Developer support is enabled, we now must choose whether to return a DevSupportManager,
|
||||
// or a more lean profiling-only PerftestDevSupportManager. We make the choice by first
|
||||
// trying to return the full support DevSupportManager and if it fails, then just
|
||||
// return PerftestDevSupportManager.
|
||||
try {
|
||||
// ProGuard is surprisingly smart in this case and will keep a class if it detects a call to
|
||||
// Class.forName() with a static string. So instead we generate a quasi-dynamic string to
|
||||
// confuse it.
|
||||
String className =
|
||||
new StringBuilder(DEVSUPPORT_IMPL_PACKAGE)
|
||||
.append(".")
|
||||
.append(DEVSUPPORT_IMPL_CLASS)
|
||||
.toString();
|
||||
Class<?> devSupportManagerClass = Class.forName(className);
|
||||
Constructor constructor =
|
||||
devSupportManagerClass.getConstructor(
|
||||
Context.class,
|
||||
ReactInstanceDevHelper.class,
|
||||
String.class,
|
||||
boolean.class,
|
||||
RedBoxHandler.class,
|
||||
DevBundleDownloadListener.class,
|
||||
int.class,
|
||||
Map.class,
|
||||
SurfaceDelegateFactory.class,
|
||||
DevLoadingViewManager.class);
|
||||
return (DevSupportManager)
|
||||
constructor.newInstance(
|
||||
applicationContext,
|
||||
reactInstanceManagerHelper,
|
||||
packagerPathForJSBundleName,
|
||||
true,
|
||||
redBoxHandler,
|
||||
devBundleDownloadListener,
|
||||
minNumShakes,
|
||||
customPackagerCommandHandlers,
|
||||
surfaceDelegateFactory,
|
||||
devLoadingViewManager);
|
||||
} catch (Exception e) {
|
||||
return new PerftestDevSupportManager(applicationContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.devsupport
|
||||
|
||||
import android.content.Context
|
||||
import com.facebook.react.common.SurfaceDelegateFactory
|
||||
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener
|
||||
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager
|
||||
import com.facebook.react.devsupport.interfaces.RedBoxHandler
|
||||
import com.facebook.react.packagerconnection.RequestHandler
|
||||
|
||||
/**
|
||||
* A simple factory that creates instances of [DevSupportManager] implementations. Uses reflection
|
||||
* to create BridgeDevSupportManager if it exists. This allows ProGuard to strip that class and its
|
||||
* dependencies in release builds. If the class isn't found, [ ] is returned instead.
|
||||
*/
|
||||
public class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
|
||||
|
||||
@Deprecated(
|
||||
"in favor of the customisable create for DevSupportManagerFactory",
|
||||
ReplaceWith(
|
||||
"create(applicationContext, reactInstanceManagerHelper, packagerPathForJSBundleName, enableOnCreate, redBoxHandler, devBundleDownloadListener, minNumShakes, customPackagerCommandHandlers, surfaceDelegateFactory, devLoadingViewManager)"))
|
||||
public fun create(
|
||||
applicationContext: Context,
|
||||
reactInstanceDevHelper: ReactInstanceDevHelper,
|
||||
packagerPathForJSBundleName: String?,
|
||||
enableOnCreate: Boolean,
|
||||
minNumShakes: Int
|
||||
): DevSupportManager {
|
||||
return create(
|
||||
applicationContext,
|
||||
reactInstanceDevHelper,
|
||||
packagerPathForJSBundleName,
|
||||
enableOnCreate,
|
||||
null,
|
||||
null,
|
||||
minNumShakes,
|
||||
null,
|
||||
null,
|
||||
null)
|
||||
}
|
||||
|
||||
public override fun create(
|
||||
applicationContext: Context,
|
||||
reactInstanceManagerHelper: ReactInstanceDevHelper,
|
||||
packagerPathForJSBundleName: String?,
|
||||
enableOnCreate: Boolean,
|
||||
redBoxHandler: RedBoxHandler?,
|
||||
devBundleDownloadListener: DevBundleDownloadListener?,
|
||||
minNumShakes: Int,
|
||||
customPackagerCommandHandlers: Map<String, RequestHandler>?,
|
||||
surfaceDelegateFactory: SurfaceDelegateFactory?,
|
||||
devLoadingViewManager: DevLoadingViewManager?
|
||||
): DevSupportManager {
|
||||
return if (!enableOnCreate) {
|
||||
ReleaseDevSupportManager()
|
||||
} else
|
||||
try {
|
||||
// Developer support is enabled, we now must choose whether to return a DevSupportManager,
|
||||
// or a more lean profiling-only PerftestDevSupportManager. We make the choice by first
|
||||
// trying to return the full support DevSupportManager and if it fails, then just
|
||||
// return PerftestDevSupportManager.
|
||||
|
||||
// ProGuard is surprisingly smart in this case and will keep a class if it detects a call
|
||||
// to
|
||||
// Class.forName() with a static string. So instead we generate a quasi-dynamic string to
|
||||
// confuse it.
|
||||
val className =
|
||||
StringBuilder(DEVSUPPORT_IMPL_PACKAGE)
|
||||
.append(".")
|
||||
.append(DEVSUPPORT_IMPL_CLASS)
|
||||
.toString()
|
||||
val devSupportManagerClass = Class.forName(className)
|
||||
val constructor =
|
||||
devSupportManagerClass.getConstructor(
|
||||
Context::class.java,
|
||||
ReactInstanceDevHelper::class.java,
|
||||
String::class.java,
|
||||
Boolean::class.javaPrimitiveType,
|
||||
RedBoxHandler::class.java,
|
||||
DevBundleDownloadListener::class.java,
|
||||
Int::class.javaPrimitiveType,
|
||||
MutableMap::class.java,
|
||||
SurfaceDelegateFactory::class.java,
|
||||
DevLoadingViewManager::class.java)
|
||||
constructor.newInstance(
|
||||
applicationContext,
|
||||
reactInstanceManagerHelper,
|
||||
packagerPathForJSBundleName,
|
||||
true,
|
||||
redBoxHandler,
|
||||
devBundleDownloadListener,
|
||||
minNumShakes,
|
||||
customPackagerCommandHandlers,
|
||||
surfaceDelegateFactory,
|
||||
devLoadingViewManager) as DevSupportManager
|
||||
} catch (e: Exception) {
|
||||
PerftestDevSupportManager(applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val DEVSUPPORT_IMPL_PACKAGE = "com.facebook.react.devsupport"
|
||||
private const val DEVSUPPORT_IMPL_CLASS = "BridgeDevSupportManager"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user