Skip to content

Commit

Permalink
Bounds check read on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Dec 17, 2024
1 parent d10201e commit 746fd1d
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fun MarkReadOnScroll(
return@collect
}

articles[index]?.let { onRead(MarkRead.After(it.id)) }
articles.getOrNull(index)?.let { onRead(MarkRead.After(it.id)) }
}
}
}
Expand Down Expand Up @@ -183,3 +183,7 @@ fun rememberArticleOptions(appPreferences: AppPreferences = koinInject()): Artic
fontScale = fontScale,
)
}

private fun <T : Any> LazyPagingItems<T>.getOrNull(index: Int): T? {
return if (index in 0..<itemCount) get(index) else null
}

0 comments on commit 746fd1d

Please sign in to comment.