Created
May 26, 2022 19:46
-
-
Save maiatoday/6a74495125a5db654205b4c962c2f5ce to your computer and use it in GitHub Desktop.
confetti modifier
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
fun Modifier.confetti( | |
// all your parameters to set up the modifier | |
) = composed { // the composed function gives you a composition on each composable where this modifier is used | |
// remeber any state you need here | |
var confettiState by remember { | |
mutableStateOf( | |
ConfettiState( | |
// parameters to setup the state | |
) | |
) | |
} | |
LaunchedEffect(isVisible) { | |
while (isVisible && isActive) { | |
withFrameMillis { newTick -> | |
// this side effect will return a tick every frame giving | |
// the elapsed time since the previous frame | |
// This would be the place where you move the particles | |
} | |
} | |
} | |
onSizeChanged { | |
// do what you need to do if the size changes | |
}.drawBehind { | |
// this is where you can draw behind what ever composable content. | |
// It proveds a drawScope with a canvas which you can use | |
// e.g. loop through the particles and draw them | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment