From ed409af0a3664b122ed808a729104af7d97e17ae Mon Sep 17 00:00:00 2001 From: Mahdi Hosseinzadeh Date: Wed, 10 Jul 2024 09:58:03 +0330 Subject: [PATCH] Reuse and rewind the same path for the wave Resolves #4 --- .../kotlin/ir/mahozad/multiplatform/wavyslider/Core.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/wavyslider/Core.kt b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/wavyslider/Core.kt index 6813100..5e368ee 100644 --- a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/wavyslider/Core.kt +++ b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/wavyslider/Core.kt @@ -107,6 +107,7 @@ data class WaveAnimationSpecs( */ typealias WaveVelocity = Pair +private val wavyPath = Path() internal val defaultIncremental = false internal val defaultWaveLength = 20.dp internal val defaultWaveHeight = 6.dp @@ -177,7 +178,8 @@ internal inline fun DrawScope.createWavyPath( waveSpread: Float, waveShift: Dp, incremental: Boolean -): Path = Path().apply { +): Path = wavyPath.apply { + rewind() val waveShiftPx = waveShift.toPx() val waveLengthPx = waveLength.toPx() val waveHeightPx = waveHeight.toPx().absoluteValue