NTP-71293 | Naman | Fixes in section rendering (#16671)
This commit is contained in:
@@ -10,8 +10,8 @@ package com.naviapp.home.compose.home.ui.renderer
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import com.navi.common.alchemist.model.AlchemistWidgetModelDefinition
|
||||
@@ -41,10 +41,15 @@ fun ChunkedWidgetRenderer(
|
||||
)
|
||||
}
|
||||
|
||||
val widgetsToShow = remember(elementList) { mutableIntStateOf(0) }
|
||||
val stableKey =
|
||||
remember(elementList) {
|
||||
elementList.mapNotNull { it.widgetId }.joinToString(",").hashCode()
|
||||
}
|
||||
|
||||
val widgetsToShow = homeVM().widgetsToShowCount.collectAsState()
|
||||
|
||||
Column {
|
||||
elementList.take(widgetsToShow.intValue).forEach { element ->
|
||||
elementList.take(widgetsToShow.value).forEach { element ->
|
||||
key(element.widgetId) {
|
||||
HomeWidgetRenderer(
|
||||
element = element,
|
||||
@@ -56,20 +61,22 @@ fun ChunkedWidgetRenderer(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(elementList) {
|
||||
widgetsToShow.intValue = 0
|
||||
LaunchedEffect(stableKey) {
|
||||
homeVM().resetWidgetsToShow()
|
||||
elementList.indices
|
||||
.chunked(chunkSize)
|
||||
.asFlow()
|
||||
.onEach { slice ->
|
||||
if (slice.last() == elementList.lastIndex) {
|
||||
onEvent(HpEvents.RenderedFirstTime)
|
||||
}
|
||||
val nextCount = slice.last() + 1
|
||||
widgetsToShow.intValue = nextCount
|
||||
homeVM().updateWidgetsToShow(nextCount)
|
||||
withFrameNanos {}
|
||||
if (slice.last() < elementList.lastIndex) {
|
||||
delay(delayBetweenWidgets)
|
||||
}
|
||||
}
|
||||
.collect()
|
||||
onEvent(HpEvents.RenderedFirstTime)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,18 @@ constructor(
|
||||
private val _isClickEnabled: MutableStateFlow<Boolean> = MutableStateFlow(false)
|
||||
val isClickEnabled: StateFlow<Boolean> = _isClickEnabled
|
||||
|
||||
// State to track widget rendering progress
|
||||
private val _widgetsToShowCount: MutableStateFlow<Int> = MutableStateFlow(0)
|
||||
val widgetsToShowCount: StateFlow<Int> = _widgetsToShowCount
|
||||
|
||||
fun resetWidgetsToShow() {
|
||||
_widgetsToShowCount.value = 0
|
||||
}
|
||||
|
||||
fun updateWidgetsToShow(count: Int) {
|
||||
_widgetsToShowCount.value = count
|
||||
}
|
||||
|
||||
fun updateClickEnabledState(isClickEnabled: Boolean) {
|
||||
viewModelScope.safeLaunch(Dispatchers.IO) { _isClickEnabled.value = isClickEnabled }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user