Skip to content

Commit eeb8b3b

Browse files
committed
fix(android): NPE fix
1 parent 60e88b2 commit eeb8b3b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/collectionview/platforms/android/java/com/nativescript/collectionview/GridLayoutManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public int computeVerticalScrollOffset(RecyclerView.State state) {
2828
}
2929
final int firstChildPosition = findFirstVisibleItemPosition();
3030
final View firstChild = findViewByPosition(firstChildPosition);
31+
if (firstChild == null) {
32+
return 0;
33+
}
3134
float scrolledY = -firstChild.getY();
3235
for (int i = 0; i < firstChildPosition; i++) {
3336
if (childSizesMap.get(i) != null) {

packages/collectionview/platforms/android/java/com/nativescript/collectionview/PreCachingGridLayoutManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public int computeVerticalScrollOffset(RecyclerView.State state) {
3333
// fixed computeVerticalScrollOffset
3434
View firstItemView = getChildAt(0);
3535
View lastItemView = getChildAt(getChildCount() - 1);
36+
if (firstItemView == null || lastItemView == null) {
37+
return 0;
38+
}
3639

3740
int firstItem = getPosition(firstItemView);
3841
int lastItem = getPosition(lastItemView);

0 commit comments

Comments
 (0)