Skip to content

Commit

Permalink
Migrate enableViewRecycling to ReactNativeFeatureFlags (facebook#45654)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45654

Migrate enableViewRecycling to ReactNativeFeatureFlags

changelog: [internal] internal

Reviewed By: mdvacca

Differential Revision: D60153238
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jul 24, 2024
1 parent 32d61d6 commit 5600a62
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 49 deletions.
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field enableEagerRootViewAttachment Z
public static field enableFabricLogs Z
public static field enableFabricRenderer Z
public static field enableViewRecycling Z
public static field traceTurboModulePromiseRejections Z
public static field unstable_enableTurboModuleSyncVoidMethods Z
public static field unstable_useFabricInterop Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public class ReactFeatureFlags {

public static boolean dispatchPointerEvents = false;

/**
* Feature Flag to enable View Recycling. When enabled, individual ViewManagers must still opt-in.
*/
public static boolean enableViewRecycling = false;

/**
* Enable prop iterator setter-style construction of Props in C++ (this flag is not used in Java).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.fabric.mounting.MountingManager.MountItemExecutor;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
Expand Down Expand Up @@ -313,7 +312,7 @@ public void stopSurface() {
mThemedReactContext = null;
mOnViewAttachMountItems.clear();

if (ReactFeatureFlags.enableViewRecycling) {
if (ReactNativeFeatureFlags.enableViewRecycling()) {
mViewManagerRegistry.onSurfaceStopped(mSurfaceId);
}
FLog.e(TAG, "Surface [" + mSurfaceId + "] was stopped on SurfaceMountingManager.");
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<<56adda271bcc179b28ee274516621130>>
* @generated SignedSource<<7d5157a67f049f5a22c31a02c1dcb2ed>>
*/

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

/**
* Enables View Recycling. When enabled, individual ViewManagers must still opt-in.
*/
@JvmStatic
public fun enableViewRecycling(): Boolean = accessor.enableViewRecycling()

/**
* When enabled, rawProps in Props will not include Yoga specific props.
*/
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<<55c12cd940ea93972522deb07da4c4f7>>
* @generated SignedSource<<455c831ec7085186cb705748cd8d0e8f>>
*/

/**
Expand Down Expand Up @@ -38,6 +38,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var enableReportEventPaintTimeCache: Boolean? = null
private var enableSynchronousStateUpdatesCache: Boolean? = null
private var enableUIConsistencyCache: Boolean? = null
private var enableViewRecyclingCache: Boolean? = null
private var excludeYogaFromRawPropsCache: Boolean? = null
private var fetchImagesInViewPreallocationCache: Boolean? = null
private var fixIncorrectScrollViewStateUpdateOnAndroidCache: Boolean? = null
Expand Down Expand Up @@ -221,6 +222,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

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

override fun excludeYogaFromRawProps(): Boolean {
var cached = excludeYogaFromRawPropsCache
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<<2c4f316e012720c438a96abf6a4939b0>>
* @generated SignedSource<<44aad84629569d0e8194eac791651c4c>>
*/

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

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

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

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

@DoNotStrip @JvmStatic public external fun fetchImagesInViewPreallocation(): 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<<6114babfba822bf81f105b9e2748783e>>
* @generated SignedSource<<ecbad2563a989be5c5ca5f521b2c6ba6>>
*/

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

override fun enableUIConsistency(): Boolean = false

override fun enableViewRecycling(): Boolean = false

override fun excludeYogaFromRawProps(): Boolean = false

override fun fetchImagesInViewPreallocation(): Boolean = false
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<<c764ec599b576cf412f62e910e82bd15>>
* @generated SignedSource<<d69601d7293b683559ac7482c73b916a>>
*/

/**
Expand Down Expand Up @@ -42,6 +42,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var enableReportEventPaintTimeCache: Boolean? = null
private var enableSynchronousStateUpdatesCache: Boolean? = null
private var enableUIConsistencyCache: Boolean? = null
private var enableViewRecyclingCache: Boolean? = null
private var excludeYogaFromRawPropsCache: Boolean? = null
private var fetchImagesInViewPreallocationCache: Boolean? = null
private var fixIncorrectScrollViewStateUpdateOnAndroidCache: Boolean? = null
Expand Down Expand Up @@ -243,6 +244,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun excludeYogaFromRawProps(): Boolean {
var cached = excludeYogaFromRawPropsCache
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<<1fe24c487e564478ff0ec5bcd2431587>>
* @generated SignedSource<<a79e9df5843b856c87160c2567b39ba7>>
*/

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

@DoNotStrip public fun enableUIConsistency(): Boolean

@DoNotStrip public fun enableViewRecycling(): Boolean

@DoNotStrip public fun excludeYogaFromRawProps(): Boolean

@DoNotStrip public fun fetchImagesInViewPreallocation(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.mapbuffer.MapBuffer;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.touch.JSResponderHandler;
import com.facebook.react.touch.ReactInterceptingViewGroup;
import com.facebook.react.uimanager.annotations.ReactProp;
Expand Down Expand Up @@ -56,7 +56,7 @@ public ViewManager(@Nullable ReactApplicationContext reactContext) {

/** Call in constructor of concrete ViewManager class to enable. */
protected void setupViewRecycling() {
if (ReactFeatureFlags.enableViewRecycling) {
if (ReactNativeFeatureFlags.enableViewRecycling()) {
mRecyclableViews = new HashMap<>();
}
}
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<<d0ae6b1ff04de53590348a469c530044>>
* @generated SignedSource<<95a2aea4237ba32909ebd21d55ac05ec>>
*/

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

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

bool excludeYogaFromRawProps() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("excludeYogaFromRawProps");
Expand Down Expand Up @@ -361,6 +367,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableUIConsistency(
return ReactNativeFeatureFlags::enableUIConsistency();
}

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

bool JReactNativeFeatureFlagsCxxInterop::excludeYogaFromRawProps(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::excludeYogaFromRawProps();
Expand Down Expand Up @@ -532,6 +543,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableUIConsistency",
JReactNativeFeatureFlagsCxxInterop::enableUIConsistency),
makeNativeMethod(
"enableViewRecycling",
JReactNativeFeatureFlagsCxxInterop::enableViewRecycling),
makeNativeMethod(
"excludeYogaFromRawProps",
JReactNativeFeatureFlagsCxxInterop::excludeYogaFromRawProps),
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<<5bdabf6e6808770c1884d055069e356a>>
* @generated SignedSource<<b763873f738b6b26570ae59422ff3b34>>
*/

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

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

static bool excludeYogaFromRawProps(
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<<30d6d96d4653c2e53eaf6fc1d259f540>>
* @generated SignedSource<<65063d9e107e8cd01ef1b90ef71dc352>>
*/

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

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

bool ReactNativeFeatureFlags::excludeYogaFromRawProps() {
return getAccessor().excludeYogaFromRawProps();
}
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<<3eb29a1ab498802529b70d37a6c5039a>>
* @generated SignedSource<<f1f1483fb2daa6b17cd0f584a2fa176b>>
*/

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

/**
* Enables View Recycling. When enabled, individual ViewManagers must still opt-in.
*/
RN_EXPORT static bool enableViewRecycling();

/**
* When enabled, rawProps in Props will not include Yoga specific props.
*/
Expand Down
Loading

0 comments on commit 5600a62

Please sign in to comment.