https://kotlinlang.org logo
#compose
Title
# compose
s

Sam

11/13/2020, 8:56 PM
hi all, i'm trying to interop with an android view inside of compose, specifically this library Konfetti. It's not filling the screen, nor is the animation playing - this is what i have so far:
Copy code
@Composable
fun Confetti() {
    val context = ContextAmbient.current
    val konfettiView = remember {
        KonfettiView(context).apply {
            build()
                .addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
                .setDirection(0.0, 359.0)
                .setSpeed(1f, 5f)
                .setFadeOutEnabled(true)
                .setTimeToLive(2000L)
                .addShapes(Square, Circle)
                .addSizes(Size(12))
                .setPosition(-50f, 500 + 50f, -50f, -50f)
                .streamFor(300, 5000L)
        }
    }
    
    AndroidView({ konfettiView }, modifier = Modifier.fillMaxSize()) { view ->
        // Do something here?
    }
}
really hard to understand what's going wrong here! any advice?
can I offer a bounty to get help? say $100 venmo?
z

zoha131

11/13/2020, 9:59 PM
I don’t have the solution. But it might help you to find the right direction. I have added a clickable modifier. Now whenever I tap on the screen then the animation get executed for a second and stops. This is weird.
Copy code
@Composable
fun Greeting(name: String) {
    AndroidView(
            viewBlock = {
                KonfettiView(it)
            },
            modifier = Modifier.fillMaxSize()
                    .clickable(onClick = { })
    ) {

        it.build()
                .addColors(Color.YELLOW, Color.GREEN, Color.MAGENTA)
                .setDirection(0.0, 359.0)
                .setSpeed(1f, 5f)
                .setFadeOutEnabled(true)
                .setTimeToLive(2000L)
                .addShapes(Shape.Square, Shape.Circle)
                .addSizes(Size(12))
                .setPosition(-50f, 500 + 50f, -50f, -50f)
                .streamFor(particlesPerSecond = 300, emittingTime = StreamEmitter.INDEFINITE)

    }
}
s

Sam

11/13/2020, 10:00 PM
i'm getting the same behavior, very weird!
as long as i keep tapping, it continues to play
maybe @Ian Lake or @Leland Richardson [G] has an idea as to why animations would only play during the onClick animation?
z

Zach Klippenstein (he/him) [MOD]

11/14/2020, 12:10 AM
This sounds like a bug. Did you file a bug?
s

Sam

11/14/2020, 12:12 AM
i don't know enough about compose to know for sure if it's a bug or if i'm not understanding how interop works. should i file anyway?
a

Adam Powell

11/14/2020, 12:19 AM
Please file. I presume that KonfettiView is calling
View.invalidate()
on itself to perform its animation and that isn't happening as expected here for whatever reason. @Mihai Popa might be interested to take a look next week
m

Mihai Popa

11/17/2020, 11:49 AM
@Sam this certainly looks like a bug, please file a bug unless you have already done so, and I will take a look
s

Sam

11/17/2020, 11:46 PM
hi @Mihai Popa where is the best place to file a bug?
z

Zach Klippenstein (he/him) [MOD]

11/17/2020, 11:49 PM
there’s a link in the channel topic
s

Sam

11/17/2020, 11:51 PM
ok my first time, i have a bunch besides this one that might be helpful
z

zoha131

11/26/2020, 8:28 PM
is there any progress on this? I am having an issue which might be similar with this: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1606422344290000
5 Views