Skip to content

Commit ef4e88d

Browse files
Abbondanzofacebook-github-bot
authored andcommitted
Mark FPS listener in ScrollViews as final, avoid reset in initView
Summary: `mFpsListener` is injected via `ReactHorizontalScrollView`'s constructor and should live for the lifetime of the view. However, it was declared as a mutable field and nulled in `initView()`, which is called both during construction and when the view is recycled in a virtualized list. After recycling, `isScrollPerfLoggingEnabled()` returned false because `mFpsListener` was null, silently disabling FPS performance tracking for the rest of that view instance's lifecycle. The fix moves `mFpsListener` to a `final` field initialized in the constructor, and removes the `mFpsListener = null` assignment from `initView()`. Applied to `ReactScrollView`, `ReactHorizontalScrollView`, and `ReactNestedScrollView`. This is a safe change because both view managers are instantiated with a single instance of FPS listener, so recycled view instances will always reference the same FPS listener instance. Changelog: [Android][Fixed] - Fix FPS performance listener being cleared on ScrollView recycle Differential Revision: D102359747
1 parent 4cbe675 commit ef4e88d

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
101101
private final VelocityHelper mVelocityHelper = new VelocityHelper();
102102
private final Rect mTempRect = new Rect();
103103
private final ValueAnimator DEFAULT_FLING_ANIMATOR = ObjectAnimator.ofInt(this, "scrollX", 0, 0);
104+
private final @Nullable FpsListener mFpsListener;
104105

105106
private Rect mOverflowInset = new Rect();
106107
private @Nullable VirtualViewContainerState mVirtualViewContainerState;
@@ -113,7 +114,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
113114
private boolean mRemoveClippedSubviews;
114115
private boolean mScrollEnabled = true;
115116
private boolean mSendMomentumEvents;
116-
private @Nullable FpsListener mFpsListener = null;
117117
private @Nullable String mScrollPerfTag;
118118
private @Nullable Drawable mEndBackground;
119119
private int mEndFillColor = Color.TRANSPARENT;
@@ -177,7 +177,6 @@ private void initView() {
177177
mRemoveClippedSubviews = false;
178178
mScrollEnabled = true;
179179
mSendMomentumEvents = false;
180-
mFpsListener = null;
181180
mScrollPerfTag = null;
182181
mEndBackground = null;
183182
mEndFillColor = Color.TRANSPARENT;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactNestedScrollView.java

Lines changed: 2 additions & 2 deletions
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<<41d03f4948562c0fae870a660e6e1eac>>
7+
* @generated SignedSource<<2aa191314924bd0f969fba0e64b86142>>
88
*/
99

1010
/**
@@ -106,6 +106,7 @@ class ReactNestedScrollView extends NestedScrollView
106106
private final VelocityHelper mVelocityHelper = new VelocityHelper();
107107
private final Rect mTempRect = new Rect();
108108
private final ValueAnimator DEFAULT_FLING_ANIMATOR = ObjectAnimator.ofInt(this, "scrollY", 0, 0);
109+
private final @Nullable FpsListener mFpsListener;
109110

110111
private Rect mOverflowInset;
111112
private @Nullable VirtualViewContainerState mVirtualViewContainerState;
@@ -118,7 +119,6 @@ class ReactNestedScrollView extends NestedScrollView
118119
private boolean mRemoveClippedSubviews;
119120
private boolean mScrollEnabled;
120121
private boolean mSendMomentumEvents;
121-
private @Nullable FpsListener mFpsListener;
122122
private @Nullable String mScrollPerfTag;
123123
private @Nullable Drawable mEndBackground;
124124
private int mEndFillColor;

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class ReactScrollView extends ScrollView
9898
private final VelocityHelper mVelocityHelper = new VelocityHelper();
9999
private final Rect mTempRect = new Rect();
100100
private final ValueAnimator DEFAULT_FLING_ANIMATOR = ObjectAnimator.ofInt(this, "scrollY", 0, 0);
101+
private final @Nullable FpsListener mFpsListener;
101102

102103
private Rect mOverflowInset;
103104
private @Nullable VirtualViewContainerState mVirtualViewContainerState;
@@ -110,7 +111,6 @@ public class ReactScrollView extends ScrollView
110111
private boolean mRemoveClippedSubviews;
111112
private boolean mScrollEnabled;
112113
private boolean mSendMomentumEvents;
113-
private @Nullable FpsListener mFpsListener;
114114
private @Nullable String mScrollPerfTag;
115115
private @Nullable Drawable mEndBackground;
116116
private int mEndFillColor;

0 commit comments

Comments
 (0)