You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 843020f
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-maintainVisibleContentPosition-itest.js
+126Lines changed: 126 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -348,6 +348,132 @@ test('maintainVisibleContentPosition with minIndexForVisible > 0 skips early ite
Copy file name to clipboardExpand all lines: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.kt
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -125,22 +125,40 @@ internal class MaintainVisibleScrollPositionHelper<ScrollViewT>(
125
125
val scrollView = scrollView ?:return
126
126
val contentView = contentView ?:return
127
127
128
+
val children =List(contentView.childCount) { contentView.getChildAt(it) }
129
+
val subviews =
130
+
if (config.minIndexForVisible >0) {
131
+
// We only need to sort if minIndexForVisible is non-zero. Normally, we just do a full
132
+
// linear scan and find the earliest item.
133
+
//
134
+
// If minIndexForVisible is set though, we have to exclude the first `minIndexForVisible`
135
+
// items, which requires sorting to do.
136
+
children.sortedWith(
137
+
compareBy<View>({ if (horizontal) it.x else it.y }, { contentView.indexOfChild(it) }))
138
+
} else {
139
+
children
140
+
}
141
+
142
+
if (config.minIndexForVisible >= subviews.size) {
143
+
return
144
+
}
145
+
128
146
val currentScroll =if (horizontal) scrollView.scrollX else scrollView.scrollY
129
147
var firstVisibleView:View?=null
130
148
// We cannot assume that the views will be in position order because of things like z-index
131
149
// which will change the order of views in their parent. This means we need to iterate through
132
150
// the full children array and find the view with the smallest position that is bigger than
133
151
// the scroll position.
134
152
var firstVisibleViewPosition =Float.MAX_VALUE
135
-
for (i in config.minIndexForVisible until contentView.childCount) {
136
-
val child =contentView.getChildAt(i)
153
+
for (i in config.minIndexForVisible until subviews.size) {
154
+
val child =subviews[i]
137
155
138
156
// Compute the position of the end of the child
139
157
val position =if (horizontal) child.x + child.width else child.y + child.height
140
158
141
159
// If the child is partially visible or this is the last child, select it as the anchor.
142
160
if ((position > currentScroll && position < firstVisibleViewPosition) ||
143
-
(firstVisibleView ==null&& i ==contentView.childCount-1)) {
161
+
(firstVisibleView ==null&& i ==subviews.size-1)) {
0 commit comments