From c6a57172f8948a10598990ce05a25a930465be92 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Thu, 11 Apr 2024 14:43:59 +0530 Subject: [PATCH] Handle featured posts section crash when featured posts list size changes --- .../rss/reader/home/ui/FeaturedSection.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/FeaturedSection.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/FeaturedSection.kt index 635284c8a..13241d6b7 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/FeaturedSection.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/FeaturedSection.kt @@ -171,18 +171,19 @@ internal fun FeaturedSection( snapAnimationSpec = spring(stiffness = Spring.StiffnessVeryLow) ) ) { page -> - val featuredPost = featuredPosts[page] - - FeaturedPostItem( - item = featuredPost, - page = page, - pagerState = pagerState, - onClick = { onItemClick(featuredPost) }, - onBookmarkClick = { onPostBookmarkClick(featuredPost) }, - onCommentsClick = { onPostCommentsClick(featuredPost.commentsLink!!) }, - onSourceClick = { onPostSourceClick(featuredPost.feedLink) }, - onTogglePostReadClick = { onTogglePostReadClick(featuredPost.link, featuredPost.read) } - ) + val featuredPost = featuredPosts.getOrNull(page) + if (featuredPost != null) { + FeaturedPostItem( + item = featuredPost, + page = page, + pagerState = pagerState, + onClick = { onItemClick(featuredPost) }, + onBookmarkClick = { onPostBookmarkClick(featuredPost) }, + onCommentsClick = { onPostCommentsClick(featuredPost.commentsLink!!) }, + onSourceClick = { onPostSourceClick(featuredPost.feedLink) }, + onTogglePostReadClick = { onTogglePostReadClick(featuredPost.link, featuredPost.read) } + ) + } } } }