From cf248aa19bdabb2fb40cc76494ccef562d9609d9 Mon Sep 17 00:00:00 2001 From: Nebojsa Vuksic Date: Thu, 7 Aug 2025 14:55:36 +0200 Subject: [PATCH] Add `PulsingText` Composable for animated text appearance in loading scenarios --- .../template/components/PulsingText.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/kotlin/org/jetbrains/plugins/template/components/PulsingText.kt diff --git a/src/main/kotlin/org/jetbrains/plugins/template/components/PulsingText.kt b/src/main/kotlin/org/jetbrains/plugins/template/components/PulsingText.kt new file mode 100644 index 0000000..3d8e8ff --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/components/PulsingText.kt @@ -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 + ) +} \ No newline at end of file