Skip to content

Commit

Permalink
Animate "Due" on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamcd committed Jan 13, 2025
1 parent dbfaf9a commit 023e3bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.jdamcd.arrivals.desktop

import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -11,6 +17,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
Expand All @@ -19,7 +26,7 @@ import androidx.compose.ui.unit.sp
import com.jdamcd.arrivals.Arrival

@Composable
fun ArrivalsList(
fun ArrivalsView(
state: ArrivalsState
) {
Column(
Expand Down Expand Up @@ -93,7 +100,11 @@ fun ArrivalRow(arrival: Arrival) {
modifier = Modifier.fillMaxWidth()
) {
LedText(arrival.destination)
LedText(arrival.time)
if (arrival.secondsToStop < 60) {
FlashingLedText(arrival.time)
} else {
LedText(arrival.time)
}
}
}

Expand All @@ -108,3 +119,24 @@ fun LedText(string: String) {
)
)
}

@Composable
fun FlashingLedText(string: String) {
val infiniteTransition = rememberInfiniteTransition()
val alpha by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 750, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
Text(
text = string,
color = LedYellow.copy(alpha = alpha),
style = TextStyle(
fontFamily = LurFontFamily,
fontSize = 52.sp
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ fun main() = application {
state = windowState,
title = "Arrivals"
) {
ArrivalsList(state)
ArrivalsView(state)
}
}

0 comments on commit 023e3bb

Please sign in to comment.