Created
December 20, 2021 21:46
-
-
Save PiotrPrus/c0540830f7513cf4558cda8abe0b25a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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