Here, I used a LazyRow with the snappingLayout behavior & the items number of that LazyRow is the size of a list which contains listOf some dates
GetScrollIndex(dateName = listOf("Monday", "Tuesday", "Wednesday", "Thursday"))
I want to change the text value
text = dateName[0] hardcoded value to dynamic value that will change its value according to the position of the snappingLayouts index number
Here's What I Tried
@Composable
fun MainUi() {
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) {
GetScrollIndex(dateName = listOf("Monday", "Tuesday", "Wednesday", "Thursday"))
}
}
@Suppress("OPT_IN_IS_NOT_ENABLED")
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun GetScrollIndex(dayName: List<String>) {
val state = rememberLazyListState()
val snappingLayout = remember(state) { SnapLayoutInfoProvider(state) }
val flingBehavior = rememberSnapFlingBehavior(snappingLayout)
Column {
Text(
modifier = Modifier
.fillMaxWidth(),
text = dateName[0],
style = GoogleSansTypography.titleMedium,
color = MaterialTheme.colorScheme.secondary,
textAlign = TextAlign.Center
)
LazyRow(
state = state,
flingBehavior = flingBehavior,
modifier = Modifier
.fillMaxSize(),
contentPadding = PaddingValues(
horizontal = 30.dp,
vertical = 40.dp
),
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
items(dayName.size) {
Card(
modifier = Modifier
.fillParentMaxSize(),
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.primary)
) {
}
}
}
}
}