mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/26797 - Add optional parameter to customize the background color of ListItemTabLarge
This commit is contained in:
parent
ebc84bc040
commit
d25f8c6c43
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.compose
|
package org.mozilla.fenix.compose
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -19,6 +20,7 @@ import androidx.compose.material.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@ -42,6 +44,7 @@ import org.mozilla.fenix.theme.Theme
|
|||||||
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
||||||
* @param title Title off the tab this composable renders.
|
* @param title Title off the tab this composable renders.
|
||||||
* @param caption Optional caption text.
|
* @param caption Optional caption text.
|
||||||
|
* @param backgroundColor Background [Color] of the item.
|
||||||
* @param onClick Optional callback to be invoked when this composable is clicked.
|
* @param onClick Optional callback to be invoked when this composable is clicked.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
@ -49,9 +52,14 @@ fun ListItemTabLarge(
|
|||||||
imageUrl: String,
|
imageUrl: String,
|
||||||
title: String,
|
title: String,
|
||||||
caption: String? = null,
|
caption: String? = null,
|
||||||
|
backgroundColor: Color = FirefoxTheme.colors.layer2,
|
||||||
onClick: (() -> Unit)? = null
|
onClick: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
ListItemTabSurface(imageUrl, onClick) {
|
ListItemTabSurface(
|
||||||
|
imageUrl = imageUrl,
|
||||||
|
backgroundColor = backgroundColor,
|
||||||
|
onClick = onClick,
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
color = FirefoxTheme.colors.textPrimary,
|
color = FirefoxTheme.colors.textPrimary,
|
||||||
@ -89,18 +97,24 @@ fun ListItemTabLarge(
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
||||||
|
* @param backgroundColor Background [Color] of the item.
|
||||||
|
* @param onClick Optional callback to be invoked when this composable is clicked.
|
||||||
* @param title Composable rendering the title of the tab this composable represents.
|
* @param title Composable rendering the title of the tab this composable represents.
|
||||||
* @param subtitle Optional tab caption composable.
|
* @param subtitle Optional tab caption composable.
|
||||||
* @param onClick Optional callback to be invoked when this composable is clicked.
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ListItemTabLarge(
|
fun ListItemTabLarge(
|
||||||
imageUrl: String,
|
imageUrl: String,
|
||||||
|
backgroundColor: Color = FirefoxTheme.colors.layer2,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
title: @Composable () -> Unit,
|
title: @Composable () -> Unit,
|
||||||
subtitle: @Composable (() -> Unit)? = null
|
subtitle: @Composable (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
ListItemTabSurface(imageUrl, onClick) {
|
ListItemTabSurface(
|
||||||
|
imageUrl = imageUrl,
|
||||||
|
backgroundColor = backgroundColor,
|
||||||
|
onClick = onClick,
|
||||||
|
) {
|
||||||
title()
|
title()
|
||||||
|
|
||||||
subtitle?.invoke()
|
subtitle?.invoke()
|
||||||
@ -111,12 +125,14 @@ fun ListItemTabLarge(
|
|||||||
* Shared default configuration of a ListItemTabLarge Composable.
|
* Shared default configuration of a ListItemTabLarge Composable.
|
||||||
*
|
*
|
||||||
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
* @param imageUrl URL from where the to download a header image of the tab this composable renders.
|
||||||
|
* @param backgroundColor Background [Color] of the item.
|
||||||
* @param onClick Optional callback to be invoked when this composable is clicked.
|
* @param onClick Optional callback to be invoked when this composable is clicked.
|
||||||
* @param tabDetails [Composable] Displayed to the the end of the image. Allows for variation in the item text style.
|
* @param tabDetails [Composable] Displayed to the the end of the image. Allows for variation in the item text style.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ListItemTabSurface(
|
fun ListItemTabSurface(
|
||||||
imageUrl: String,
|
imageUrl: String,
|
||||||
|
backgroundColor: Color = FirefoxTheme.colors.layer2,
|
||||||
onClick: (() -> Unit)? = null,
|
onClick: (() -> Unit)? = null,
|
||||||
tabDetails: @Composable () -> Unit
|
tabDetails: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
@ -126,7 +142,7 @@ fun ListItemTabSurface(
|
|||||||
Card(
|
Card(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
shape = RoundedCornerShape(8.dp),
|
shape = RoundedCornerShape(8.dp),
|
||||||
backgroundColor = FirefoxTheme.colors.layer2,
|
backgroundColor = backgroundColor,
|
||||||
elevation = 6.dp
|
elevation = 6.dp
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@ -152,7 +168,8 @@ fun ListItemTabSurface(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
private fun ListItemTabLargePreview() {
|
private fun ListItemTabLargePreview() {
|
||||||
FirefoxTheme(theme = Theme.getTheme()) {
|
FirefoxTheme(theme = Theme.getTheme()) {
|
||||||
ListItemTabLarge(
|
ListItemTabLarge(
|
||||||
@ -164,7 +181,8 @@ private fun ListItemTabLargePreview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
private fun ListItemTabSurfacePreview() {
|
private fun ListItemTabSurfacePreview() {
|
||||||
FirefoxTheme(theme = Theme.getTheme()) {
|
FirefoxTheme(theme = Theme.getTheme()) {
|
||||||
ListItemTabSurface(
|
ListItemTabSurface(
|
||||||
@ -178,3 +196,21 @@ private fun ListItemTabSurfacePreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
|
private fun ListItemTabSurfaceWithCustomBackgroundPreview() {
|
||||||
|
FirefoxTheme(theme = Theme.getTheme()) {
|
||||||
|
ListItemTabSurface(
|
||||||
|
imageUrl = "",
|
||||||
|
backgroundColor = Color.Cyan,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "This can be anything",
|
||||||
|
color = FirefoxTheme.colors.textPrimary,
|
||||||
|
fontSize = 22.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -165,7 +165,10 @@ fun PocketSponsoredStory(
|
|||||||
"&resize=w$imageWidth-h$imageHeight"
|
"&resize=w$imageWidth-h$imageHeight"
|
||||||
)
|
)
|
||||||
|
|
||||||
ListItemTabSurface(imageUrl, { onStoryClick(story) }) {
|
ListItemTabSurface(
|
||||||
|
imageUrl = imageUrl,
|
||||||
|
onClick = { onStoryClick(story) },
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = story.title,
|
text = story.title,
|
||||||
color = FirefoxTheme.colors.textPrimary,
|
color = FirefoxTheme.colors.textPrimary,
|
||||||
|
Loading…
Reference in New Issue
Block a user