Skip to content

Commit 41a1467

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
Fix VirtualViewExperimental alignment for empty cases (#53519)
Summary: Pull Request resolved: #53519 Changelog: [Internal] - Remove empty checks on the target rects and early return for empty ScrollView rects -- aligning the implementation with v1 of VirtualView Reviewed By: yungsters Differential Revision: D81247994 fbshipit-source-id: 4fda9f90e18d736944fe4236a4b79f0681e1564c
1 parent 09be5d9 commit 41a1467

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTVirtualViewContainerState.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ - (void)_updateModes:(id<RCTVirtualViewProtocol>)virtualView
161161
RCTVirtualViewMode mode = RCTVirtualViewModeHidden;
162162
CGRect thresholdRect = _emptyRect;
163163

164-
if (CGRectIsEmpty(rect)) {
165-
mode = RCTVirtualViewModeHidden;
166-
thresholdRect = _emptyRect;
167-
} else if (CGRectOverlaps(rect, visibleRect)) {
164+
if (CGRectOverlaps(rect, visibleRect)) {
168165
thresholdRect = visibleRect;
169166
mode = RCTVirtualViewModeVisible;
170167
} else if (CGRectOverlaps(rect, _prerenderRect)) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ internal class VirtualViewContainerState {
104104

105105
private fun updateModes(virtualView: VirtualView? = null) {
106106
scrollView.getDrawingRect(visibleRect)
107+
108+
// This happens because ScrollView content isn't ready yet. The danger here is if ScrollView
109+
// intentionally goes but curently ScrollView and v1 Fling use this check to determine if
110+
// "content ready"
111+
if (visibleRect.isEmpty()) {
112+
debugLog("updateModes", { "scrollView visibleRect is empty" })
113+
return
114+
}
115+
107116
prerenderRect.set(visibleRect)
108117
prerenderRect.inset(
109118
(-prerenderRect.width() * prerenderRatio).toInt(),
@@ -117,7 +126,6 @@ internal class VirtualViewContainerState {
117126
var mode = VirtualViewMode.Hidden
118127
var thresholdRect = emptyRect
119128
when {
120-
rect.isEmpty -> {}
121129
rectsOverlap(rect, visibleRect) -> {
122130
thresholdRect = visibleRect
123131
if (onWindowFocusChangeListener != null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/virtual/viewexperimental/ReactVirtualViewExperimental.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public class ReactVirtualViewExperimental(context: Context) :
129129
}
130130

131131
override fun onModeChange(newMode: VirtualViewMode, thresholdRect: Rect) {
132+
modeChangeEmitter ?: return
133+
scrollView ?: return
134+
132135
if (newMode == mode) {
133136
return
134137
}

0 commit comments

Comments
 (0)