Skip to content

Commit 2dfb36e

Browse files
CalixTangfacebook-github-bot
authored andcommitted
Simplify VirtualViewContainer hysteresis window logic (facebook#53914)
Summary: Pull Request resolved: facebook#53914 Pulls hysteresis window computation out of for loop. Simplify the remaining code. Changelog: [Internal] - Same as general summary. Reviewed By: lunaleaps Differential Revision: D83005735 fbshipit-source-id: 824863c649406a750d44b31ac92878505ab61596
1 parent 10b45b6 commit 2dfb36e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ internal class VirtualViewContainerState {
121121
(-prerenderRect.height() * prerenderRatio).toInt(),
122122
)
123123

124+
if (hysteresisRatio > 0.0) {
125+
hysteresisRect.set(prerenderRect)
126+
hysteresisRect.inset(
127+
(-visibleRect.width() * hysteresisRatio).toInt(),
128+
(-visibleRect.height() * hysteresisRatio).toInt(),
129+
)
130+
}
131+
124132
val virtualViewsIt =
125133
if (virtualView != null) listOf(virtualView) else virtualViews.toMutableSet()
126134
virtualViewsIt.forEach { vv ->
@@ -145,17 +153,8 @@ internal class VirtualViewContainerState {
145153
mode = VirtualViewMode.Prerender
146154
thresholdRect = prerenderRect
147155
}
148-
else -> {
149-
if (hysteresisRatio > 0.0) {
150-
hysteresisRect.set(prerenderRect)
151-
hysteresisRect.inset(
152-
(-visibleRect.width() * hysteresisRatio).toInt(),
153-
(-visibleRect.height() * hysteresisRatio).toInt(),
154-
)
155-
if (rectsOverlap(rect, hysteresisRect)) {
156-
mode = null
157-
}
158-
}
156+
(hysteresisRatio > 0.0 && rectsOverlap(rect, hysteresisRect)) -> {
157+
mode = null
159158
}
160159
}
161160

0 commit comments

Comments
 (0)