DanielMartinus / Konfetti

Celebrate more with this lightweight confetti particle system 🎊
ISC License
3.13k stars 299 forks source link

fix alpha on DrawableShape, on compose: add parameter to apply alpha or not #309

Closed laurentyhuel closed 1 year ago

laurentyhuel commented 1 year ago

Alpha on DrawableShape not had same behavior between Compose and XML View.

I used same parameter:

Party(
                    speed = 0f,
                    maxSpeed = 10f,
                    damping = 1f,
                    spread = 360,
                    size = listOf(Size(sizeInDp = 20, mass = 8f)),
                    shapes = listOf(
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_yellow_2)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_purple_1)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_purple_3)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_green_1)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_blue_1)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_red_2)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_purple_4)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_blue_2)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_red_1)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_yellow_1)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_purple_2)!!, false),
                        Shape.DrawableShape(AppCompatResources.getDrawable(context,R.drawable.img_conf_green_2)!!, false),

                        ),
                    emitter = Emitter(duration = 100, TimeUnit.MILLISECONDS).max(100),
                    position = Position.Relative(0.5, 0.3)
                )

And here the result: confetti-xml-kotlin.webm confetti-compose.webm

I think is same issue as https://github.com/DanielMartinus/Konfetti/issues/298

I could use a sealed interface instead of new boolean parameter but it break compatibility with older version:

data class DrawableShape(
        val drawable: Drawable,
        val transformation: DrawableShapeTransformation = DrawableShapeTransformation.Tint,
    ) : Shape {
        ...
    }

sealed interface DrawableShapeTransformation {
    object Tint : DrawableShapeTransformation
    object Alpha : DrawableShapeTransformation
    object None : DrawableShapeTransformation
}
DanielMartinus commented 1 year ago

@laurentyhuel thanks for the fix, Appreciated! I did some testing and decided to merge the PR as it indeed solves the issue

laurentyhuel commented 1 year ago

@laurentyhuel thanks for the fix, Appreciated! I did some testing and decided to merge the PR as it indeed solves the issue

Oh great, do you plan a new release soon ?

DanielMartinus commented 1 year ago

@laurentyhuel yes, definitely! Working on it

DanielMartinus commented 1 year ago

New version is released: https://github.com/DanielMartinus/Konfetti/releases/tag/v2.0.3