-
-
Save nuhkoca/ede72676aeb47960a5990ebbfdaea381 to your computer and use it in GitHub Desktop.
PerformancePulse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun PerformancePulse( | |
performancePulseUpdate: PerformancePulseUpdate, | |
onDispose: (() -> Unit)? = null | |
) { | |
val alpha = remember { Animatable(0f) } | |
LaunchedEffect(performancePulseUpdate) { | |
alpha.snapTo(0f) | |
if (performancePulseUpdate !is PerformancePulseUpdate.None) { | |
// Fade in | |
alpha.animateTo( | |
targetValue = 1f, | |
animationSpec = tween( | |
durationMillis = 200, | |
easing = CubicBezierEasing(0.5f, 0f, 0f, 0.9f) | |
) | |
) | |
// Fade out | |
alpha.animateTo( | |
targetValue = 0f, | |
animationSpec = tween( | |
durationMillis = 800, | |
easing = CubicBezierEasing(0f, 0f, 0.6f, 1f) | |
) | |
) | |
} | |
} | |
DisposableEffect(Unit) { | |
onDispose { | |
onDispose?.invoke() | |
} | |
} | |
val tint = when (performancePulseUpdate) { | |
is PerformancePulseUpdate.Up -> TRTheme.colors.primaryGreen2 | |
is PerformancePulseUpdate.Down -> TRTheme.colors.primaryRed2 | |
is PerformancePulseUpdate.None -> Color.Transparent // Not visible due alpha 0f | |
} | |
Box(modifier = Modifier.alpha(alpha.value)) { | |
TRIcon( | |
iconResId = TRTheme.icons.indicatorDefaultXS, | |
tint = tint | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
private fun PerformancePulseContainer(performancePulseUpdateObservable: Observable<PerformancePulseUpdate>) { | |
val performancePulseUpdate by performancePulseUpdateObservable.subscribeAsState(PerformancePulseUpdate.None) | |
PerformancePulse1(performancePulseUpdate) | |
} | |
private val performancePulseUpdateObservable1 = getPerformancePulseUpdateObservable( | |
periodInMilliseconds = 500, | |
pulse = { PerformancePulseUpdate.Up } | |
) | |
fun getPerformancePulseUpdateObservable( | |
periodInMilliseconds: Long = 2000, | |
pulse: (Long) -> PerformancePulseUpdate | |
): Observable<PerformancePulseUpdate> { | |
return Observable.interval(periodInMilliseconds, periodInMilliseconds, TimeUnit.MILLISECONDS) | |
.map { value -> | |
pulse(value) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class PerformancePulseUpdate : Serializable { | |
object Up : PerformancePulseUpdate() | |
object Down : PerformancePulseUpdate() | |
object None : PerformancePulseUpdate() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment