I'm implementing coil image loading in a `Box` com...
# compose-android
a
I'm implementing coil image loading in a
Box
composable with a TopAppBar on top of it. For some reason, there's a space between the image displayed and the top edge of the screen (just below status bar) and as well at the bottom edge just before other composables start. Anyone ran into this issue? Screenshot in 🧵
solved 1
See ↑ red arrows.
c
set an appropriate
contentScale
thank you color 1
a
I tried multiple
contentScale
, but all of them (Crop, Fit, FitHeight) failed to close the gaps.
My code looks like the following:
Copy code
Box(
        modifier = modifier
            .height(300.dp)
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .align(Alignment.Center),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            if (photoUri != null && !deleteImage) {
                Box(
                    contentAlignment = Alignment.Center
                ) {
                    /** Show selected image */
                    Image(
                        painter = rememberAsyncImagePainter(
                            model = ImageRequest.Builder(context)
                                .data(photoUri)
                                .crossfade(true)
                                .build()
                        ),
                        contentDescription = null,
                        contentScale = ContentScale.Crop
                    )
And TopAppBar:
Copy code
Box {
        if (uiState == ProfileUiState.Success) {
            ProfilePhoto(
                modifier = modifier,
                context = context,
                onPhotoSelected = onPhotoSelected,
                ...
            )
        }

        TopAppBar(
            title = { },
            modifier = modifier,
            colors = TopAppBarDefaults.mediumTopAppBarColors(
                containerColor = Color.Transparent
            ),
...
In a Scaffold
Doing
contentScale
On both Image composable AND rememberAsyncImagePainter fixed the issue