-
Notifications
You must be signed in to change notification settings - Fork 0
Error and Loading State UI #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e033a35
8b226d5
d05dfc8
c374983
83e081f
e5c2177
df00252
54c9372
8c8037c
4c38dfe
e60c5f5
f8608d2
5f986aa
b781e27
0b1963f
86ec992
acc40c8
42c8fe4
5c52d62
a992ad3
5daf380
b7739a4
c480669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.cornellappdev.score.components | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.score.R | ||
| import com.cornellappdev.score.theme.CrimsonPrimary | ||
| import com.cornellappdev.score.theme.GrayMedium | ||
| import com.cornellappdev.score.theme.GrayPrimary | ||
| import com.cornellappdev.score.theme.Style.bodyNormal | ||
| import com.cornellappdev.score.theme.Style.heading2 | ||
|
|
||
| @Composable | ||
| fun ErrorState( | ||
| onRefresh: () -> Unit, | ||
| message: String, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Column( | ||
| modifier = modifier | ||
| .fillMaxSize(), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| verticalArrangement = Arrangement.spacedBy(100.dp) | ||
| ) { | ||
| Spacer(modifier = Modifier.height(200.dp)) | ||
| Column( | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant parameter here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i made a column for the feedback icon + text and nested that + the button within the main column, so i think both of these are necessary |
||
| ) { | ||
| Image( | ||
| painter = painterResource(R.drawable.ic_feedback), | ||
| contentDescription = "feedback bubble" | ||
| ) | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| Text( | ||
| text = message, | ||
| style = heading2.copy(color = GrayPrimary) | ||
| ) | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
| Text( | ||
| text = "Please try again later.", | ||
| style = bodyNormal.copy(color = GrayMedium) | ||
| ) | ||
| } | ||
|
|
||
| Button( | ||
| colors = ButtonDefaults.buttonColors(containerColor = CrimsonPrimary), | ||
| onClick = onRefresh | ||
| ) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Image( | ||
| painter = painterResource(R.drawable.ic_cached), | ||
| contentDescription = "refresh icon" | ||
| ) | ||
| Text("Try again") | ||
| } | ||
| } | ||
| Spacer(modifier = Modifier.height(70.dp)) | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Composable | ||
| private fun ErrorStatePreview() = ScorePreview { | ||
| ErrorState({}, "Oops! Failed to load.") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package com.cornellappdev.score.components | ||
|
|
||
| import androidx.compose.foundation.Canvas | ||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material3.MaterialTheme.typography | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.score.R | ||
| import com.cornellappdev.score.theme.GrayStroke | ||
| import com.cornellappdev.score.theme.LocalInfiniteLoading | ||
| import com.cornellappdev.score.theme.Stroke | ||
| import com.cornellappdev.score.theme.Wash | ||
| import com.cornellappdev.score.util.interpolateColorHSV | ||
|
|
||
| @Composable | ||
| fun GameDetailsLoadingScreen( | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| val shimmerColor = interpolateColorHSV(Wash, Stroke, LocalInfiniteLoading.current) | ||
| Column( | ||
| modifier = modifier.fillMaxWidth() | ||
| ) { | ||
| Row( | ||
| modifier = Modifier | ||
| .background(color = shimmerColor) | ||
| .fillMaxWidth() | ||
| .height(185.dp), | ||
| horizontalArrangement = Arrangement.Center, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Canvas( | ||
| modifier = Modifier | ||
| .size(72.dp) | ||
| ) { | ||
| drawCircle(color = shimmerColor) | ||
| } | ||
| Spacer(modifier = Modifier.width(24.dp)) | ||
| LoadingStateBox(100, 33.dp, Modifier.width(100.dp)) | ||
| Spacer(modifier = Modifier.width(24.dp)) | ||
| Canvas( | ||
| modifier = Modifier | ||
| .size(72.dp) | ||
| ) { | ||
| drawCircle(color = shimmerColor) | ||
| } | ||
| } | ||
| Column( | ||
| modifier = Modifier.padding(24.dp) | ||
| ) { | ||
| LoadingStateBox(12, 16.dp, Modifier.width(100.dp)) | ||
| Spacer(modifier = Modifier.height(12.dp)) | ||
| LoadingStateBox(100, 32.dp, Modifier.width(200.dp)) | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| LoadingStateBox(12, 16.dp) | ||
|
|
||
| Spacer(modifier = Modifier.height(24.dp)) | ||
| LoadingStateBox(8, 125.dp) | ||
| Spacer(modifier = Modifier.height(24.dp)) | ||
|
|
||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = "Loading Score Summary", | ||
| color = GrayStroke, | ||
| style = typography.titleMedium, | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
|
|
||
| Image( | ||
| painter = painterResource(R.drawable.ic_right_chevron), | ||
| contentDescription = "right chevron" | ||
| ) | ||
| } | ||
|
|
||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| LoadingStateBox(8, 48.dp) | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| LoadingStateBox(8, 48.dp) | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| LoadingStateBox(8, 48.dp) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun GameDetailsLoadingStatePreview() = ScorePreview { | ||
| GameDetailsLoadingScreen() | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.