Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add devSupportFactory for new arch #37

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.facebook.react.common.annotations

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ package com.facebook.react.devsupport

import android.content.Context
import com.facebook.react.common.SurfaceDelegateFactory
import com.facebook.react.common.annotations.FrameworkAPI
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.PausedInDebuggerOverlayManager
import com.facebook.react.devsupport.interfaces.RedBoxHandler
import com.facebook.react.packagerconnection.RequestHandler
import com.facebook.react.runtime.BridgelessDevSupportManager
import com.facebook.react.runtime.ReactHostImpl

/**
* A simple factory that creates instances of [DevSupportManager] implementations. Uses reflection
Expand All @@ -23,93 +26,102 @@ import com.facebook.react.packagerconnection.RequestHandler
*/
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, pausedInDebuggerOverlayManager)"))
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,
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?,
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?
applicationContext: Context,
reactInstanceManagerHelper: ReactInstanceDevHelper,
packagerPathForJSBundleName: String?,
enableOnCreate: Boolean,
redBoxHandler: RedBoxHandler?,
devBundleDownloadListener: DevBundleDownloadListener?,
minNumShakes: Int,
customPackagerCommandHandlers: Map<String, RequestHandler>?,
surfaceDelegateFactory: SurfaceDelegateFactory?,
devLoadingViewManager: DevLoadingViewManager?,
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?
): 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.
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,
PausedInDebuggerOverlayManager::class.java)
constructor.newInstance(
applicationContext,
reactInstanceManagerHelper,
packagerPathForJSBundleName,
true,
redBoxHandler,
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory,
devLoadingViewManager,
pausedInDebuggerOverlayManager) as DevSupportManager
} catch (e: Exception) {
PerftestDevSupportManager(applicationContext)
}
// 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,
PausedInDebuggerOverlayManager::class.java)
constructor.newInstance(
applicationContext,
reactInstanceManagerHelper,
packagerPathForJSBundleName,
true,
redBoxHandler,
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory,
devLoadingViewManager,
pausedInDebuggerOverlayManager) as DevSupportManager
} catch (e: Exception) {
PerftestDevSupportManager(applicationContext)
}
}

@FrameworkAPI
override fun create(
reactHost: ReactHostImpl,
applicationContext: Context,
reactInstanceManagerHelper: ReactInstanceDevHelper,
packagerPathForJSBundleName: String?,
enableOnCreate: Boolean,
redBoxHandler: RedBoxHandler?,
devBundleDownloadListener: DevBundleDownloadListener?,
minNumShakes: Int,
customPackagerCommandHandlers: MutableMap<String, RequestHandler>?,
surfaceDelegateFactory: SurfaceDelegateFactory?,
devLoadingViewManager: DevLoadingViewManager?,
pausedInDebuggerOverlayManager: PausedInDebuggerOverlayManager?,
useDevSupport: Boolean
): DevSupportManager =
if (!useDevSupport) {
ReleaseDevSupportManager()
} else {
BridgelessDevSupportManager(
reactHost,
applicationContext,
reactInstanceManagerHelper,
packagerPathForJSBundleName,
enableOnCreate,
redBoxHandler,
devBundleDownloadListener,
minNumShakes,
customPackagerCommandHandlers,
surfaceDelegateFactory,
devLoadingViewManager,
pausedInDebuggerOverlayManager)
}

private companion object {
private const val DEVSUPPORT_IMPL_PACKAGE = "com.facebook.react.devsupport"
private const val DEVSUPPORT_IMPL_CLASS = "BridgeDevSupportManager"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,43 @@
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager;
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
import com.facebook.react.packagerconnection.RequestHandler;
import com.facebook.react.runtime.ReactHostImpl;
import java.util.Map;

public interface DevSupportManagerFactory {
/**
* Factory used by the Old Architecture flow to create a {@link DevSupportManager} and a {@link
* com.facebook.react.runtime.BridgeDevSupportManager}
*/
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,
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager);
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,
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager);

/**
* Factory used by the New Architecture/Bridgeless flow to create a {@link DevSupportManager} and
* a {@link com.facebook.react.runtime.BridgelessDevSupportManager}
*/
DevSupportManager create(
ReactHostImpl host,
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,
@Nullable PausedInDebuggerOverlayManager pausedInDebuggerOverlayManager,
boolean useDevSupport);
}
Loading
Loading