Skip to content

Commit ca5ce20

Browse files
Thomas Nardonefacebook-github-bot
authored andcommitted
Add separate flags for recycling View, Text components (#49211)
Summary: Pull Request resolved: #49211 Add more control over view recycling behavior by splitting out each component that currently supports it. Changelog:[Android][Added] Feature flags for recycling View, Text components separately Reviewed By: sammy-SC, mdvacca Differential Revision: D69190841 fbshipit-source-id: 6d85fee7103bf928e4f5bf6946bab3ff4cae4053
1 parent fb8a6a5 commit ca5ce20

22 files changed

+279
-39
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<5d3aa805cfedaf97ef3e6229046dc288>>
7+
* @generated SignedSource<<d7e150b5b7f7b62f347bc417f542f2ba>>
88
*/
99

1010
/**
@@ -172,6 +172,18 @@ public object ReactNativeFeatureFlags {
172172
@JvmStatic
173173
public fun enableViewRecycling(): Boolean = accessor.enableViewRecycling()
174174

175+
/**
176+
* Enables View Recycling for <Text> via ReactTextView/ReactTextViewManager.
177+
*/
178+
@JvmStatic
179+
public fun enableViewRecyclingForText(): Boolean = accessor.enableViewRecyclingForText()
180+
181+
/**
182+
* Enables View Recycling for <View> via ReactViewGroup/ReactViewManager.
183+
*/
184+
@JvmStatic
185+
public fun enableViewRecyclingForView(): Boolean = accessor.enableViewRecyclingForView()
186+
175187
/**
176188
* When enabled, rawProps in Props will not include Yoga specific props.
177189
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<001f61b20e3bacb67e4145a257cb92b1>>
7+
* @generated SignedSource<<ae7503526759f8b9f1ef56207ee1cab5>>
88
*/
99

1010
/**
@@ -44,6 +44,8 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
4444
private var enableSynchronousStateUpdatesCache: Boolean? = null
4545
private var enableUIConsistencyCache: Boolean? = null
4646
private var enableViewRecyclingCache: Boolean? = null
47+
private var enableViewRecyclingForTextCache: Boolean? = null
48+
private var enableViewRecyclingForViewCache: Boolean? = null
4749
private var excludeYogaFromRawPropsCache: Boolean? = null
4850
private var fixDifferentiatorEmittingUpdatesWithWrongParentTagCache: Boolean? = null
4951
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
@@ -278,6 +280,24 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
278280
return cached
279281
}
280282

283+
override fun enableViewRecyclingForText(): Boolean {
284+
var cached = enableViewRecyclingForTextCache
285+
if (cached == null) {
286+
cached = ReactNativeFeatureFlagsCxxInterop.enableViewRecyclingForText()
287+
enableViewRecyclingForTextCache = cached
288+
}
289+
return cached
290+
}
291+
292+
override fun enableViewRecyclingForView(): Boolean {
293+
var cached = enableViewRecyclingForViewCache
294+
if (cached == null) {
295+
cached = ReactNativeFeatureFlagsCxxInterop.enableViewRecyclingForView()
296+
enableViewRecyclingForViewCache = cached
297+
}
298+
return cached
299+
}
300+
281301
override fun excludeYogaFromRawProps(): Boolean {
282302
var cached = excludeYogaFromRawPropsCache
283303
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<745b574df700a813a49fed3c88aada66>>
7+
* @generated SignedSource<<5292a5f705fc3587ee9d81cc83a79c05>>
88
*/
99

1010
/**
@@ -76,6 +76,10 @@ public object ReactNativeFeatureFlagsCxxInterop {
7676

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

79+
@DoNotStrip @JvmStatic public external fun enableViewRecyclingForText(): Boolean
80+
81+
@DoNotStrip @JvmStatic public external fun enableViewRecyclingForView(): Boolean
82+
7983
@DoNotStrip @JvmStatic public external fun excludeYogaFromRawProps(): Boolean
8084

8185
@DoNotStrip @JvmStatic public external fun fixDifferentiatorEmittingUpdatesWithWrongParentTag(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<86207e36abfecc310dbd28b8d61c5fbf>>
7+
* @generated SignedSource<<d904f548576348ea7a6eb58fa306faea>>
88
*/
99

1010
/**
@@ -71,6 +71,10 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
7171

7272
override fun enableViewRecycling(): Boolean = false
7373

74+
override fun enableViewRecyclingForText(): Boolean = true
75+
76+
override fun enableViewRecyclingForView(): Boolean = true
77+
7478
override fun excludeYogaFromRawProps(): Boolean = false
7579

7680
override fun fixDifferentiatorEmittingUpdatesWithWrongParentTag(): Boolean = true

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c2ee44bcc04c2ab7fdb14c66980c7d73>>
7+
* @generated SignedSource<<f2440756231f770d7240112ed2a460d8>>
88
*/
99

1010
/**
@@ -48,6 +48,8 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
4848
private var enableSynchronousStateUpdatesCache: Boolean? = null
4949
private var enableUIConsistencyCache: Boolean? = null
5050
private var enableViewRecyclingCache: Boolean? = null
51+
private var enableViewRecyclingForTextCache: Boolean? = null
52+
private var enableViewRecyclingForViewCache: Boolean? = null
5153
private var excludeYogaFromRawPropsCache: Boolean? = null
5254
private var fixDifferentiatorEmittingUpdatesWithWrongParentTagCache: Boolean? = null
5355
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
@@ -306,6 +308,26 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
306308
return cached
307309
}
308310

311+
override fun enableViewRecyclingForText(): Boolean {
312+
var cached = enableViewRecyclingForTextCache
313+
if (cached == null) {
314+
cached = currentProvider.enableViewRecyclingForText()
315+
accessedFeatureFlags.add("enableViewRecyclingForText")
316+
enableViewRecyclingForTextCache = cached
317+
}
318+
return cached
319+
}
320+
321+
override fun enableViewRecyclingForView(): Boolean {
322+
var cached = enableViewRecyclingForViewCache
323+
if (cached == null) {
324+
cached = currentProvider.enableViewRecyclingForView()
325+
accessedFeatureFlags.add("enableViewRecyclingForView")
326+
enableViewRecyclingForViewCache = cached
327+
}
328+
return cached
329+
}
330+
309331
override fun excludeYogaFromRawProps(): Boolean {
310332
var cached = excludeYogaFromRawPropsCache
311333
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<e592fe3140fb310638240a84bd3f3e8f>>
7+
* @generated SignedSource<<3bb3618781161c0b6beaffcfabf0288c>>
88
*/
99

1010
/**
@@ -71,6 +71,10 @@ public interface ReactNativeFeatureFlagsProvider {
7171

7272
@DoNotStrip public fun enableViewRecycling(): Boolean
7373

74+
@DoNotStrip public fun enableViewRecyclingForText(): Boolean
75+
76+
@DoNotStrip public fun enableViewRecyclingForView(): Boolean
77+
7478
@DoNotStrip public fun excludeYogaFromRawProps(): Boolean
7579

7680
@DoNotStrip public fun fixDifferentiatorEmittingUpdatesWithWrongParentTag(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.react.common.annotations.VisibleForTesting;
1919
import com.facebook.react.common.mapbuffer.MapBuffer;
2020
import com.facebook.react.internal.SystraceSection;
21+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
2122
import com.facebook.react.module.annotations.ReactModule;
2223
import com.facebook.react.uimanager.IViewManagerWithChildren;
2324
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
@@ -58,7 +59,9 @@ public ReactTextViewManager() {
5859

5960
public ReactTextViewManager(@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
6061
mReactTextViewManagerCallback = reactTextViewManagerCallback;
61-
setupViewRecycling();
62+
if (ReactNativeFeatureFlags.enableViewRecyclingForText()) {
63+
setupViewRecycling();
64+
}
6265
}
6366

6467
@Override

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.facebook.react.bridge.ReadableArray
1818
import com.facebook.react.bridge.ReadableMap
1919
import com.facebook.react.bridge.ReadableType
2020
import com.facebook.react.common.ReactConstants
21+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
2122
import com.facebook.react.module.annotations.ReactModule
2223
import com.facebook.react.uimanager.BackgroundStyleApplicator
2324
import com.facebook.react.uimanager.LengthPercentage
@@ -63,7 +64,9 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()
6364
}
6465

6566
init {
66-
setupViewRecycling()
67+
if (ReactNativeFeatureFlags.enableViewRecyclingForView()) {
68+
setupViewRecycling()
69+
}
6770
}
6871

6972
override fun prepareToRecycleView(

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<89691e6748ef791ca022f1289304046d>>
7+
* @generated SignedSource<<b04123b022b1f120895d027f8bc12a4e>>
88
*/
99

1010
/**
@@ -183,6 +183,18 @@ class ReactNativeFeatureFlagsProviderHolder
183183
return method(javaProvider_);
184184
}
185185

186+
bool enableViewRecyclingForText() override {
187+
static const auto method =
188+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableViewRecyclingForText");
189+
return method(javaProvider_);
190+
}
191+
192+
bool enableViewRecyclingForView() override {
193+
static const auto method =
194+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableViewRecyclingForView");
195+
return method(javaProvider_);
196+
}
197+
186198
bool excludeYogaFromRawProps() override {
187199
static const auto method =
188200
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("excludeYogaFromRawProps");
@@ -409,6 +421,16 @@ bool JReactNativeFeatureFlagsCxxInterop::enableViewRecycling(
409421
return ReactNativeFeatureFlags::enableViewRecycling();
410422
}
411423

424+
bool JReactNativeFeatureFlagsCxxInterop::enableViewRecyclingForText(
425+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
426+
return ReactNativeFeatureFlags::enableViewRecyclingForText();
427+
}
428+
429+
bool JReactNativeFeatureFlagsCxxInterop::enableViewRecyclingForView(
430+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
431+
return ReactNativeFeatureFlags::enableViewRecyclingForView();
432+
}
433+
412434
bool JReactNativeFeatureFlagsCxxInterop::excludeYogaFromRawProps(
413435
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
414436
return ReactNativeFeatureFlags::excludeYogaFromRawProps();
@@ -597,6 +619,12 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
597619
makeNativeMethod(
598620
"enableViewRecycling",
599621
JReactNativeFeatureFlagsCxxInterop::enableViewRecycling),
622+
makeNativeMethod(
623+
"enableViewRecyclingForText",
624+
JReactNativeFeatureFlagsCxxInterop::enableViewRecyclingForText),
625+
makeNativeMethod(
626+
"enableViewRecyclingForView",
627+
JReactNativeFeatureFlagsCxxInterop::enableViewRecyclingForView),
600628
makeNativeMethod(
601629
"excludeYogaFromRawProps",
602630
JReactNativeFeatureFlagsCxxInterop::excludeYogaFromRawProps),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<00ecf4fa0d9e7286d2ddb824970fb392>>
7+
* @generated SignedSource<<141e3b288582658dac52d18b9f8fe273>>
88
*/
99

1010
/**
@@ -102,6 +102,12 @@ class JReactNativeFeatureFlagsCxxInterop
102102
static bool enableViewRecycling(
103103
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
104104

105+
static bool enableViewRecyclingForText(
106+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
107+
108+
static bool enableViewRecyclingForView(
109+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
110+
105111
static bool excludeYogaFromRawProps(
106112
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
107113

0 commit comments

Comments
 (0)