Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
package com.codingwithmitch.mvvmrecipeapp.presentation.components

import androidx.compose.animation.core.*
import androidx.compose.animation.transition
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.dp
import com.codingwithmitch.mvvmrecipeapp.presentation.components.PulseAnimationDefinitions.PulseState.FINAL
import com.codingwithmitch.mvvmrecipeapp.presentation.components.PulseAnimationDefinitions.PulseState.INITIAL
import com.codingwithmitch.mvvmrecipeapp.presentation.components.PulseAnimationDefinitions.pulseDefinition
import com.codingwithmitch.mvvmrecipeapp.presentation.components.PulseAnimationDefinitions.pulsePropKey


@Composable
fun PulsingDemo(){
fun PulsingDemo() {
val color = MaterialTheme.colors.primary

val pulseAnim = transition(
definition = pulseDefinition,
initState = INITIAL,
toState = FINAL
val infiniteTransition = rememberInfiniteTransition()
val pulseMagnitude by infiniteTransition.animateFloat(
initialValue = 40f,
targetValue = 50f,
animationSpec = infiniteRepeatable(
animation = tween(500, easing = FastOutSlowInEasing),
repeatMode = RepeatMode.Restart
)
)

val pulseMagnitude = pulseAnim[pulsePropKey]

Row(
modifier = Modifier
.fillMaxWidth()
.height(55.dp),
horizontalArrangement = Arrangement.Center
){
) {
Image(
modifier = Modifier
.align(Alignment.CenterVertically)
.height(pulseMagnitude.dp)
.width(pulseMagnitude.dp)
,
imageVector = Icons.Default.Favorite.copy(),
.width(pulseMagnitude.dp),
imageVector = Icons.Default.Favorite,
contentDescription = ""
)
}


Canvas(
modifier = Modifier.fillMaxWidth().height(55.dp),
modifier = Modifier
.fillMaxWidth()
.height(55.dp),
) {
drawCircle(
radius = pulseMagnitude,
Expand All @@ -59,33 +57,6 @@ fun PulsingDemo(){
}


object PulseAnimationDefinitions{

enum class PulseState{
INITIAL, FINAL
}

val pulsePropKey = FloatPropKey("pulseKey")

val pulseDefinition = transitionDefinition<PulseState> {
state(INITIAL) { this[pulsePropKey] = 40f }
state(FINAL) { this[pulsePropKey] = 50f }

transition(
INITIAL to FINAL,
) {
pulsePropKey using infiniteRepeatable(
animation = tween(
durationMillis = 500,
easing = FastOutSlowInEasing
),
repeatMode = RepeatMode.Restart
)
}
}
}





Expand Down