https://kotlinlang.org logo
#compose
Title
# compose
s

Satyam G

05/25/2022, 12:48 PM
If we are using LazyLayout with with lots of entries in List and each List Card having a ImageView which displays Image from any URL. Now, We are using the GlideImage from Landscapist library. For Image part how does it work for displaying the images in ImageView from URL and when new views are visible on screen does it use image from cache or triggers recomposition of views
c

Colton Idle

05/25/2022, 1:35 PM
I'm not sure I really understand your question, but this seems like it'd be an internal implementation detail of Glide and not really anything compose related?
s

Satyam G

05/25/2022, 1:38 PM
Copy code
@Composable
fun MyImageWrapper(
    modifier: Modifier = Modifier,
    imageUrl: String? = null,
    imageDrawable: Int? = null,
    contentScale: ContentScale = ContentScale.Crop,
    loadingDrawable: Int? = null,
    errorDrawable: Int? = null,
    alignment: Alignment = Alignment.Center,
    errorView: @Composable () -> Unit = {
        errorDrawable?.let {
            Image(
                painter = painterResource(id = errorDrawable),
                contentDescription = ""
            )
        }
    },
    loadingView: @Composable () -> Unit = {
        loadingDrawable?.let {
            Image(painter = painterResource(id = loadingDrawable), contentDescription = "")
        }
    }
) {
    GlideImage(modifier = modifier, imageModel = imageUrl ?: imageDrawable, loading = {
        loadingView()
    }, failure = {
        errorView()
    }, alignment = alignment, contentScale = contentScale, contentDescription = "")
}
If I am using this Composable for displaying Images for Item in LazyLayout, will it be optimised internally or I have to maintain states for Images etc to avoid recompositions is my query
3 Views