-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhirkevich Alexander Y
authored and
Zhirkevich Alexander Y
committed
Jul 15, 2024
1 parent
67f348c
commit cf9bca0
Showing
18 changed files
with
652 additions
and
278 deletions.
There are no files selected for viewing
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
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
38 changes: 34 additions & 4 deletions
38
...avp/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/avp/AnimatedVectorPainter.kt
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
11 changes: 11 additions & 0 deletions
11
...ottie-avp/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/avp/AnimationTarget.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.alexzhirkevich.compottie.avp | ||
|
||
public class AnimationTarget( | ||
public val name : String, | ||
public val animation: String | ||
) | ||
|
||
public class AnimatedVector( | ||
public val animations : List<AnimationTarget> | ||
) | ||
|
7 changes: 5 additions & 2 deletions
7
...avp/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/avp/animator/AnimatorSpec.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package io.github.alexzhirkevich.compottie.avp.animator | ||
|
||
import io.github.alexzhirkevich.compottie.avp.AnimatedVector | ||
|
||
public interface AnimatorSpec { | ||
|
||
public suspend fun load() : ObjectAnimator<*,*> | ||
public suspend fun load( | ||
animatedVector: AnimatedVector | ||
): Map<String, ObjectAnimator<*, *>> | ||
} |
138 changes: 138 additions & 0 deletions
138
...ie-avp/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/avp/animator/ColorData.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package io.github.alexzhirkevich.compottie.avp.animator | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.LinearGradientShader | ||
import androidx.compose.ui.graphics.RadialGradientShader | ||
import androidx.compose.ui.graphics.Shader | ||
import androidx.compose.ui.graphics.SweepGradientShader | ||
import androidx.compose.ui.graphics.TileMode | ||
|
||
public sealed interface ColorData { | ||
|
||
public sealed class GradientColorData : ColorData { | ||
|
||
public abstract val colorStops: List<Pair<Float, Color>> | ||
|
||
protected val colors : List<Color> get() = mColors | ||
|
||
protected val stops : List<Float> get() = mStops | ||
|
||
|
||
private val mColors by lazy { | ||
colorStops.map { it.second }.toMutableList() | ||
} | ||
|
||
private val mStops by lazy { | ||
colorStops.map { it.first }.toMutableList() | ||
} | ||
|
||
internal abstract val shader : Shader | ||
|
||
internal abstract fun lerpShader(other : GradientColorData, progress: Float) : Shader | ||
|
||
protected fun lerpColorStops(other: GradientColorData, progress: Float) { | ||
require(other.colorStops.size == colorStops.size){ | ||
repeat(colorStops.size) { | ||
mColors[it] = androidx.compose.ui.graphics.lerp( | ||
colorStops[it].second, | ||
other.colorStops[it].second, | ||
progress | ||
) | ||
mStops[it] = androidx.compose.ui.util.lerp( | ||
colorStops[it].first, | ||
other.colorStops[it].first, | ||
progress | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class Solid(public val color: Color) : ColorData | ||
|
||
public class LinearGradient( | ||
override val colorStops : List<Pair<Float, Color>>, | ||
public val start : Offset, | ||
public val end : Offset, | ||
public val tileMode: TileMode | ||
) : GradientColorData() { | ||
|
||
override val shader: Shader by lazy { | ||
LinearGradientShader( | ||
from = start, | ||
to = end, | ||
colors = colors, | ||
colorStops = stops | ||
) | ||
} | ||
|
||
override fun lerpShader(other: GradientColorData, progress: Float): Shader { | ||
other as LinearGradient | ||
lerpColorStops(other, progress) | ||
|
||
return LinearGradientShader( | ||
from = androidx.compose.ui.geometry.lerp(start, other.start, progress), | ||
to = androidx.compose.ui.geometry.lerp(end, other.end, progress), | ||
colors = colors, | ||
colorStops = stops, | ||
tileMode = other.tileMode | ||
) | ||
} | ||
} | ||
|
||
public class RadialGradient( | ||
override val colorStops : List<Pair<Float, Color>>, | ||
public val center : Offset, | ||
public val radius : Float, | ||
public val tileMode: TileMode | ||
) : GradientColorData() { | ||
|
||
override val shader: Shader by lazy { | ||
RadialGradientShader( | ||
center = center, | ||
radius = radius, | ||
colors = colors, | ||
colorStops = stops | ||
) | ||
} | ||
|
||
override fun lerpShader(other: GradientColorData, progress: Float): Shader { | ||
other as RadialGradient | ||
lerpColorStops(other, progress) | ||
|
||
return RadialGradientShader( | ||
center = androidx.compose.ui.geometry.lerp(center, other.center, progress), | ||
radius = androidx.compose.ui.util.lerp(radius, other.radius, progress), | ||
colors = colors, | ||
colorStops = stops, | ||
tileMode = other.tileMode | ||
) | ||
} | ||
} | ||
|
||
public class SweepGradient( | ||
override val colorStops : List<Pair<Float, Color>>, | ||
public val center : Offset, | ||
) : GradientColorData() { | ||
|
||
override val shader: Shader by lazy { | ||
SweepGradientShader( | ||
center = center, | ||
colors = colors, | ||
colorStops = stops | ||
) | ||
} | ||
|
||
override fun lerpShader(other: GradientColorData, progress: Float): Shader { | ||
other as SweepGradient | ||
lerpColorStops(other, progress) | ||
|
||
return SweepGradientShader( | ||
center = androidx.compose.ui.geometry.lerp(center, other.center, progress), | ||
colors = colors, | ||
colorStops = stops, | ||
) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../src/commonMain/kotlin/io/github/alexzhirkevich/compottie/avp/animator/DynamicAnimator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.alexzhirkevich.compottie.avp.animator | ||
|
||
import androidx.compose.animation.core.Easing | ||
import androidx.compose.animation.core.LinearEasing | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import io.github.alexzhirkevich.compottie.avp.xml.AnimatedVectorProperty | ||
|
||
@Composable | ||
public fun rememberNumberAnimator( | ||
duration: Float, | ||
valueFrom: Float, | ||
valueTo: Float, | ||
property: AnimatedVectorProperty<FloatAnimator>, | ||
delay : Float = 0f, | ||
interpolator: Easing = LinearEasing, | ||
) : FloatAnimator { | ||
return remember(duration, valueFrom, valueTo, property, delay, interpolator) { | ||
FloatAnimator(duration, valueFrom, valueTo, property, delay, interpolator) | ||
} | ||
} |
Oops, something went wrong.