diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index 4235f29476b..cdbd3b13ce1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -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<<3a6a61e2cc2bf01a35ab5c3919462ad5>> + * @generated SignedSource<<152d2c6f279f3e7f2c11badd0a4a4be0>> */ /** @@ -402,6 +402,12 @@ public object ReactNativeFeatureFlags { @JvmStatic public fun enableVirtualViewContainerStateExperimental(): Boolean = accessor.enableVirtualViewContainerStateExperimental() + /** + * Enables scroll-position stability improvements for variable-height VirtualizedLists, including spacer-length stabilization, improved native maintainVisibleContentPosition anchoring, and default anchoring. + */ + @JvmStatic + public fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean = accessor.enableVirtualizedListMaintainVisibleContentPosition() + /** * Prevents a borderless ripple feedback underlay from projecting the entire view background on Android, which could hide the background and ripple. */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index 1369551650b..1747edee438 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -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<> + * @generated SignedSource<> */ /** @@ -82,6 +82,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces private var enableViewRecyclingForTextCache: Boolean? = null private var enableViewRecyclingForViewCache: Boolean? = null private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null + private var enableVirtualizedListMaintainVisibleContentPositionCache: Boolean? = null private var fixBorderlessRippleAndroidCache: Boolean? = null private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null private var fixMultilineContentJumpAndroidCache: Boolean? = null @@ -683,6 +684,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces return cached } + override fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean { + var cached = enableVirtualizedListMaintainVisibleContentPositionCache + if (cached == null) { + cached = ReactNativeFeatureFlagsCxxInterop.enableVirtualizedListMaintainVisibleContentPosition() + enableVirtualizedListMaintainVisibleContentPositionCache = cached + } + return cached + } + override fun fixBorderlessRippleAndroid(): Boolean { var cached = fixBorderlessRippleAndroidCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index 605434477a7..654f848ba2d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -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<> + * @generated SignedSource<> */ /** @@ -152,6 +152,8 @@ public object ReactNativeFeatureFlagsCxxInterop { @DoNotStrip @JvmStatic public external fun enableVirtualViewContainerStateExperimental(): Boolean + @DoNotStrip @JvmStatic public external fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean + @DoNotStrip @JvmStatic public external fun fixBorderlessRippleAndroid(): Boolean @DoNotStrip @JvmStatic public external fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 536ffc40b81..04276f093c1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -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<<834b0e9533cbc775a1c12b86140d718d>> + * @generated SignedSource<<28f7a8ffb0692a5e6e2f59d858801f94>> */ /** @@ -147,6 +147,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun enableVirtualViewContainerStateExperimental(): Boolean = false + override fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean = false + override fun fixBorderlessRippleAndroid(): Boolean = false override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = false diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index b03e57fa3d9..ec9a5ab7d58 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -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<<15c65d4497fd9f36f8902efb2812b3b2>> + * @generated SignedSource<<707cc7dc09ae7c9f186cbb69ac53d87f>> */ /** @@ -86,6 +86,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc private var enableViewRecyclingForTextCache: Boolean? = null private var enableViewRecyclingForViewCache: Boolean? = null private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null + private var enableVirtualizedListMaintainVisibleContentPositionCache: Boolean? = null private var fixBorderlessRippleAndroidCache: Boolean? = null private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null private var fixMultilineContentJumpAndroidCache: Boolean? = null @@ -749,6 +750,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc return cached } + override fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean { + var cached = enableVirtualizedListMaintainVisibleContentPositionCache + if (cached == null) { + cached = currentProvider.enableVirtualizedListMaintainVisibleContentPosition() + accessedFeatureFlags.add("enableVirtualizedListMaintainVisibleContentPosition") + enableVirtualizedListMaintainVisibleContentPositionCache = cached + } + return cached + } + override fun fixBorderlessRippleAndroid(): Boolean { var cached = fixBorderlessRippleAndroidCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index 8e45070b5b8..221c3c61c6b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -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<<89f683cb28a7d1ef52c86faa96f1107c>> + * @generated SignedSource<> */ /** @@ -147,6 +147,8 @@ public interface ReactNativeFeatureFlagsProvider { @DoNotStrip public fun enableVirtualViewContainerStateExperimental(): Boolean + @DoNotStrip public fun enableVirtualizedListMaintainVisibleContentPosition(): Boolean + @DoNotStrip public fun fixBorderlessRippleAndroid(): Boolean @DoNotStrip public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index 05171db7995..88dbdc834b3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -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<<407c8e5915db07bb6cc2b9ba4449750a>> + * @generated SignedSource<<740b3a4ce4d4872f7b8e5db7bc34df2c>> */ /** @@ -411,6 +411,12 @@ class ReactNativeFeatureFlagsJavaProvider return method(javaProvider_); } + bool enableVirtualizedListMaintainVisibleContentPosition() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableVirtualizedListMaintainVisibleContentPosition"); + return method(javaProvider_); + } + bool fixBorderlessRippleAndroid() override { static const auto method = getReactNativeFeatureFlagsProviderJavaClass()->getMethod("fixBorderlessRippleAndroid"); @@ -977,6 +983,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableVirtualViewContainerStateExperime return ReactNativeFeatureFlags::enableVirtualViewContainerStateExperimental(); } +bool JReactNativeFeatureFlagsCxxInterop::enableVirtualizedListMaintainVisibleContentPosition( + facebook::jni::alias_ref /*unused*/) { + return ReactNativeFeatureFlags::enableVirtualizedListMaintainVisibleContentPosition(); +} + bool JReactNativeFeatureFlagsCxxInterop::fixBorderlessRippleAndroid( facebook::jni::alias_ref /*unused*/) { return ReactNativeFeatureFlags::fixBorderlessRippleAndroid(); @@ -1404,6 +1415,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "enableVirtualViewContainerStateExperimental", JReactNativeFeatureFlagsCxxInterop::enableVirtualViewContainerStateExperimental), + makeNativeMethod( + "enableVirtualizedListMaintainVisibleContentPosition", + JReactNativeFeatureFlagsCxxInterop::enableVirtualizedListMaintainVisibleContentPosition), makeNativeMethod( "fixBorderlessRippleAndroid", JReactNativeFeatureFlagsCxxInterop::fixBorderlessRippleAndroid), diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index 8a3d8c458db..6f2e7cbb37e 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -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<<7cb5d49e9124d56b3e242e2023db8649>> + * @generated SignedSource<<2508a344dfff3b40f3ed99574ebcf703>> */ /** @@ -216,6 +216,9 @@ class JReactNativeFeatureFlagsCxxInterop static bool enableVirtualViewContainerStateExperimental( facebook::jni::alias_ref); + static bool enableVirtualizedListMaintainVisibleContentPosition( + facebook::jni::alias_ref); + static bool fixBorderlessRippleAndroid( facebook::jni::alias_ref); diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index 8b4970ef87f..c323a5e45e0 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -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<> + * @generated SignedSource<> */ /** @@ -274,6 +274,10 @@ bool ReactNativeFeatureFlags::enableVirtualViewContainerStateExperimental() { return getAccessor().enableVirtualViewContainerStateExperimental(); } +bool ReactNativeFeatureFlags::enableVirtualizedListMaintainVisibleContentPosition() { + return getAccessor().enableVirtualizedListMaintainVisibleContentPosition(); +} + bool ReactNativeFeatureFlags::fixBorderlessRippleAndroid() { return getAccessor().fixBorderlessRippleAndroid(); } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index dd6d63f7373..bb60f1119ec 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -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<<2ddd9296377ea4c1fd9c84883fbde049>> + * @generated SignedSource<<3a0e51e5d4982dfca714485e681d9110>> */ /** @@ -351,6 +351,11 @@ class ReactNativeFeatureFlags { */ RN_EXPORT static bool enableVirtualViewContainerStateExperimental(); + /** + * Enables scroll-position stability improvements for variable-height VirtualizedLists, including spacer-length stabilization, improved native maintainVisibleContentPosition anchoring, and default anchoring. + */ + RN_EXPORT static bool enableVirtualizedListMaintainVisibleContentPosition(); + /** * Prevents a borderless ripple feedback underlay from projecting the entire view background on Android, which could hide the background and ripple. */ diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index 461adbb5f51..736b3711111 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -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<> + * @generated SignedSource<<09c4cdc5369f371b3050154eb599aee4>> */ /** @@ -1145,6 +1145,24 @@ bool ReactNativeFeatureFlagsAccessor::enableVirtualViewContainerStateExperimenta return flagValue.value(); } +bool ReactNativeFeatureFlagsAccessor::enableVirtualizedListMaintainVisibleContentPosition() { + auto flagValue = enableVirtualizedListMaintainVisibleContentPosition_.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(62, "enableVirtualizedListMaintainVisibleContentPosition"); + + flagValue = currentProvider_->enableVirtualizedListMaintainVisibleContentPosition(); + enableVirtualizedListMaintainVisibleContentPosition_ = flagValue; + } + + return flagValue.value(); +} + bool ReactNativeFeatureFlagsAccessor::fixBorderlessRippleAndroid() { auto flagValue = fixBorderlessRippleAndroid_.load(); @@ -1154,7 +1172,7 @@ bool ReactNativeFeatureFlagsAccessor::fixBorderlessRippleAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(62, "fixBorderlessRippleAndroid"); + markFlagAsAccessed(63, "fixBorderlessRippleAndroid"); flagValue = currentProvider_->fixBorderlessRippleAndroid(); fixBorderlessRippleAndroid_ = flagValue; @@ -1172,7 +1190,7 @@ bool ReactNativeFeatureFlagsAccessor::fixMappingOfEventPrioritiesBetweenFabricAn // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(63, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); + markFlagAsAccessed(64, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); flagValue = currentProvider_->fixMappingOfEventPrioritiesBetweenFabricAndReact(); fixMappingOfEventPrioritiesBetweenFabricAndReact_ = flagValue; @@ -1190,7 +1208,7 @@ bool ReactNativeFeatureFlagsAccessor::fixMultilineContentJumpAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(64, "fixMultilineContentJumpAndroid"); + markFlagAsAccessed(65, "fixMultilineContentJumpAndroid"); flagValue = currentProvider_->fixMultilineContentJumpAndroid(); fixMultilineContentJumpAndroid_ = flagValue; @@ -1208,7 +1226,7 @@ bool ReactNativeFeatureFlagsAccessor::fixProgrammaticScrollMomentumEventsIOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(65, "fixProgrammaticScrollMomentumEventsIOS"); + markFlagAsAccessed(66, "fixProgrammaticScrollMomentumEventsIOS"); flagValue = currentProvider_->fixProgrammaticScrollMomentumEventsIOS(); fixProgrammaticScrollMomentumEventsIOS_ = flagValue; @@ -1226,7 +1244,7 @@ bool ReactNativeFeatureFlagsAccessor::fixTextInlineViewLineHeight() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(66, "fixTextInlineViewLineHeight"); + markFlagAsAccessed(67, "fixTextInlineViewLineHeight"); flagValue = currentProvider_->fixTextInlineViewLineHeight(); fixTextInlineViewLineHeight_ = flagValue; @@ -1244,7 +1262,7 @@ bool ReactNativeFeatureFlagsAccessor::fixTextLayoutOnPixelDensityChange() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(67, "fixTextLayoutOnPixelDensityChange"); + markFlagAsAccessed(68, "fixTextLayoutOnPixelDensityChange"); flagValue = currentProvider_->fixTextLayoutOnPixelDensityChange(); fixTextLayoutOnPixelDensityChange_ = flagValue; @@ -1262,7 +1280,7 @@ bool ReactNativeFeatureFlagsAccessor::fixYogaFlexBasisFitContentInMainAxis() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(68, "fixYogaFlexBasisFitContentInMainAxis"); + markFlagAsAccessed(69, "fixYogaFlexBasisFitContentInMainAxis"); flagValue = currentProvider_->fixYogaFlexBasisFitContentInMainAxis(); fixYogaFlexBasisFitContentInMainAxis_ = flagValue; @@ -1280,7 +1298,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxAssertSingleHostState() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(69, "fuseboxAssertSingleHostState"); + markFlagAsAccessed(70, "fuseboxAssertSingleHostState"); flagValue = currentProvider_->fuseboxAssertSingleHostState(); fuseboxAssertSingleHostState_ = flagValue; @@ -1298,7 +1316,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxEnabledRelease() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(70, "fuseboxEnabledRelease"); + markFlagAsAccessed(71, "fuseboxEnabledRelease"); flagValue = currentProvider_->fuseboxEnabledRelease(); fuseboxEnabledRelease_ = flagValue; @@ -1316,7 +1334,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxFrameRecordingEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(71, "fuseboxFrameRecordingEnabled"); + markFlagAsAccessed(72, "fuseboxFrameRecordingEnabled"); flagValue = currentProvider_->fuseboxFrameRecordingEnabled(); fuseboxFrameRecordingEnabled_ = flagValue; @@ -1334,7 +1352,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxScreenshotCaptureEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(72, "fuseboxScreenshotCaptureEnabled"); + markFlagAsAccessed(73, "fuseboxScreenshotCaptureEnabled"); flagValue = currentProvider_->fuseboxScreenshotCaptureEnabled(); fuseboxScreenshotCaptureEnabled_ = flagValue; @@ -1352,7 +1370,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxWebSocketEventsEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(73, "fuseboxWebSocketEventsEnabled"); + markFlagAsAccessed(74, "fuseboxWebSocketEventsEnabled"); flagValue = currentProvider_->fuseboxWebSocketEventsEnabled(); fuseboxWebSocketEventsEnabled_ = flagValue; @@ -1370,7 +1388,7 @@ bool ReactNativeFeatureFlagsAccessor::keepTimersRunningWhileHostPausedAndroid() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(74, "keepTimersRunningWhileHostPausedAndroid"); + markFlagAsAccessed(75, "keepTimersRunningWhileHostPausedAndroid"); flagValue = currentProvider_->keepTimersRunningWhileHostPausedAndroid(); keepTimersRunningWhileHostPausedAndroid_ = flagValue; @@ -1388,7 +1406,7 @@ bool ReactNativeFeatureFlagsAccessor::optimizedAnimatedPropUpdates() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(75, "optimizedAnimatedPropUpdates"); + markFlagAsAccessed(76, "optimizedAnimatedPropUpdates"); flagValue = currentProvider_->optimizedAnimatedPropUpdates(); optimizedAnimatedPropUpdates_ = flagValue; @@ -1406,7 +1424,7 @@ bool ReactNativeFeatureFlagsAccessor::overrideBySynchronousMountPropsAtMountingA // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(76, "overrideBySynchronousMountPropsAtMountingAndroid"); + markFlagAsAccessed(77, "overrideBySynchronousMountPropsAtMountingAndroid"); flagValue = currentProvider_->overrideBySynchronousMountPropsAtMountingAndroid(); overrideBySynchronousMountPropsAtMountingAndroid_ = flagValue; @@ -1424,7 +1442,7 @@ bool ReactNativeFeatureFlagsAccessor::perfIssuesEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(77, "perfIssuesEnabled"); + markFlagAsAccessed(78, "perfIssuesEnabled"); flagValue = currentProvider_->perfIssuesEnabled(); perfIssuesEnabled_ = flagValue; @@ -1442,7 +1460,7 @@ bool ReactNativeFeatureFlagsAccessor::perfMonitorV2Enabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(78, "perfMonitorV2Enabled"); + markFlagAsAccessed(79, "perfMonitorV2Enabled"); flagValue = currentProvider_->perfMonitorV2Enabled(); perfMonitorV2Enabled_ = flagValue; @@ -1460,7 +1478,7 @@ double ReactNativeFeatureFlagsAccessor::preparedTextCacheSize() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(79, "preparedTextCacheSize"); + markFlagAsAccessed(80, "preparedTextCacheSize"); flagValue = currentProvider_->preparedTextCacheSize(); preparedTextCacheSize_ = flagValue; @@ -1478,7 +1496,7 @@ bool ReactNativeFeatureFlagsAccessor::preventShadowTreeCommitExhaustion() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(80, "preventShadowTreeCommitExhaustion"); + markFlagAsAccessed(81, "preventShadowTreeCommitExhaustion"); flagValue = currentProvider_->preventShadowTreeCommitExhaustion(); preventShadowTreeCommitExhaustion_ = flagValue; @@ -1496,7 +1514,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2Android() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(81, "redBoxV2Android"); + markFlagAsAccessed(82, "redBoxV2Android"); flagValue = currentProvider_->redBoxV2Android(); redBoxV2Android_ = flagValue; @@ -1514,7 +1532,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2IOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(82, "redBoxV2IOS"); + markFlagAsAccessed(83, "redBoxV2IOS"); flagValue = currentProvider_->redBoxV2IOS(); redBoxV2IOS_ = flagValue; @@ -1532,7 +1550,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldPressibilityUseW3CPointerEventsForHo // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(83, "shouldPressibilityUseW3CPointerEventsForHover"); + markFlagAsAccessed(84, "shouldPressibilityUseW3CPointerEventsForHover"); flagValue = currentProvider_->shouldPressibilityUseW3CPointerEventsForHover(); shouldPressibilityUseW3CPointerEventsForHover_ = flagValue; @@ -1550,7 +1568,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldTriggerResponderTransferOnScrollAndr // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(84, "shouldTriggerResponderTransferOnScrollAndroid"); + markFlagAsAccessed(85, "shouldTriggerResponderTransferOnScrollAndroid"); flagValue = currentProvider_->shouldTriggerResponderTransferOnScrollAndroid(); shouldTriggerResponderTransferOnScrollAndroid_ = flagValue; @@ -1568,7 +1586,7 @@ bool ReactNativeFeatureFlagsAccessor::skipActivityIdentityAssertionOnHostPause() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(85, "skipActivityIdentityAssertionOnHostPause"); + markFlagAsAccessed(86, "skipActivityIdentityAssertionOnHostPause"); flagValue = currentProvider_->skipActivityIdentityAssertionOnHostPause(); skipActivityIdentityAssertionOnHostPause_ = flagValue; @@ -1586,7 +1604,7 @@ bool ReactNativeFeatureFlagsAccessor::skipNativePropsForViewManagerWithDelegateA // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(86, "skipNativePropsForViewManagerWithDelegateAndroid"); + markFlagAsAccessed(87, "skipNativePropsForViewManagerWithDelegateAndroid"); flagValue = currentProvider_->skipNativePropsForViewManagerWithDelegateAndroid(); skipNativePropsForViewManagerWithDelegateAndroid_ = flagValue; @@ -1604,7 +1622,7 @@ bool ReactNativeFeatureFlagsAccessor::skipUnchangedChildrenInDifferentiator() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(87, "skipUnchangedChildrenInDifferentiator"); + markFlagAsAccessed(88, "skipUnchangedChildrenInDifferentiator"); flagValue = currentProvider_->skipUnchangedChildrenInDifferentiator(); skipUnchangedChildrenInDifferentiator_ = flagValue; @@ -1622,7 +1640,7 @@ bool ReactNativeFeatureFlagsAccessor::syncAndroidClipBoundsWithOverflow() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(88, "syncAndroidClipBoundsWithOverflow"); + markFlagAsAccessed(89, "syncAndroidClipBoundsWithOverflow"); flagValue = currentProvider_->syncAndroidClipBoundsWithOverflow(); syncAndroidClipBoundsWithOverflow_ = flagValue; @@ -1640,7 +1658,7 @@ bool ReactNativeFeatureFlagsAccessor::traceTurboModulePromiseRejectionsOnAndroid // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(89, "traceTurboModulePromiseRejectionsOnAndroid"); + markFlagAsAccessed(90, "traceTurboModulePromiseRejectionsOnAndroid"); flagValue = currentProvider_->traceTurboModulePromiseRejectionsOnAndroid(); traceTurboModulePromiseRejectionsOnAndroid_ = flagValue; @@ -1658,7 +1676,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommit( // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(90, "updateRuntimeShadowNodeReferencesOnCommit"); + markFlagAsAccessed(91, "updateRuntimeShadowNodeReferencesOnCommit"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommit(); updateRuntimeShadowNodeReferencesOnCommit_ = flagValue; @@ -1676,7 +1694,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommitT // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(91, "updateRuntimeShadowNodeReferencesOnCommitThread"); + markFlagAsAccessed(92, "updateRuntimeShadowNodeReferencesOnCommitThread"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommitThread(); updateRuntimeShadowNodeReferencesOnCommitThread_ = flagValue; @@ -1694,7 +1712,7 @@ bool ReactNativeFeatureFlagsAccessor::useAlwaysAvailableJSErrorHandling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(92, "useAlwaysAvailableJSErrorHandling"); + markFlagAsAccessed(93, "useAlwaysAvailableJSErrorHandling"); flagValue = currentProvider_->useAlwaysAvailableJSErrorHandling(); useAlwaysAvailableJSErrorHandling_ = flagValue; @@ -1712,7 +1730,7 @@ bool ReactNativeFeatureFlagsAccessor::useFabricInterop() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(93, "useFabricInterop"); + markFlagAsAccessed(94, "useFabricInterop"); flagValue = currentProvider_->useFabricInterop(); useFabricInterop_ = flagValue; @@ -1730,7 +1748,7 @@ bool ReactNativeFeatureFlagsAccessor::useNativeViewConfigsInBridgelessMode() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(94, "useNativeViewConfigsInBridgelessMode"); + markFlagAsAccessed(95, "useNativeViewConfigsInBridgelessMode"); flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode(); useNativeViewConfigsInBridgelessMode_ = flagValue; @@ -1748,7 +1766,7 @@ bool ReactNativeFeatureFlagsAccessor::useNestedScrollViewAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(95, "useNestedScrollViewAndroid"); + markFlagAsAccessed(96, "useNestedScrollViewAndroid"); flagValue = currentProvider_->useNestedScrollViewAndroid(); useNestedScrollViewAndroid_ = flagValue; @@ -1766,7 +1784,7 @@ bool ReactNativeFeatureFlagsAccessor::useSharedAnimatedBackend() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(96, "useSharedAnimatedBackend"); + markFlagAsAccessed(97, "useSharedAnimatedBackend"); flagValue = currentProvider_->useSharedAnimatedBackend(); useSharedAnimatedBackend_ = flagValue; @@ -1784,7 +1802,7 @@ bool ReactNativeFeatureFlagsAccessor::useTraitHiddenOnAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(97, "useTraitHiddenOnAndroid"); + markFlagAsAccessed(98, "useTraitHiddenOnAndroid"); flagValue = currentProvider_->useTraitHiddenOnAndroid(); useTraitHiddenOnAndroid_ = flagValue; @@ -1802,7 +1820,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(98, "useTurboModuleInterop"); + markFlagAsAccessed(99, "useTurboModuleInterop"); flagValue = currentProvider_->useTurboModuleInterop(); useTurboModuleInterop_ = flagValue; @@ -1820,7 +1838,7 @@ bool ReactNativeFeatureFlagsAccessor::useWindowDensityForDisplayMetricsAndroid() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(99, "useWindowDensityForDisplayMetricsAndroid"); + markFlagAsAccessed(100, "useWindowDensityForDisplayMetricsAndroid"); flagValue = currentProvider_->useWindowDensityForDisplayMetricsAndroid(); useWindowDensityForDisplayMetricsAndroid_ = flagValue; @@ -1838,7 +1856,7 @@ double ReactNativeFeatureFlagsAccessor::viewCullingOutsetRatio() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(100, "viewCullingOutsetRatio"); + markFlagAsAccessed(101, "viewCullingOutsetRatio"); flagValue = currentProvider_->viewCullingOutsetRatio(); viewCullingOutsetRatio_ = flagValue; @@ -1856,7 +1874,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(101, "viewTransitionEnabled"); + markFlagAsAccessed(102, "viewTransitionEnabled"); flagValue = currentProvider_->viewTransitionEnabled(); viewTransitionEnabled_ = flagValue; @@ -1874,7 +1892,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionUseHardwareBitmapAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(102, "viewTransitionUseHardwareBitmapAndroid"); + markFlagAsAccessed(103, "viewTransitionUseHardwareBitmapAndroid"); flagValue = currentProvider_->viewTransitionUseHardwareBitmapAndroid(); viewTransitionUseHardwareBitmapAndroid_ = flagValue; @@ -1892,7 +1910,7 @@ double ReactNativeFeatureFlagsAccessor::virtualViewPrerenderRatio() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(103, "virtualViewPrerenderRatio"); + markFlagAsAccessed(104, "virtualViewPrerenderRatio"); flagValue = currentProvider_->virtualViewPrerenderRatio(); virtualViewPrerenderRatio_ = flagValue; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index d4616bebccd..01b5a2692d5 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -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<<9f2e67fdc5a5e9e452b59c47ceb68411>> + * @generated SignedSource<<9db810f471665ee1f06e25a29cdab702>> */ /** @@ -96,6 +96,7 @@ class ReactNativeFeatureFlagsAccessor { bool enableViewRecyclingForText(); bool enableViewRecyclingForView(); bool enableVirtualViewContainerStateExperimental(); + bool enableVirtualizedListMaintainVisibleContentPosition(); bool fixBorderlessRippleAndroid(); bool fixMappingOfEventPrioritiesBetweenFabricAndReact(); bool fixMultilineContentJumpAndroid(); @@ -149,7 +150,7 @@ class ReactNativeFeatureFlagsAccessor { std::unique_ptr currentProvider_; bool wasOverridden_; - std::array, 104> accessedFeatureFlags_; + std::array, 105> accessedFeatureFlags_; std::atomic> commonTestFlag_; std::atomic> cdpInteractionMetricsEnabled_; @@ -213,6 +214,7 @@ class ReactNativeFeatureFlagsAccessor { std::atomic> enableViewRecyclingForText_; std::atomic> enableViewRecyclingForView_; std::atomic> enableVirtualViewContainerStateExperimental_; + std::atomic> enableVirtualizedListMaintainVisibleContentPosition_; std::atomic> fixBorderlessRippleAndroid_; std::atomic> fixMappingOfEventPrioritiesBetweenFabricAndReact_; std::atomic> fixMultilineContentJumpAndroid_; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index c67cef573d7..7ec062a07b3 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -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<<7a81ab39c483265b1e958b1091a60778>> + * @generated SignedSource<> */ /** @@ -277,6 +277,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { return false; } + bool enableVirtualizedListMaintainVisibleContentPosition() override { + return false; + } + bool fixBorderlessRippleAndroid() override { return false; } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h index 65d27bd4f55..e8d31648b4e 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h @@ -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<<224a696e6d9f5af0cc450c8742d565e2>> + * @generated SignedSource<<48251923d4f775172a1e6719f946e6af>> */ /** @@ -605,6 +605,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef return ReactNativeFeatureFlagsDefaults::enableVirtualViewContainerStateExperimental(); } + bool enableVirtualizedListMaintainVisibleContentPosition() override { + auto value = values_["enableVirtualizedListMaintainVisibleContentPosition"]; + if (!value.isNull()) { + return value.getBool(); + } + + return ReactNativeFeatureFlagsDefaults::enableVirtualizedListMaintainVisibleContentPosition(); + } + bool fixBorderlessRippleAndroid() override { auto value = values_["fixBorderlessRippleAndroid"]; if (!value.isNull()) { diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index 7a33d63c5c3..5a5dec90e93 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -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<<8aa886405e9e5978c6572980119d7ea9>> + * @generated SignedSource<<35ace750e42b62932d6edf0edc4d4644>> */ /** @@ -89,6 +89,7 @@ class ReactNativeFeatureFlagsProvider { virtual bool enableViewRecyclingForText() = 0; virtual bool enableViewRecyclingForView() = 0; virtual bool enableVirtualViewContainerStateExperimental() = 0; + virtual bool enableVirtualizedListMaintainVisibleContentPosition() = 0; virtual bool fixBorderlessRippleAndroid() = 0; virtual bool fixMappingOfEventPrioritiesBetweenFabricAndReact() = 0; virtual bool fixMultilineContentJumpAndroid() = 0; diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index 3184a83f67a..46417ef331d 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -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<<1b5afe4df88834163a9e8a39ca24dd15>> + * @generated SignedSource<> */ /** @@ -354,6 +354,11 @@ bool NativeReactNativeFeatureFlags::enableVirtualViewContainerStateExperimental( return ReactNativeFeatureFlags::enableVirtualViewContainerStateExperimental(); } +bool NativeReactNativeFeatureFlags::enableVirtualizedListMaintainVisibleContentPosition( + jsi::Runtime& /*runtime*/) { + return ReactNativeFeatureFlags::enableVirtualizedListMaintainVisibleContentPosition(); +} + bool NativeReactNativeFeatureFlags::fixBorderlessRippleAndroid( jsi::Runtime& /*runtime*/) { return ReactNativeFeatureFlags::fixBorderlessRippleAndroid(); diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index c0d6598a33b..f8735278b81 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -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<<9829941034a694056c0baf2f2e7e6574>> + * @generated SignedSource<<2bacbd550b01a8eb0b2850459c9a32b2>> */ /** @@ -162,6 +162,8 @@ class NativeReactNativeFeatureFlags bool enableVirtualViewContainerStateExperimental(jsi::Runtime& runtime); + bool enableVirtualizedListMaintainVisibleContentPosition(jsi::Runtime& runtime); + bool fixBorderlessRippleAndroid(jsi::Runtime& runtime); bool fixMappingOfEventPrioritiesBetweenFabricAndReact(jsi::Runtime& runtime); diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index e030600d90b..4b3e9e1e2a8 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -717,6 +717,17 @@ const definitions: FeatureFlagDefinitions = { }, ossReleaseStage: 'none', }, + enableVirtualizedListMaintainVisibleContentPosition: { + defaultValue: false, + metadata: { + dateAdded: '2026-12-03', + description: + 'Enables scroll-position stability improvements for variable-height VirtualizedLists, including spacer-length stabilization, improved native maintainVisibleContentPosition anchoring, and default anchoring.', + expectedReleaseValue: true, + purpose: 'experimentation', + }, + ossReleaseStage: 'none', + }, fixBorderlessRippleAndroid: { defaultValue: false, metadata: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 60509629c60..5bbe9ade064 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -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<<581558c9591efde03b925773bbf05e66>> + * @generated SignedSource<> * @flow strict * @noformat */ @@ -111,6 +111,7 @@ export type ReactNativeFeatureFlags = Readonly<{ enableViewRecyclingForText: Getter, enableViewRecyclingForView: Getter, enableVirtualViewContainerStateExperimental: Getter, + enableVirtualizedListMaintainVisibleContentPosition: Getter, fixBorderlessRippleAndroid: Getter, fixMappingOfEventPrioritiesBetweenFabricAndReact: Getter, fixMultilineContentJumpAndroid: Getter, @@ -477,6 +478,10 @@ export const enableViewRecyclingForView: Getter = createNativeFlagGette * Enables the experimental version of `VirtualViewContainerState`. */ export const enableVirtualViewContainerStateExperimental: Getter = createNativeFlagGetter('enableVirtualViewContainerStateExperimental', false); +/** + * Enables scroll-position stability improvements for variable-height VirtualizedLists, including spacer-length stabilization, improved native maintainVisibleContentPosition anchoring, and default anchoring. + */ +export const enableVirtualizedListMaintainVisibleContentPosition: Getter = createNativeFlagGetter('enableVirtualizedListMaintainVisibleContentPosition', false); /** * Prevents a borderless ripple feedback underlay from projecting the entire view background on Android, which could hide the background and ripple. */ diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index e01580594e2..bf74a113269 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -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<<5fc3f6a14b4e46e34e89fe358e57183b>> + * @generated SignedSource<> * @flow strict * @noformat */ @@ -87,6 +87,7 @@ export interface Spec extends TurboModule { readonly enableViewRecyclingForText?: () => boolean; readonly enableViewRecyclingForView?: () => boolean; readonly enableVirtualViewContainerStateExperimental?: () => boolean; + readonly enableVirtualizedListMaintainVisibleContentPosition?: () => boolean; readonly fixBorderlessRippleAndroid?: () => boolean; readonly fixMappingOfEventPrioritiesBetweenFabricAndReact?: () => boolean; readonly fixMultilineContentJumpAndroid?: () => boolean; diff --git a/packages/virtualized-lists/Lists/NumericFenwickTree.js b/packages/virtualized-lists/Lists/NumericFenwickTree.js new file mode 100644 index 00000000000..e04ce6de936 --- /dev/null +++ b/packages/virtualized-lists/Lists/NumericFenwickTree.js @@ -0,0 +1,91 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +export default class NumericFenwickTree { + _capacity: number = 0; + _tree: Float64Array = new Float64Array(1); + + add(index: number, delta: number): void { + if (delta === 0 || index < 0) { + return; + } + if (index >= this._capacity) { + this._grow(index + 1); + } + for ( + let i = index + 1; + i <= this._capacity; + // eslint-disable-next-line no-bitwise + i += i & -i + ) { + this._tree[i] += delta; + } + } + + prefixSum(index: number): number { + if (index < 0 || this._capacity === 0) { + return 0; + } + let sum = 0; + let i = Math.min(index + 1, this._capacity); + while (i > 0) { + sum += this._tree[i]; + // eslint-disable-next-line no-bitwise + i -= i & -i; + } + return sum; + } + + rangeSum(first: number, last: number): number { + if (last < first || this._capacity === 0) { + return 0; + } + return this.prefixSum(last) - (first > 0 ? this.prefixSum(first - 1) : 0); + } + + findNth(target: number): number { + if (target <= 0 || this._capacity === 0) { + return -1; + } + let pos = 0; + let acc = 0; + for (let step = this._capacity; step > 0; step = Math.floor(step / 2)) { + const next = pos + step; + if (next <= this._capacity && acc + this._tree[next] < target) { + acc += this._tree[next]; + pos = next; + } + } + return pos < this._capacity ? pos : -1; + } + + clear(): void { + this._capacity = 0; + this._tree = new Float64Array(1); + } + + _grow(minSize: number): void { + const oldCap = this._capacity; + let newCap = oldCap > 0 ? oldCap : 16; + while (newCap < minSize) { + newCap *= 2; + } + const nextTree = new Float64Array(newCap + 1); + if (oldCap > 0) { + nextTree.set(this._tree); + const total = this._tree[oldCap]; + for (let p = oldCap * 2; p <= newCap; p *= 2) { + nextTree[p] = total; + } + } + this._capacity = newCap; + this._tree = nextTree; + } +} diff --git a/packages/virtualized-lists/Lists/__tests__/NumericFenwickTree-test.js b/packages/virtualized-lists/Lists/__tests__/NumericFenwickTree-test.js new file mode 100644 index 00000000000..27be62dc0ae --- /dev/null +++ b/packages/virtualized-lists/Lists/__tests__/NumericFenwickTree-test.js @@ -0,0 +1,70 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +import NumericFenwickTree from '../NumericFenwickTree'; + +describe('NumericFenwickTree', () => { + it('computes prefix and range sums across dynamic capacity growth', () => { + const tree = new NumericFenwickTree(); + expect(tree.prefixSum(0)).toBe(0); + expect(tree.rangeSum(0, 10)).toBe(0); + + tree.add(0, 100); + tree.add(5, 250); + tree.add(40, 500); + tree.add(100, 75); + + expect(tree.prefixSum(-1)).toBe(0); + expect(tree.prefixSum(0)).toBe(100); + expect(tree.prefixSum(5)).toBe(350); + expect(tree.prefixSum(40)).toBe(850); + expect(tree.prefixSum(1000)).toBe(925); + + expect(tree.rangeSum(5, 40)).toBe(750); + expect(tree.rangeSum(6, 39)).toBe(0); + expect(tree.rangeSum(10, 5)).toBe(0); + + tree.add(5, -50); + expect(tree.rangeSum(0, 40)).toBe(800); + }); + + it('finds the lowest index whose prefix sum reaches target via findNth', () => { + const tree = new NumericFenwickTree(); + expect(tree.findNth(1)).toBe(-1); + + tree.add(3, 1); + tree.add(17, 1); + tree.add(64, 1); + + expect(tree.findNth(0)).toBe(-1); + expect(tree.findNth(1)).toBe(3); + expect(tree.findNth(2)).toBe(17); + expect(tree.findNth(3)).toBe(64); + expect(tree.findNth(4)).toBe(-1); + + tree.add(17, -1); + expect(tree.findNth(1)).toBe(3); + expect(tree.findNth(2)).toBe(64); + expect(tree.findNth(3)).toBe(-1); + }); + + it('resets state on clear', () => { + const tree = new NumericFenwickTree(); + tree.add(20, 42); + expect(tree.prefixSum(20)).toBe(42); + + tree.clear(); + expect(tree.prefixSum(20)).toBe(0); + expect(tree.findNth(1)).toBe(-1); + + tree.add(2, 15); + expect(tree.prefixSum(2)).toBe(15); + }); +});