From 8f209acb3f7338448b0b7a26224fc4b2cfb722db Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 5 Mar 2025 11:47:52 -0800 Subject: [PATCH] Fix out of sync state in ScrollView after animation Summary: It seems that if we update the scroll state when the state wrapper is null we can get into an out of sync state. I've replicated the issue in HelpCenter and confirmed with a video this seems to be the case (i.e. when gazing on some cards, their corresponding frame is incorrect) https://www.internalfb.com/intern/px/p/6xWgl NOTE: I have accidentally stumbled upon this fix but I could really use a review from someone who has more context around the `ReactScrollViewHelper` because this change might have bigger implications I'm not aware of! Changelog: [Android][Fixed] - Fix occasional syncronization issue in ScrollView when rendering dynamic content with content offset Commits affecting the React Native open source repository must have a changelog entry in the commit summary. Every React Native release has almost 1000 commits, and manually categorizing these commits is very time consuming. In your diff summary, please add a `Changelog:` entry using the format: The "Category" field may be one of: - **Android**, for changes that affect Android. - **iOS**, for changes that affect iOS. - **General**, for changes that do not fit any of the other categories. - **Internal**, for changes that would not be relevant to developers consuming the release notes. The "Type" field may be one of: - **Breaking**, for breaking changes. - **Added**, for new features. - **Changed**, for changes in existing functionality. - **Deprecated**, for soon-to-be removed features. - **Removed**, for now removed features. - **Fixed**, for any bug fixes. - **Security**, in case of vulnerabilities. If your change does not modify React Native's public interface, you can use: Changelog: [Internal] For more details, please read the wiki: https://fburl.com/react-native/changelog Reviewed By: javache Differential Revision: D70484547 fbshipit-source-id: c314b958eeed4dd96755539f5bbfb8f03e17a525 --- .../com/facebook/react/views/scroll/ReactScrollViewHelper.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt index df3d8e98b30..5b3f661c634 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt @@ -315,6 +315,11 @@ public object ReactScrollViewHelper { if (ViewUtil.getUIManagerType(scrollView.id) == UIManagerType.DEFAULT) { return } + // NOTE: if the state wrapper is null, we shouldn't even update + // the scroll state because there is a chance of going out of sync! + if (scrollView.stateWrapper == null) { + return + } val scrollState = scrollView.reactScrollViewScrollState // Dedupe events to reduce JNI traffic if (scrollState.lastStateUpdateScroll.equals(scrollX, scrollY)) {