Add LoadingOrError component

This commit is contained in:
vfsfitvnm
2022-07-01 18:50:03 +02:00
parent c4a8d22760
commit f7012c9134

View File

@@ -0,0 +1,41 @@
package it.vfsfitvnm.vimusic.ui.components.themed
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import com.valentinilk.shimmer.shimmer
import it.vfsfitvnm.vimusic.R
@Composable
fun LoadingOrError(
errorMessage: String? = null,
onRetry: (() -> Unit)? = null,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
loadingContent: @Composable ColumnScope.() -> Unit
) {
Box {
Column(
horizontalAlignment = horizontalAlignment,
modifier = Modifier
.alpha(if (errorMessage == null) 1f else 0f)
.shimmer(),
content = loadingContent
)
errorMessage?.let {
TextCard(
icon = R.drawable.alert_circle,
onClick = onRetry,
modifier = Modifier
.align(Alignment.Center)
) {
Title(text = onRetry?.let { "Tap to retry" } ?: "Error")
Text(text = "An error has occurred:\n$errorMessage")
}
}
}
}