NTP-13179 | unpaid bills list index out of bound crash fix (#13674)

This commit is contained in:
Mohit Rajput
2024-11-19 02:54:59 -08:00
committed by GitHub
parent 4610ea8d7a
commit 63c8abc804

View File

@@ -69,13 +69,16 @@ import com.navi.bbps.feature.category.model.view.MyBillCardInfoState
import com.navi.bbps.feature.category.model.view.RewardDataEntity
import com.navi.bbps.feature.mybills.model.view.MyBillEntity
import com.navi.common.R as CommonR
import com.navi.common.utils.log
import com.navi.design.common.NaviVerticalGrid
import com.navi.design.font.FontWeightEnum
import com.navi.design.theme.ABABAB
import com.navi.design.theme.getFontWeight
import com.navi.design.theme.ttComposeFontFamily
import com.navi.naviwidgets.extensions.NaviText
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.debounce
typealias CategoryGroupId = String
@@ -202,7 +205,7 @@ fun PendingCountSection(
Spacer(modifier = Modifier.height(16.dp))
}
@OptIn(ExperimentalFoundationApi::class)
@OptIn(ExperimentalFoundationApi::class, FlowPreview::class)
@Composable
internal fun PendingBillCarouselSection(
nonDismissedUnpaidBills: List<MyBillEntity>,
@@ -215,12 +218,10 @@ internal fun PendingBillCarouselSection(
val itemWidth by
remember(nonDismissedUnpaidBills.size) {
derivedStateOf {
if (nonDismissedUnpaidBills.isEmpty()) {
configuration.screenWidthDp.dp
} else if (nonDismissedUnpaidBills.size == 1) {
configuration.screenWidthDp.dp - 16.dp
} else {
configuration.screenWidthDp.dp - 32.dp
when (nonDismissedUnpaidBills.size) {
0 -> configuration.screenWidthDp.dp
1 -> maxOf(configuration.screenWidthDp.dp - 16.dp, 0.dp)
else -> maxOf(configuration.screenWidthDp.dp - 32.dp, 0.dp)
}
}
}
@@ -229,9 +230,16 @@ internal fun PendingBillCarouselSection(
LaunchedEffect(listState, nonDismissedUnpaidBills.size) {
snapshotFlow { listState.firstVisibleItemIndex }
.debounce(50)
.collectLatest { index ->
if (index < nonDismissedUnpaidBills.size) {
listState.scrollToItem(index)
try {
if (index < nonDismissedUnpaidBills.size) {
listState.scrollToItem(index)
} else {
listState.scrollToItem(0) // Safe fallback
}
} catch (e: Exception) {
e.log()
}
}
}