Skip to content

Commit e6daa69

Browse files
committed
Properly align "empty", "error" and "loading" state
1 parent 7b02537 commit e6daa69

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

app/src/main/java/net/opatry/adoptacat/ui/CatsScreen.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.foundation.clickable
2626
import androidx.compose.foundation.layout.Box
2727
import androidx.compose.foundation.layout.Column
2828
import androidx.compose.foundation.layout.Row
29+
import androidx.compose.foundation.layout.fillMaxHeight
2930
import androidx.compose.foundation.layout.fillMaxWidth
3031
import androidx.compose.foundation.layout.height
3132
import androidx.compose.foundation.layout.padding
@@ -86,19 +87,37 @@ fun CatsStateDispatcher(uiState: CatsScreenState, selectedCat: CatModel?, onCatS
8687

8788
@Composable
8889
fun LoadingCatsContent() {
89-
Box {
90+
Box(Modifier.fillMaxWidth().fillMaxHeight(.6f),
91+
contentAlignment = Alignment.Center) {
9092
CircularProgressIndicator(Modifier.align(Alignment.Center))
9193
}
9294
}
9395

9496
@Composable
9597
fun ErrorCatsContent(cause: Exception) {
96-
Text(stringResource(R.string.cats_list_error, cause.message ?: ""))
98+
Box(Modifier
99+
.fillMaxWidth()
100+
.fillMaxHeight(.6f)
101+
.padding(8.dp)
102+
,
103+
contentAlignment = Alignment.Center) {
104+
Text(
105+
stringResource(R.string.cats_list_error, cause.message ?: ""),
106+
color = MaterialTheme.colors.error,
107+
style = typography.body1,
108+
)
109+
}
97110
}
98111

99112
@Composable
100113
fun EmptyCatsContent() {
101-
Text(stringResource(R.string.cats_list_empty))
114+
Box(Modifier.fillMaxWidth().fillMaxHeight(.6f),
115+
contentAlignment = Alignment.Center) {
116+
Text(
117+
stringResource(R.string.cats_list_empty),
118+
style = typography.body1,
119+
)
120+
}
102121
}
103122

104123
@Composable

0 commit comments

Comments
 (0)