From e926ad04288b7e7ca35f228eae21874a0f9155f6 Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Thu, 9 Oct 2025 20:59:18 -0700 Subject: [PATCH] Allow overriding the horizontal scroll position restore (#54115) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54115 Horizontal scroll view extensions should be able to customize the scrolling behavior for state restores. This adds the `restoreScrollTo` function that will be called to restore the scroll position to the location provided by the shadow node state. Changelog: [Internal] Reviewed By: rozele Differential Revision: D84310601 fbshipit-source-id: 007caa3d0922a5430ffc6f970eebb180a112f894 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 1 + .../react/views/scroll/ReactHorizontalScrollView.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 99a4ce525e1..e4568253663 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -5618,6 +5618,7 @@ public class com/facebook/react/views/scroll/ReactHorizontalScrollView : android public fun pageScroll (I)Z public fun reactSmoothScrollTo (II)V public fun requestChildFocus (Landroid/view/View;Landroid/view/View;)V + protected fun restoreScrollTo (II)V public fun scrollTo (II)V public fun scrollToPreservingMomentum (II)V public fun setBackgroundColor (I)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index 3521d244a18..948285d831a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -1660,10 +1660,14 @@ public class ReactHorizontalScrollView extends HorizontalScrollView if (ReactNativeFeatureFlags.enableViewCulling() || ReactNativeFeatureFlags.useTraitHiddenOnAndroid()) { Point scrollPosition = scrollState.getLastStateUpdateScroll(); - scrollTo(scrollPosition.x, scrollPosition.y); + restoreScrollTo(scrollPosition.x, scrollPosition.y); } } + protected void restoreScrollTo(int x, int y) { + scrollTo(x, y); + } + @Override public ReactScrollViewScrollState getReactScrollViewScrollState() { return mReactScrollViewScrollState;