Skip to content

Commit

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

Migrate enableViewRecycling to ReactNativeFeatureFlags

changelog: [internal] internal

Reviewed By: mdvacca

Differential Revision: D60153238

fbshipit-source-id: 14980174cb21833e35e107dc4cf52867cd0a5f8e
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jul 31, 2024
1 parent 59da1ab commit a5b84b9
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 52 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 @@ -2029,7 +2029,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field enableBridgelessArchitecture Z
public static field enableCppPropsIteratorSetter Z
public static field enableFabricRenderer Z
public static field enableViewRecycling Z
public static field useTurboModules Z
public fun <init> ()V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,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<<5fb700b3cb0d98843505d210fc62cc82>>
* @generated SignedSource<<ea2ffa17af587ce1889472a5fd1bb0ee>>
*/

/**
Expand Down Expand Up @@ -148,6 +148,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<<4b36a495186bb73c9cd9541f72ecb9ff>>
* @generated SignedSource<<2d2f24ab93b9c2eb0b2002354f609ead>>
*/

/**
Expand Down Expand Up @@ -40,6 +40,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 @@ -244,6 +245,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<<7b542b9761fd6b5c3f00945880476616>>
* @generated SignedSource<<fab209e8817791c6892b61889b3c42ec>>
*/

/**
Expand Down Expand Up @@ -68,6 +68,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<<f954cbf175ce33373e3ba3e471d4b25f>>
* @generated SignedSource<<4c87f6bbb603ad9a66d08600fba93554>>
*/

/**
Expand Down Expand Up @@ -63,6 +63,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<<6f654101103cfdc987ade9e47a0b3d32>>
* @generated SignedSource<<9df3a3025e104c4dd9ce4fb99b8acbcd>>
*/

/**
Expand Down Expand Up @@ -44,6 +44,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 @@ -268,6 +269,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<<a2aff32b352c4a8edb4ed2898c4ec938>>
* @generated SignedSource<<ede274d7ec557bdc870c7f87bf1e0b9b>>
*/

/**
Expand Down Expand Up @@ -63,6 +63,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<<107da3f94e88bcd11b94dd62a71f4556>>
* @generated SignedSource<<8c7af40ab6ea0f4ea88a795d5884a07b>>
*/

/**
Expand Down Expand Up @@ -159,6 +159,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 @@ -401,6 +407,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 @@ -593,6 +604,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<<4182ca268eb74ffa52295cefb2c51f50>>
* @generated SignedSource<<6c0276095ccff4eb927141ce3b2c5469>>
*/

/**
Expand Down Expand Up @@ -90,6 +90,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 @@ -12,6 +12,7 @@ import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.JavaOnlyArray
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.react.bridge.WritableArray
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
import com.facebook.react.views.view.ReactViewGroup
import com.facebook.react.views.view.ReactViewManager
import java.util.Locale
Expand All @@ -33,6 +34,7 @@ class BaseViewManagerTest {

@Before
fun setUp() {
ReactNativeFeatureFlagsForTests.setUp()
viewManager = ReactViewManager()
view = ReactViewGroup(RuntimeEnvironment.getApplication())
arguments = Mockito.mockStatic(Arguments::class.java)
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<<003171b5ce3055ef281d041408ca146e>>
* @generated SignedSource<<763d10f3232028a26f5ed194fdb3b4f7>>
*/

/**
Expand Down Expand Up @@ -101,6 +101,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<<8be6a1e808bdf073829a7801545b2b8f>>
* @generated SignedSource<<14d7dd1b3690775bb8df6dc17d18c43c>>
*/

/**
Expand Down Expand Up @@ -137,6 +137,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 a5b84b9

Please sign in to comment.