Skip to content
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

Only enable inexact size if ImageView has a matching SizeResolver. #344

Merged
merged 2 commits into from Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions coil-base/src/main/java/coil/memory/RequestService.kt
Expand Up @@ -107,11 +107,14 @@ internal class RequestService(
Precision.EXACT -> false
Precision.INEXACT -> true
Precision.AUTOMATIC -> {
// ImageViews will automatically scale the image.
if ((request.target as? ViewTarget<*>)?.view is ImageView) return true
// There must not be an explicit size resolver.
if (request.sizeResolver == null) {
// ImageViews will automatically scale the image.
if ((request.target as? ViewTarget<*>)?.view is ImageView) return true

// If we fall back to a DisplaySizeResolver, allow the dimensions to be inexact.
if (request.sizeResolver == null && request.target !is ViewTarget<*>) return true
// If we fall back to a DisplaySizeResolver, allow the dimensions to be inexact.
if (request.target !is ViewTarget<*>) return true
}

// Else, require the dimensions to be exact.
return false
Expand Down
9 changes: 9 additions & 0 deletions coil-base/src/test/java/coil/request/RequestServiceTest.kt
Expand Up @@ -54,6 +54,15 @@ class RequestServiceTest {
assertTrue(service.allowInexactSize(request))
}

@Test
fun `allowInexactSize - ImageViewTarget explicit size`() {
val request = createLoadRequest(context) {
target(ImageView(context))
size(100, 100)
}
assertFalse(service.allowInexactSize(request))
}

@Test
fun `allowInexactSize - NullSizeResolver`() {
val request = createLoadRequest(context)
Expand Down