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

Kotlinify MemoryPressure* #43961

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;
package com.facebook.react.bridge

public enum MemoryPressure {
public enum class MemoryPressure {
UI_HIDDEN,
MODERATE,
CRITICAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;
package com.facebook.react.bridge

/** Listener interface for memory pressure events. */
public interface MemoryPressureListener {

/** Called when the system generates a memory warning. */
void handleMemoryPressure(int level);
public fun handleMemoryPressure(level: Int)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.image;
package com.facebook.react.views.image

import android.net.Uri;
import android.net.Uri

/** Listener interface for global image loading events. */
public interface GlobalImageLoadListener {

/** Called when a source has been set on an ImageView, but before it is actually loaded. */
void onLoadAttempt(Uri uri);
public fun onLoadAttempt(uri: Uri?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.views.image

/**
* This interface is used from [ReactImageManager] to customize the CallerContext object associated
* with each instance of [ReactImageView].
*/
public fun interface ReactCallerContextFactory {
/**
* This method will be called at the time [ReactImageManager] creates [ReactImageView]
*
* @param surfaceName [String] used to log the name of the surface
* @return an [Object] that represents the CallerContext.
*/
public fun getOrCreateCallerContext(surfaceName: String?, analyticTag: String?): Any?
}
Loading
Loading