Height issue with ContentScale.FillWidth
See original GitHub issue- Library Version: landscapist-coil:1.5.2
- Affected Device: Emulator Android 10, Samsung devices Android 11/12
Describe the Bug:
I wanted to add rounded corners to images that I’m loading, their contentScale is set to ContentScale.FillWidth, so I’m expecting that once the image is loaded the bounds are updated and the clip() modifier is applied. I added a border so the issue can be visible.
HorizontalPager(
count = content.size,
state = pagerState,
modifier = Modifier.fillMaxHeight(fraction = 0.67f),
verticalAlignment = Alignment.CenterVertically,
contentPadding = PaddingValues(horizontal = 23.dp)
) { page ->
content.getOrNull(page)?.let {
CoilImage(
imageModel = it.location,
contentDescription = it.fileName,
contentScale = ContentScale.FillWidth,
// FIXME: 24.05.22 found a solution for rounded corners.
modifier = Modifier
.padding(horizontal = 7.dp)
.fillMaxWidth()
.clip(
RoundedCornerShape(16.dp)
)
.border(0.5.dp, color = grayscale20, shape = RoundedCornerShape(16.dp))
)
}
}
Expected Behavior:
This actually works if I use Coil 2.0 directly
HorizontalPager(
count = content.size,
state = pagerState,
modifier = Modifier.fillMaxHeight(fraction = 0.67f),
verticalAlignment = Alignment.CenterVertically,
contentPadding = PaddingValues(horizontal = 23.dp)
) { page ->
content.getOrNull(page)?.let {
AsyncImage(
model = it.location,
contentDescription = it.fileName,
contentScale = ContentScale.FillWidth,
modifier = Modifier
.padding(horizontal = 7.dp)
.fillMaxWidth()
.clip(
RoundedCornerShape(16.dp)
)
.border(0.5.dp, color = grayscale20, shape = RoundedCornerShape(16.dp))
)
}
}
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:14 (7 by maintainers)
Top Results From Across the Web
ContentScale.FillWidth is not working Jetpack Compose
For landscape images, again due to ContentScale.FillWidth scaling, the full width of the square will be filled by image but since the height...
Read more >After upgrade, Image no longer renders if height not specified
The problem is that I am rendering images fetched from RSS feeds and I simply do not know the size of the images...
Read more >ContentScale.Companion - Android Developers
Scale the source maintaining the aspect ratio so that the bounds match the destination height. ContentScale · FillWidth.
Read more >Jetpack Compose Image Content ScaleType Fully Illustrated
In this ContentScale, it will ensure the height of the image hits the edge of the view top and bottom bounds.
Read more >Content -> Scale to fit width/height - DCP-o-matic
They wouldn't solve the issue, as, even with a dedicated 16:9 container, it is still your screen which defines the black bars. Yes,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a workaround, the
success
callback can be usedAwesome. Thank you for checking these, @antonb03!