-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85bc621
commit 88677cd
Showing
3 changed files
with
58 additions
and
71 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
53 changes: 53 additions & 0 deletions
53
ui/src/main/java/com/rubylichtenstein/ui/images/DogImage.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,53 @@ | ||
package com.rubylichtenstein.ui.images | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import coil.compose.SubcomposeAsyncImage | ||
|
||
@Composable | ||
fun DogImage(url: String) { | ||
SubcomposeAsyncImage( | ||
model = url, | ||
contentDescription = null, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.aspectRatio(1f), | ||
contentScale = ContentScale.Crop, | ||
loading = { | ||
Box( | ||
Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center // <-- Centering here | ||
) { | ||
CircularProgressIndicator( | ||
Modifier.size(32.dp) | ||
) | ||
} | ||
}, | ||
error = { | ||
Box( | ||
Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center // <-- Centering here | ||
) { | ||
Text( | ||
text = "Image failed to load", | ||
style = TextStyle( | ||
color = Color.Red, | ||
fontSize = 14.sp | ||
) | ||
) | ||
} | ||
} | ||
) | ||
} |
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