In my Jetpack Compose project, one of my components uses a FlowRow
from Accompanist.
But I don't know how to make the FlowRow
scroll to a given "node".
Here the relevant code from my @Composable
:
sealed class MovesNavigatorElement(open val text: String)
data class MoveNumber(override val text: String) : MovesNavigatorElement(text)
data class HalfMoveSAN(override val text: String) : MovesNavigatorElement(text)
@Composable
fun MovesNavigator(modifier: Modifier = Modifier, elements: Array<MovesNavigatorElement>, mustBeVisibleByDefaultElementIndex: Int) {
val vertScrollState = rememberScrollState()
FlowRow(
modifier = modifier
.background(color = Color.Yellow.copy(alpha = 0.3f))
.verticalScroll(vertScrollState),
mainAxisSpacing = 10.dp,
crossAxisSpacing = 15.dp,
) {
elements.map {
Text(text = it.text, fontSize = 34.sp, color = Color.Blue, style= MaterialTheme.typography.body1)
}
}
}
Where you can see that I declare the "nodes" of the FlowRow
as a list : the parameter elements
. Also I'm using a ScrollState
in the local variable vertScrollState
.
But, let's say that I want to make it scroll to elements[30]
: how should I do that ? Given that mustBeVisibleByDefaultElementIndex
is the index of the element that must be visible by default. I mean, when composition occurs. But the user can change the position later of course.
In other words :
- At composition : the element whose index is given is made visible
- Then, before any other composition occurs of course, the user can scroll it with the scrollbar.