Add PulsingText Composable for animated text appearance in loading scenarios

This commit is contained in:
Nebojsa Vuksic 2025-08-07 14:55:36 +02:00
parent 54ca91fea4
commit cf248aa19b

View File

@ -0,0 +1,46 @@
package org.jetbrains.plugins.template.components
import androidx.compose.animation.core.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.ui.component.Text
@Composable
fun PulsingText(
text: String,
isLoading: Boolean,
modifier: Modifier = Modifier,
color: Color = Color.White,
fontSize: TextUnit = JewelTheme.defaultTextStyle.fontSize,
fontWeight: FontWeight? = JewelTheme.defaultTextStyle.fontWeight
) {
val alpha = if (isLoading) {
val infiniteTransition = rememberInfiniteTransition(label = "pulsing_text")
infiniteTransition.animateFloat(
initialValue = 0.3f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 1000,
easing = FastOutSlowInEasing
),
repeatMode = RepeatMode.Reverse
),
label = "text_alpha"
).value
} else {
1f
}
Text(
text = text,
color = color.copy(alpha = alpha),
fontSize = fontSize,
fontWeight = fontWeight,
modifier = modifier
)
}