Skip to content

Instantly share code, notes, and snippets.

View riggaroo's full-sized avatar
🌍

Rebecca Franks riggaroo

🌍
View GitHub Profile
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@riggaroo
riggaroo / CompositingStrategyOffscreenExample.kt
Last active May 27, 2024 16:20
GraphicsLayer CompositingStrategy Example demonstrating offscreen compositing strategy in Jetpack Compose, leveraging BlendMode.Clear to mask some of the image away.
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun GraphicsLayerCompositingStrategyExample() {
Image(painter = painterResource(id = R.drawable.dog),
contentDescription = "Dog",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(120.dp)
.aspectRatio(1f)
@riggaroo
riggaroo / GradientAlongPathAnimation.kt
Last active December 26, 2024 20:07
Gradient along a path using path.flatten in Compose, Inspired by William Candillon https://youtu.be/7SCzL-XnfUU, this uses Jetpack Compose to draw a gradient along a path https://github.com/wcandillon/can-it-be-done-in-react-native/tree/master/bonuses/skia-examples/src/PathGradient
package androidx.compose.samples.animationfactory
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
@riggaroo
riggaroo / AnimatedText.kt
Created May 8, 2024 16:32
Animate text character by character as you type.
@Preview
@Composable
private fun AnimatedText() {
val text = "This text animates as though it is being typed \uD83E\uDDDE\u200D♀\uFE0F \uD83D\uDD10 \uD83D\uDC69\u200D❤\uFE0F\u200D\uD83D\uDC68 \uD83D\uDC74\uD83C\uDFFD"
// Use BreakIterator as it correctly iterates over characters regardless of how they are
// stored, for example, some emojis are made up of multiple characters.
// You don't want to break up an emoji as it animates, so using BreakIterator will ensure
// this is correctly handled!
val breakIterator = remember(text) { BreakIterator.getCharacterInstance() }
@riggaroo
riggaroo / GraphicsBlend.kt
Last active May 27, 2024 16:19
GraphicsLayer APIs - BlendMode per layer
@Preview
@Composable
private fun GraphicsLayerBlendModes() {
Box(modifier = Modifier
.fillMaxSize()){
Image(
painter = painterResource(id = R.drawable.sunset),
contentDescription = null
)
val graphicsLayer2 = rememberGraphicsLayer()
@riggaroo
riggaroo / AnimateBounds.kt
Last active December 27, 2024 08:07
Simple Modifier.animateBounds() example
@OptIn(ExperimentalSharedTransitionApi::class)
@Preview
@Composable
private fun AnimateBoundsSimple() {
// We need the SharedTransitionLayout in order for the animateBounds modifier to have a
// lookaheadScope to use.
SharedTransitionLayout {
var position by remember {
mutableStateOf(true)
}
@riggaroo
riggaroo / KeyframesWithSpline.kt
Created December 17, 2024 11:34
KeyframesWithSpline Example
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.animateValue
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.keyframesWithSpline
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints