Skip to content

Instantly share code, notes, and snippets.

@maiatoday
maiatoday / Confetti.kt
Created May 26, 2022 19:46
confetti modifier
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
)
)
@maiatoday
maiatoday / boxWithConfetti.kt
Created May 26, 2022 19:45
Using the Confetti modifier
Box(modifier = Modifier
.background(Color.Black)
.fillMaxSize()
.confetti()
) {
Text("Hello World", color = Color.Red)
}
@Composable
fun GlitterBox(
rainbow: List<Color> = SkittlesRainbow,
fleckCount: Int = 2,
visible: Boolean = true
) {
var size by remember { mutableStateOf(Size.Zero) }
var source by remember { mutableStateOf(Offset(200f, 200f)) }
var glitterState by remember {
@Composable
fun HeartPulse(modifier: Modifier = Modifier) {
val infiniteTransition = rememberInfiniteTransition()
val heartSize by infiniteTransition.animateFloat(
initialValue = 0.5f,
targetValue = 1.5f,
animationSpec = infiniteRepeatable(
animation = tween(1000, easing = FastOutSlowInEasing),
repeatMode = RepeatMode.Reverse
@Composable
fun Heart(modifier: Modifier = Modifier, color: Color = Color.Red, size: Dp = 100.dp) {
Surface(
shape = HeartShape,
color = color,
modifier = modifier
.height(size)
.width(size)
) {
@maiatoday
maiatoday / heartShape.kt
Created May 26, 2022 18:47
heart shape
// Thank You https://mahendranv.github.io/posts/compose-shapes-gists/
val HeartShape = GenericShape { size, _ ->
val h = size.height
val w = size.width
lineTo(0.5f*w, 0.25f*h)
cubicTo(0.5f*w, 0.225f*h, 0.458333333333333f*w, 0.125f*h, 0.291666666666667f*w, 0.125f*h)
cubicTo(0.0416666666666667f*w, 0.125f*h, 0.0416666666666667f*w, 0.4f*h, 0.0416666666666667f*w, 0.4f*h)
cubicTo(0.0416666666666667f*w, 0.583333333333333f*h, 0.208333333333333f*w, 0.766666666666667f*h, 0.5f*w, 0.916666666666667f*h)
cubicTo(0.791666666666667f*w, 0.766666666666667f*h, 0.958333333333333f*w, 0.583333333333333f*h, 0.958333333333333f*w, 0.4f*h)
cubicTo(0.958333333333333f*w, 0.4f*h, 0.958333333333333f*w, 0.125f*h, 0.708333333333333f*w, 0.125f*h)
@Composable
fun rainbowState(
rainbow: List<Color> = SkittlesRainbow,
duration: Int = 3000
): State<Color> {
val infiniteTransition = rememberInfiniteTransition()
val interval = duration / rainbow.size
return infiniteTransition.animateColor(
initialValue = rainbow[0],
targetValue = rainbow.last(),
@Composable
fun LifeSaver(rainbow: List<Color> = SkittlesRainbow) {
val color by rainbowState(rainbow = rainbow, duration = 2000)
val highlight by rainbowState(PastelRainbow, 2000)
val infiniteTransition = rememberInfiniteTransition()
val arcAngle1 by infiniteTransition.animateFloat(
initialValue = 0F,
targetValue = 180F,
animationSpec = infiniteRepeatable(
animation = tween(5000, easing = LinearEasing),
@maiatoday
maiatoday / cursorVisible.kt
Last active May 26, 2022 18:43
CursorVisible
@Composable
fun CursorVisible(content: @Composable () -> Unit) {
val boxSize = 100.dp
val boxPx = with(LocalDensity.current) { boxSize.toPx() }
var offset by remember { mutableStateOf(Offset(0f, 0f)) }
var visible by remember { mutableStateOf(false) }
Box(modifier = Modifier
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures {
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.2"
// Custom reports directory can be specfied like this:
// reportsDir = file("$buildDir/customJacocoReportDir")
}
project.afterEvaluate {