Add loading while grid col count is calculed
This commit is contained in:
parent
f6366cfd3f
commit
ca2e10b9b2
1 changed files with 35 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.geometry.Size
|
import androidx.compose.ui.geometry.Size
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
|
@ -476,13 +477,17 @@ fun TimeUnitComposable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class TUOWidthMeasure(val width: Dp, val isReady: Boolean)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun bestTUOWidth(items: List<TimeUnitObject>): Dp {
|
fun bestTUOWidth(items: List<TimeUnitObject>): TUOWidthMeasure {
|
||||||
val textMeasurer = rememberTextMeasurer()
|
val textMeasurer = rememberTextMeasurer()
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
|
|
||||||
var maxWidth by remember { mutableStateOf(0.dp) }
|
var maxWidth by remember(items) { mutableStateOf(0.dp) }
|
||||||
|
var isReady by remember(items) { mutableStateOf(false) }
|
||||||
LaunchedEffect(items) {
|
LaunchedEffect(items) {
|
||||||
|
isReady = false
|
||||||
maxWidth = 0.dp
|
maxWidth = 0.dp
|
||||||
items.forEach {
|
items.forEach {
|
||||||
val textLayoutResult: TextLayoutResult = textMeasurer.measure(
|
val textLayoutResult: TextLayoutResult = textMeasurer.measure(
|
||||||
|
|
@ -496,8 +501,9 @@ fun bestTUOWidth(items: List<TimeUnitObject>): Dp {
|
||||||
maxWidth = textWidth
|
maxWidth = textWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isReady = true
|
||||||
}
|
}
|
||||||
return maxWidth + 13.dp
|
return TUOWidthMeasure(maxWidth + 13.dp, isReady)
|
||||||
}
|
}
|
||||||
@Composable
|
@Composable
|
||||||
fun AutoResizingText(
|
fun AutoResizingText(
|
||||||
|
|
@ -609,9 +615,13 @@ fun LazyVerticalGridTUO(
|
||||||
val horizontalArrangementSpacing: Dp = 0.dp
|
val horizontalArrangementSpacing: Dp = 0.dp
|
||||||
val columnGroupString = regexMeasure?.groupValues?.get(1) ?: "1"
|
val columnGroupString = regexMeasure?.groupValues?.get(1) ?: "1"
|
||||||
val columnGroup = columnGroupString.toInt().coerceAtLeast(1)
|
val columnGroup = columnGroupString.toInt().coerceAtLeast(1)
|
||||||
val itemMinBaseWidth = bestTUOWidth(tuoList)
|
val tuoWidthMeasure = bestTUOWidth(tuoList)
|
||||||
|
val itemMinBaseWidth = tuoWidthMeasure.width
|
||||||
val gridWidthDp = with(density) { gridWidthPx.toDp() }
|
val gridWidthDp = with(density) { gridWidthPx.toDp() }
|
||||||
|
|
||||||
|
// on affiche un loader pour éviter le "saut" visuel
|
||||||
|
val isLayoutReady = tuoWidthMeasure.isReady && gridWidthDp > 0.dp
|
||||||
|
|
||||||
val gridCount by sharedScreenModel.gridCount.collectAsState()
|
val gridCount by sharedScreenModel.gridCount.collectAsState()
|
||||||
|
|
||||||
var gridColumnCount: Int = remember(gridWidthDp, itemMinBaseWidth, columnGroup) {
|
var gridColumnCount: Int = remember(gridWidthDp, itemMinBaseWidth, columnGroup) {
|
||||||
|
|
@ -680,6 +690,26 @@ fun LazyVerticalGridTUO(
|
||||||
val totalSyllables = sharedScreenModel.synchronizedSyllables.value.size
|
val totalSyllables = sharedScreenModel.synchronizedSyllables.value.size
|
||||||
//println("Sync complète effectuée SUR stz: ${sharedScreenModel.stanza.value}! Total colonnes : $totalSyllables")
|
//println("Sync complète effectuée SUR stz: ${sharedScreenModel.stanza.value}! Total colonnes : $totalSyllables")
|
||||||
}
|
}
|
||||||
|
if (!isLayoutReady) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(200.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(64.dp),
|
||||||
|
strokeWidth = 3.dp
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "𝄞 ♫",
|
||||||
|
style = TextStyle(
|
||||||
|
fontSize = 28.sp,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
|
|
@ -1084,6 +1114,7 @@ fun LazyVerticalGridTUO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun makeSpaceBetweenSyllables(
|
fun makeSpaceBetweenSyllables(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue