Skip to content

Commit

Permalink
Add enableImagePrefetchingAndroid to ReactNativeFeatureFlags (#47755)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #47755

TIA.
Changelog: [Internal]

Differential Revision: D65596686
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Nov 20, 2024
1 parent 88b27fa commit cc0382b
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 19 deletions.
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<<ee42281fb9796bed1fd93755c0bcbff1>>
*/

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

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

/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
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<<0018102b7a8cf32cf7fc8d03306ed923>>
*/

/**
Expand Down Expand Up @@ -65,6 +65,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useTurboModulesCache: Boolean? = null
private var enableImagePrefetchingAndroidCache: Boolean? = null

override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
Expand Down Expand Up @@ -471,6 +472,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 override(provider: ReactNativeFeatureFlagsProvider): Unit =
ReactNativeFeatureFlagsCxxInterop.override(provider as Any)

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<<3ba2c93bb4bcf6b975bbdd1d809751fb>>
*/

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

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

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

@DoNotStrip @JvmStatic public external fun override(provider: Any)

@DoNotStrip @JvmStatic public external fun dangerouslyReset()
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<<32cc634efb851112e7c84738d4865efa>>
*/

/**
Expand Down Expand Up @@ -112,4 +112,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun useTurboModuleInterop(): Boolean = false

override fun useTurboModules(): Boolean = false

override fun enableImagePrefetchingAndroid(): Boolean = false
}
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<<1bb12e58bc6a646d703437df3bccad0a>>
*/

/**
Expand Down Expand Up @@ -69,6 +69,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useTurboModuleInteropCache: Boolean? = null
private var useTurboModulesCache: Boolean? = null
private var enableImagePrefetchingAndroidCache: Boolean? = null

override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
Expand Down Expand Up @@ -520,6 +521,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 override(provider: ReactNativeFeatureFlagsProvider) {
if (accessedFeatureFlags.isNotEmpty()) {
val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it }
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<<97d18c49fd8c1e8445c3df37b809d41b>>
*/

/**
Expand Down Expand Up @@ -112,4 +112,6 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun useTurboModuleInterop(): Boolean

@DoNotStrip public fun useTurboModules(): Boolean

@DoNotStrip public fun enableImagePrefetchingAndroid(): Boolean
}
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<<bf20919f04656c8600fbafe4080aad64>>
*/

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

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

private:
jni::global_ref<jobject> javaProvider_;
};
Expand Down Expand Up @@ -538,6 +544,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useTurboModules(
return ReactNativeFeatureFlags::useTurboModules();
}

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

void JReactNativeFeatureFlagsCxxInterop::override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/,
jni::alias_ref<jobject> provider) {
Expand Down Expand Up @@ -704,6 +715,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"useTurboModules",
JReactNativeFeatureFlagsCxxInterop::useTurboModules),
makeNativeMethod(
"enableImagePrefetchingAndroid",
JReactNativeFeatureFlagsCxxInterop::enableImagePrefetchingAndroid),
});
}

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<<8f4ef3aff65c6c6b5259edcd5b0b267f>>
*/

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

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

static void override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>,
jni::alias_ref<jobject> provider);
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<<202cfb76de94becae47e956ec7e17b64>>
*/

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

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

void ReactNativeFeatureFlags::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
getAccessor().override(std::move(provider));
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<<3cb95ebc1c83bc6dd8faefe0857020f9>>
*/

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

/**
* When enabled, Andoid will create and start image prefetch request on ImageShadowNode::layout
*/
RN_EXPORT static bool enableImagePrefetchingAndroid();

/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
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<<cd77cfb18c0099b88035ff42fcd2dd46>>
* @generated SignedSource<<3e93e134cf50f9971089c9f344d580d3>>
*/

/**
Expand Down Expand Up @@ -839,6 +839,24 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModules() {
return flagValue.value();
}

bool ReactNativeFeatureFlagsAccessor::enableImagePrefetchingAndroid() {
auto flagValue = enableImagePrefetchingAndroid_.load();

if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(45, "enableImagePrefetchingAndroid");

flagValue = currentProvider_->enableImagePrefetchingAndroid();
enableImagePrefetchingAndroid_ = flagValue;
}

return flagValue.value();
}

void ReactNativeFeatureFlagsAccessor::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
if (wasOverridden_) {
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<<6f11d494553e3f12b2ca326a880746f3>>
* @generated SignedSource<<664bd38e988465f8d323ae4a223cbab7>>
*/

/**
Expand Down Expand Up @@ -77,6 +77,7 @@ class ReactNativeFeatureFlagsAccessor {
bool useRuntimeShadowNodeReferenceUpdate();
bool useTurboModuleInterop();
bool useTurboModules();
bool enableImagePrefetchingAndroid();

void override(std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
std::optional<std::string> getAccessedFeatureFlagNames() const;
Expand All @@ -88,7 +89,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;

std::array<std::atomic<const char*>, 45> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 46> accessedFeatureFlags_;

std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> completeReactInstanceCreationOnBgThreadOnAndroid_;
Expand Down Expand Up @@ -135,6 +136,7 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> useRuntimeShadowNodeReferenceUpdate_;
std::atomic<std::optional<bool>> useTurboModuleInterop_;
std::atomic<std::optional<bool>> useTurboModules_;
std::atomic<std::optional<bool>> enableImagePrefetchingAndroid_;
};

} // namespace facebook::react
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<<213e1ad83360a79e27d41c06e20fb8c9>>
* @generated SignedSource<<0d007c42c0ef8b2848a49f65cc360d3d>>
*/

/**
Expand Down Expand Up @@ -206,6 +206,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
bool useTurboModules() override {
return false;
}

bool enableImagePrefetchingAndroid() override {
return false;
}
};

} // namespace facebook::react
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<<5b2b2aba574e77851ad214809ead9228>>
* @generated SignedSource<<ed548023a7b40d4b93ef743f7a49807f>>
*/

/**
Expand Down Expand Up @@ -70,6 +70,7 @@ class ReactNativeFeatureFlagsProvider {
virtual bool useRuntimeShadowNodeReferenceUpdate() = 0;
virtual bool useTurboModuleInterop() = 0;
virtual bool useTurboModules() = 0;
virtual bool enableImagePrefetchingAndroid() = 0;
};

} // namespace facebook::react
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<<aeb742608efce797a86b73e243a62d0c>>
* @generated SignedSource<<9817d1122862f357bed3979f342f8704>>
*/

/**
Expand Down Expand Up @@ -269,4 +269,9 @@ bool NativeReactNativeFeatureFlags::useTurboModules(
return ReactNativeFeatureFlags::useTurboModules();
}

bool NativeReactNativeFeatureFlags::enableImagePrefetchingAndroid(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::enableImagePrefetchingAndroid();
}

} // namespace facebook::react
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<<b42cf9d00bd5b0d01f3d14b633771201>>
* @generated SignedSource<<2086478a8d4b599855acb29dfd958305>>
*/

/**
Expand Down Expand Up @@ -126,6 +126,8 @@ class NativeReactNativeFeatureFlags
bool useTurboModuleInterop(jsi::Runtime& runtime);

bool useTurboModules(jsi::Runtime& runtime);

bool enableImagePrefetchingAndroid(jsi::Runtime& runtime);
};

} // namespace facebook::react
Loading

0 comments on commit cc0382b

Please sign in to comment.