I have a list that includes Slider the problem is when I scroll the slider detecting the tap event and change it, see attached gif
The excepted behavior is when the user scroll the slider not will change just when the user tap on the slider.
How can I avoid changing the slider while scrolling?
Relevant code:
@Composable
fun TodoScreen(
items: List<TodoItem>,
currentlyEditing: TodoItem?,
onAddItem: (TodoItem) -> Unit,
onRemoveItem: (TodoItem) -> Unit,
onStartEdit: (TodoItem) -> Unit,
onEditItemChange: (TodoItem) -> Unit,
onEditDone: () -> Unit,
onPositionChanged: (TodoItem, Float) -> Unit
) {
Column {
val enableTopSection = currentlyEditing == null
TodoItemInputBackground(elevate = enableTopSection) {
if (enableTopSection) {
TodoItemEntryInput(onAddItem)
} else {
Text(
text = "Editing item",
style = MaterialTheme.typography.h6,
textAlign = TextAlign.Center,
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(16.dp)
.fillMaxWidth()
)
}
}
LazyColumn(
modifier = Modifier.weight(1f),
contentPadding = PaddingValues(top = 8.dp)
) {
items(items = items) { todo ->
if (currentlyEditing?.id == todo.id) {
Log.d("ListTodo", "task: ${todo.task}")
TodoItemInlineEditor(
item = currentlyEditing,
onEditItemChange = onEditItemChange,
onEditDone = onEditDone,
onRemoveItem = { onRemoveItem(todo) }
)
} else {
TodoRow(
todo = todo,
onItemClicked = { onStartEdit(it) },
modifier = Modifier.fillParentMaxWidth(),
position = todo.position,
onPositionChanged = onPositionChanged
)
}
}
}
// For quick testing, a random item generator button
Button(
onClick = { onAddItem(generateRandomTodoItem()) },
modifier = Modifier
.padding(16.dp)
.fillMaxWidth(),
) {
Text("Add random item")
}
}
}
And
@Composable
fun TodoRow(
todo: TodoItem,
onItemClicked: (TodoItem) -> Unit,
modifier: Modifier = Modifier,
iconAlpha: Float = remember(todo.id) { randomTint() },
position: Float,
onPositionChanged: (TodoItem, Float) -> Unit
) {
Column() {
Row(
modifier
.clickable { onItemClicked(todo) }
.padding(horizontal = 16.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(todo.task)
Icon(
imageVector = todo.icon.imageVector,
tint = LocalContentColor.current.copy(alpha = iconAlpha),
contentDescription = stringResource(id = todo.icon.contentDescription)
)
}
Slider(value = position, onValueChange = { onPositionChanged(todo.copy(position = it), it) })
}
}