From d12cb7269bd7705ac6be644fa8ef9f7082f97ffb Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 27 Sep 2024 00:12:35 +0200 Subject: [PATCH] Fixed using Composable's scope instead of GlobalScope --- .../banking/ui/composables/tan/ChipTanFlickerCodeView.kt | 4 +++- .../net/codinux/banking/ui/service/tan/FlickerCodeAnimator.kt | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/tan/ChipTanFlickerCodeView.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/tan/ChipTanFlickerCodeView.kt index 58fda29..165e87e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/tan/ChipTanFlickerCodeView.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/composables/tan/ChipTanFlickerCodeView.kt @@ -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 } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/tan/FlickerCodeAnimator.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/tan/FlickerCodeAnimator.kt index a46a373..85d613e 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/tan/FlickerCodeAnimator.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/tan/FlickerCodeAnimator.kt @@ -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)