For #24873 - Add a modifier parameter to the Favicon Composable
This commit is contained in:
parent
051e3bbd50
commit
07a444c5a0
|
@ -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,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user