-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve image loading placeholders
This commit introduces two new components: `LoadingPlaceholder` and `Placeholder`. - `LoadingPlaceholder` displays a circular progress indicator while content is loading. It can be configured to be colorful or monochrome. - `Placeholder` displays an icon within a surface, providing a visual cue when content is unavailable. It can also be configured to be colorful or monochrome. The `AsyncImage` component now uses these new components to provide better feedback to the user during image loading and in cases of errors or missing images. Additionally, the component has been updated to allow for optional placeholders and to handle file-not-found errors more gracefully. This change improves the overall user experience by providing more informative and visually appealing placeholders during image loading and error states.
- Loading branch information
Showing
4 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/ui/src/main/java/com/bobbyesp/ui/components/others/LoadingPlaceholder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.bobbyesp.ui.components.others | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun LoadingPlaceholder( | ||
modifier: Modifier = Modifier, | ||
progress: Float? = null, | ||
colorful: Boolean, | ||
) { | ||
|
||
val color = if (colorful) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surface | ||
val onColor = if (colorful) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.onSurface | ||
val elevation = if (colorful) 0.dp else 8.dp | ||
|
||
Surface( | ||
tonalElevation = elevation, | ||
color = color, | ||
modifier = modifier | ||
) { | ||
if (progress == null) { | ||
CircularProgressIndicator( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(8.dp), | ||
color = onColor, | ||
) | ||
} else { | ||
CircularProgressIndicator( | ||
progress = { progress }, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(8.dp), | ||
color = onColor, | ||
) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters