Skip to content

Instantly share code, notes, and snippets.

@PiotrPrus
Created December 20, 2021 21:46
Show Gist options
  • Save PiotrPrus/c0540830f7513cf4558cda8abe0b25a1 to your computer and use it in GitHub Desktop.
Save PiotrPrus/c0540830f7513cf4558cda8abe0b25a1 to your computer and use it in GitHub Desktop.
Modifier.tapOrPress(
onStart = { position ->
scope.launch {
selectedBar?.let { selected ->
if (position in selected.xStart..selected.xEnd) {
// click in selected area - do nothing
} else {
tempPosition = position
scope.launch {
tempAnimatable.snapTo(0f)
tempAnimatable.animateTo(1f)
}
}
}
}
},
onCancel = { position ->
tempPosition = -Int.MAX_VALUE.toFloat()
scope.launch {
tempAnimatable.animateTo(0f)
}
},
onCompleted = {
val currentSelected = selectedBar
scope.launch {
selectedPosition = it
animatable.snapTo(tempAnimatable.value)
selectedBar?.data?.let { barData ->
measurementSelected(barData)
}
async {
animatable.animateTo(
1f,
animationSpec = tween(300.times(1f - tempAnimatable.value).roundToInt())
)
}
async {
tempAnimatable.snapTo(0f)
currentSelected?.let {
tempPosition = currentSelected.xStart.plus(1f)
tempAnimatable.snapTo(1f)
tempAnimatable.animateTo(0f)
}
}
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment