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

Introduce experimental image prefetching API #47755

Closed
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,7 @@ public class com/facebook/react/fabric/mounting/MountingManager {
public fun attachRootView (ILandroid/view/View;Lcom/facebook/react/uimanager/ThemedReactContext;)V
public fun clearJSResponder ()V
public fun enqueuePendingEvent (IILjava/lang/String;ZLcom/facebook/react/bridge/WritableMap;I)V
public fun experimental_prefetchResource (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;IILcom/facebook/react/common/mapbuffer/MapBuffer;)V
public fun getEventEmitter (II)Lcom/facebook/react/fabric/events/EventEmitterWrapper;
public fun getSurfaceManager (I)Lcom/facebook/react/fabric/mounting/SurfaceMountingManager;
public fun getSurfaceManagerEnforced (ILjava/lang/String;)Lcom/facebook/react/fabric/mounting/SurfaceMountingManager;
Expand Down Expand Up @@ -5281,6 +5282,8 @@ public abstract class com/facebook/react/uimanager/ViewManager : com/facebook/re
public fun createView (ILcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/touch/JSResponderHandler;)Landroid/view/View;
protected fun createViewInstance (ILcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Landroid/view/View;
protected abstract fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
protected fun experimental_isPrefetchingEnabled ()Z
public fun experimental_prefetchResource (Lcom/facebook/react/bridge/ReactContext;IILcom/facebook/react/common/mapbuffer/MapBuffer;)V
public fun getCommandsMap ()Ljava/util/Map;
protected fun getDelegate ()Lcom/facebook/react/uimanager/ViewManagerDelegate;
public fun getExportedCustomBubblingEventTypeConstants ()Ljava/util/Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,28 @@ public long measureMapBuffer(
attachmentsPositions);
}

/**
* @deprecated THIS PREFETCH METHOD IS EXPERIMENTAL, DO NOT USE IT FOR PRODUCTION CODE. IT WILL
* MOST LIKELY CHANGE OR BE REMOVED IN THE FUTURE.
* @param reactContext
* @param componentName
* @param surfaceId {@link int} surface ID
* @param reactTag reactTag that should be set as ID of the view instance
* @param params {@link MapBuffer} prefetch request params defined in C++
*/
@AnyThread
@Deprecated
public void experimental_prefetchResource(
ReactContext reactContext,
String componentName,
int surfaceId,
int reactTag,
MapBuffer params) {
mViewManagerRegistry
.get(componentName)
.experimental_prefetchResource(reactContext, surfaceId, reactTag, params);
}

public void enqueuePendingEvent(
int surfaceId,
int reactTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b1ad8179cf22c2e97f623435bf152aab>>
* @generated SignedSource<<6d8d8f4b81d7be882b315d0960499dcb>>
*/

/**
Expand Down Expand Up @@ -130,6 +130,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableIOSViewClipToPaddingBox(): Boolean = accessor.enableIOSViewClipToPaddingBox()

/**
* When enabled, Andoid will build and initiate image prefetch requests on ImageShadowNode::layout
*/
@JvmStatic
public fun enableImagePrefetchingAndroid(): Boolean = accessor.enableImagePrefetchingAndroid()

/**
* When enabled, LayoutAnimations API will animate state changes on Android.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7dd21b62dfe429aecdbd179cb482fb26>>
* @generated SignedSource<<031fce8e8b4c20a3e3d6dbecf94d138a>>
*/

/**
Expand Down Expand Up @@ -37,6 +37,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var enableFixForViewCommandRaceCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
private var enableImagePrefetchingAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
Expand Down Expand Up @@ -219,6 +220,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun enableImagePrefetchingAndroid(): Boolean {
var cached = enableImagePrefetchingAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableImagePrefetchingAndroid()
enableImagePrefetchingAndroidCache = cached
}
return cached
}

override fun enableLayoutAnimationsOnAndroid(): Boolean {
var cached = enableLayoutAnimationsOnAndroidCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fcfded14a5fe05501892993c1f58f3ed>>
* @generated SignedSource<<35811667ac2543e1f64e27bbdb483ec1>>
*/

/**
Expand Down Expand Up @@ -62,6 +62,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableIOSViewClipToPaddingBox(): Boolean

@DoNotStrip @JvmStatic public external fun enableImagePrefetchingAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableLayoutAnimationsOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableLayoutAnimationsOnIOS(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<86d8dd894e80a788af7f47172d30d33c>>
* @generated SignedSource<<9d829c58e49164a0b2b6b66bc0ce088a>>
*/

/**
Expand Down Expand Up @@ -57,6 +57,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableIOSViewClipToPaddingBox(): Boolean = false

override fun enableImagePrefetchingAndroid(): Boolean = false

override fun enableLayoutAnimationsOnAndroid(): Boolean = false

override fun enableLayoutAnimationsOnIOS(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4bb5173b9ba1d3e620f3a7d613b27ac7>>
* @generated SignedSource<<0121e113410a5b0e14eaf74a3076df2f>>
*/

/**
Expand Down Expand Up @@ -41,6 +41,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var enableFixForViewCommandRaceCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
private var enableImagePrefetchingAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
Expand Down Expand Up @@ -240,6 +241,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableImagePrefetchingAndroid(): Boolean {
var cached = enableImagePrefetchingAndroidCache
if (cached == null) {
cached = currentProvider.enableImagePrefetchingAndroid()
accessedFeatureFlags.add("enableImagePrefetchingAndroid")
enableImagePrefetchingAndroidCache = cached
}
return cached
}

override fun enableLayoutAnimationsOnAndroid(): Boolean {
var cached = enableLayoutAnimationsOnAndroidCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2217f2b9992c9424c3d1d221bdfa2236>>
* @generated SignedSource<<2787d9027695dd14ec6b917a32a1a6de>>
*/

/**
Expand Down Expand Up @@ -57,6 +57,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableIOSViewClipToPaddingBox(): Boolean

@DoNotStrip public fun enableImagePrefetchingAndroid(): Boolean

@DoNotStrip public fun enableLayoutAnimationsOnAndroid(): Boolean

@DoNotStrip public fun enableLayoutAnimationsOnIOS(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.mapbuffer.MapBuffer;
Expand Down Expand Up @@ -488,4 +489,25 @@ public void onSurfaceStopped(int surfaceId) {
mRecyclableViews = new HashMap<>();
}
}

/**
* @deprecated THIS PREFETCH METHOD IS EXPERIMENTAL, DO NOT USE IT FOR PRODUCTION CODE, MOST
* LIKELY IT WILL CHANGE OR BE REMOVED IN THE FUTURE.
* <p>Subclasses can override this method to implement custom resource prefetching for the
* ViewManager.
* @param reactContext {@link com.facebook.react.bridge.ReactContext} used for the view.
* @param surfaceId {@link int} surface ID
* @param reactTag reactTag that should be set as ID of the view instance
* @param params {@link MapBuffer} prefetch request params defined in C++
*/
@Deprecated
public void experimental_prefetchResource(
ReactContext reactContext, int surfaceId, int reactTag, MapBuffer params) {
return;
}

@Deprecated
protected boolean experimental_isPrefetchingEnabled() {
return ReactNativeFeatureFlags.enableImagePrefetchingAndroid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<d5ccaecdf8cc2cf6144409658d9076ae>>
* @generated SignedSource<<902b269e45fcb4970c6f8a86818e1940>>
*/

/**
Expand Down Expand Up @@ -141,6 +141,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool enableImagePrefetchingAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableImagePrefetchingAndroid");
return method(javaProvider_);
}

bool enableLayoutAnimationsOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableLayoutAnimationsOnAndroid");
Expand Down Expand Up @@ -398,6 +404,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableIOSViewClipToPaddingBox(
return ReactNativeFeatureFlags::enableIOSViewClipToPaddingBox();
}

bool JReactNativeFeatureFlagsCxxInterop::enableImagePrefetchingAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableImagePrefetchingAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid();
Expand Down Expand Up @@ -620,6 +631,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableIOSViewClipToPaddingBox",
JReactNativeFeatureFlagsCxxInterop::enableIOSViewClipToPaddingBox),
makeNativeMethod(
"enableImagePrefetchingAndroid",
JReactNativeFeatureFlagsCxxInterop::enableImagePrefetchingAndroid),
makeNativeMethod(
"enableLayoutAnimationsOnAndroid",
JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnAndroid),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<0b07eaeba8112f65ecb18d53b7b893af>>
* @generated SignedSource<<17da0d7937c5c0c533293b86c8cdc9be>>
*/

/**
Expand Down Expand Up @@ -81,6 +81,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableIOSViewClipToPaddingBox(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableImagePrefetchingAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableLayoutAnimationsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<90e3ea3abb6f13c711aec3754ab03126>>
* @generated SignedSource<<ef215623465d45c563030d724287b1c9>>
*/

/**
Expand Down Expand Up @@ -94,6 +94,10 @@ bool ReactNativeFeatureFlags::enableIOSViewClipToPaddingBox() {
return getAccessor().enableIOSViewClipToPaddingBox();
}

bool ReactNativeFeatureFlags::enableImagePrefetchingAndroid() {
return getAccessor().enableImagePrefetchingAndroid();
}

bool ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid() {
return getAccessor().enableLayoutAnimationsOnAndroid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4544b1e206765808859ef84c2e6333a9>>
* @generated SignedSource<<f741660e4cf2528defe0ab1f61858aab>>
*/

/**
Expand Down Expand Up @@ -124,6 +124,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableIOSViewClipToPaddingBox();

/**
* When enabled, Andoid will build and initiate image prefetch requests on ImageShadowNode::layout
*/
RN_EXPORT static bool enableImagePrefetchingAndroid();

/**
* When enabled, LayoutAnimations API will animate state changes on Android.
*/
Expand Down
Loading
Loading