Fixed using Composable's scope instead of GlobalScope

This commit is contained in:
dankito 2024-09-27 00:12:35 +02:00
parent e3a6cd7df2
commit d12cb7269b
2 changed files with 5 additions and 3 deletions

View File

@ -44,6 +44,8 @@ fun ChipTanFlickerCodeView(flickerCode: FlickerCode, textColor: Color = Color.Bl
var step by remember { mutableStateOf(Step(Bit.High, Bit.High, Bit.High, Bit.High, Bit.High)) }
val coroutineScope = rememberCoroutineScope()
fun setSize(width: Dp, height: Dp, spaceBetween: Dp) {
stripesWidth = width
@ -157,7 +159,7 @@ fun ChipTanFlickerCodeView(flickerCode: FlickerCode, textColor: Color = Color.Bl
DisposableEffect(animator) {
animator.setFrequency(frequency)
animator.animateFlickerCode(flickerCode) {
animator.animateFlickerCode(flickerCode, coroutineScope) {
step = it
}

View File

@ -26,11 +26,11 @@ class FlickerCodeAnimator {
fun animateFlickerCode(flickerCode: FlickerCode, showStep: (Step) -> Unit) { // TODO: find better coroutine scope
fun animateFlickerCode(flickerCode: FlickerCode, scope: CoroutineScope , showStep: (Step) -> Unit) {
stop() // stop may still running previous animation
flickerCode.parsedDataSet?.let { parsedDataSet ->
animationJob = GlobalScope.launch(Dispatchers.Default) {
animationJob = scope.launch(Dispatchers.Default) {
val steps = FlickerCodeStepsCalculator().calculateSteps(parsedDataSet)
calculateAnimation(steps, showStep)