From 07a444c5a00cda3310300f1b38c090d45aa07e00 Mon Sep 17 00:00:00 2001 From: Noah Bond Date: Wed, 20 Apr 2022 09:27:00 -0700 Subject: [PATCH] For #24873 - Add a modifier parameter to the Favicon Composable --- .../java/org/mozilla/fenix/compose/Favicon.kt | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/Favicon.kt b/app/src/main/java/org/mozilla/fenix/compose/Favicon.kt index 64d538d25..5cb636344 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/Favicon.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/Favicon.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.compose import android.content.res.Configuration import androidx.compose.foundation.Image import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape @@ -23,7 +22,6 @@ import mozilla.components.browser.icons.IconRequest import mozilla.components.browser.icons.compose.Loader import mozilla.components.browser.icons.compose.Placeholder import mozilla.components.browser.icons.compose.WithIcon -import mozilla.components.ui.colors.PhotonColors import org.mozilla.fenix.components.components import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.Theme @@ -31,8 +29,9 @@ import org.mozilla.fenix.theme.Theme /** * Load and display the favicon of a particular website. * - * @param url Website [URL] for which the favicon will be shown. + * @param url Website [url] for which the favicon will be shown. * @param size [Dp] height and width of the image to be loaded. + * @param modifier [Modifier] to be applied to the layout. * @param isPrivate Whether or not a private request (like in private browsing) should be used to * download the icon (if needed). */ @@ -40,10 +39,14 @@ import org.mozilla.fenix.theme.Theme fun Favicon( url: String, size: Dp, - isPrivate: Boolean = false + modifier: Modifier = Modifier, + isPrivate: Boolean = false, ) { if (inComposePreview) { - FaviconPlaceholder(size = size) + FaviconPlaceholder( + size = size, + modifier = modifier, + ) } else { components.core.icons.Loader( url = url, @@ -51,14 +54,17 @@ fun Favicon( size = size.toIconRequestSize() ) { Placeholder { - FaviconPlaceholder(size = size) + FaviconPlaceholder( + size = size, + modifier = modifier, + ) } WithIcon { icon -> Image( painter = icon.painter, contentDescription = null, - modifier = Modifier + modifier = modifier .size(size) .clip(RoundedCornerShape(2.dp)), contentScale = ContentScale.Fit @@ -68,17 +74,23 @@ fun Favicon( } } +/** + * Placeholder used while the Favicon image is loading. + * + * @param size [Dp] height and width of the image. + * @param modifier [Modifier] allowing to control among others the dimensions and shape of the image. + */ @Composable -private fun FaviconPlaceholder(size: Dp) { +private fun FaviconPlaceholder( + size: Dp, + modifier: Modifier = Modifier, +) { Box( - modifier = Modifier + modifier = modifier .size(size) .clip(RoundedCornerShape(2.dp)) .background( - color = when (isSystemInDarkTheme()) { - true -> PhotonColors.DarkGrey30 - false -> PhotonColors.LightGrey30 - } + color = FirefoxTheme.colors.layer2, ) ) }