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

ImageLoader defaults not working in Compose Preview #977

Closed
CurtJRees opened this issue Nov 9, 2021 · 0 comments · Fixed by #987
Closed

ImageLoader defaults not working in Compose Preview #977

CurtJRees opened this issue Nov 9, 2021 · 0 comments · Fixed by #987

Comments

@CurtJRees
Copy link

Describe the bug
It seems that the defaults set on an ImageLoader aren't applied or used when in a Compose Preview
Explicitly setting the defaults on the specific ImageRequest.Builder however, does work as expected

To Reproduce
Not working:

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun CoilDefaultsPreviewTest() {
    val context = LocalContext.current
    val drawable = ColorDrawable(android.graphics.Color.CYAN)

    val previewImageLoader = remember {
        ImageLoader.Builder(context)
            .placeholder(drawable)
            .error(drawable)
            .fallback(drawable)
            .build()
    }

    CompositionLocalProvider(LocalImageLoader provides previewImageLoader) {
        Box {
            Image(
                painter = rememberImagePainter(
                    data = "data",
                ),
                contentDescription = null,
                modifier = Modifier.size(200.dp)
            )
        }
    }
}

Working:

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun CoilDefaultsPreviewTest() {
    val context = LocalContext.current
    val drawable = ColorDrawable(android.graphics.Color.CYAN)

    val previewImageLoader = remember {
        ImageLoader.Builder(context)
            .placeholder(drawable)
            .error(drawable)
            .fallback(drawable)
            .build()
    }

    CompositionLocalProvider(LocalImageLoader provides previewImageLoader) {
        Box {
            Image(
                painter = rememberImagePainter(
                    data = "data",
                    builder = {
                        defaults(LocalImageLoader.current.defaults)
                    }
                ),
                contentDescription = null,
                modifier = Modifier.size(200.dp)
            )
        }
    }
}

Logs/Screenshots
Not Working Preview:
Screenshot 2021-11-09 at 11 41 46

Working Preview:
Screenshot 2021-11-09 at 11 42 38

Version
Coil 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant