[fenix] For https://github.com/mozilla-mobile/fenix/issues/26444: Adapt HomeSectionHeader text colors to wallpaper.

pull/600/head
mcarare 2 years ago committed by mergify[bot]
parent 8e99bc1852
commit 49e8207a93

@ -7,6 +7,7 @@ package org.mozilla.fenix.compose
import androidx.compose.material.Text 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.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 org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.FirefoxTheme
@ -16,16 +17,18 @@ import org.mozilla.fenix.theme.FirefoxTheme
* *
* @param text [String] to be styled as header and displayed. * @param text [String] to be styled as header and displayed.
* @param modifier [Modifier] to be applied to the [Text]. * @param modifier [Modifier] to be applied to the [Text].
* @param textColor [Color] to be applied to the [Text].
*/ */
@Composable @Composable
fun SectionHeader( fun SectionHeader(
text: String, text: String,
modifier: Modifier = Modifier modifier: Modifier = Modifier,
textColor: Color = FirefoxTheme.colors.textPrimary,
) { ) {
Text( Text(
text = text, text = text,
modifier = modifier, modifier = modifier,
color = FirefoxTheme.colors.textPrimary, color = textColor,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
maxLines = 2, maxLines = 2,
style = FirefoxTheme.typography.headline7 style = FirefoxTheme.typography.headline7

@ -53,16 +53,19 @@ fun HomeSectionHeader(
val wallpaperState = components.appStore val wallpaperState = components.appStore
.observeAsComposableState { state -> state.wallpaperState }.value .observeAsComposableState { state -> state.wallpaperState }.value
val wallpaperAdaptedTextColor = wallpaperState?.currentWallpaper?.textColor?.let { Color(it) }
val isWallpaperDefault = val isWallpaperDefault =
(wallpaperState?.currentWallpaper ?: Wallpaper.Default) == Wallpaper.Default (wallpaperState?.currentWallpaper ?: Wallpaper.Default) == Wallpaper.Default
HomeSectionHeaderContent( HomeSectionHeaderContent(
headerText = headerText, headerText = headerText,
textColor = wallpaperAdaptedTextColor ?: FirefoxTheme.colors.textPrimary,
description = description, description = description,
showAllTextColor = if (isWallpaperDefault) { showAllTextColor = if (isWallpaperDefault) {
FirefoxTheme.colors.textAccent FirefoxTheme.colors.textAccent
} else { } else {
FirefoxTheme.colors.textPrimary wallpaperAdaptedTextColor ?: FirefoxTheme.colors.textAccent
}, },
onShowAllClick = onShowAllClick, onShowAllClick = onShowAllClick,
) )
@ -80,6 +83,7 @@ fun HomeSectionHeader(
@Composable @Composable
private fun HomeSectionHeaderContent( private fun HomeSectionHeaderContent(
headerText: String, headerText: String,
textColor: Color = FirefoxTheme.colors.textPrimary,
description: String = "", description: String = "",
showAllTextColor: Color = FirefoxTheme.colors.textAccent, showAllTextColor: Color = FirefoxTheme.colors.textAccent,
onShowAllClick: (() -> Unit)? = null, onShowAllClick: (() -> Unit)? = null,
@ -89,6 +93,7 @@ private fun HomeSectionHeaderContent(
) { ) {
SectionHeader( SectionHeader(
text = headerText, text = headerText,
textColor = textColor,
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.wrapContentHeight(align = Alignment.Top) .wrapContentHeight(align = Alignment.Top)

Loading…
Cancel
Save