android/ui: only show loading spinner if op takes more than 300 milliseconds

Updates tailscale/corp#18202

Signed-off-by: Percy Wegmann <percy@tailscale.com>
jonathan/runasexitnode
Percy Wegmann 8 months ago committed by Percy Wegmann
parent c0ffd5016b
commit e7539f5ff3

@ -10,12 +10,15 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.produceState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.tailscale.ipn.ui.view.TailscaleLogoView
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
object LoadingIndicator {
@ -40,6 +43,13 @@ object LoadingIndicator {
if (isLoading) {
Box(Modifier.clickable {}.matchParentSize().background(Color.Gray.copy(alpha = 0.0f)))
val showSpinner: State<Boolean> =
produceState(initialValue = false) {
delay(300)
value = true
}
if (showSpinner.value) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally) {
@ -48,4 +58,5 @@ object LoadingIndicator {
}
}
}
}
}

Loading…
Cancel
Save