For #26444: Replace SectionHeader with HomeSectionHeader for home sections.

This commit is contained in:
mcarare 2022-08-30 20:59:53 +03:00 committed by mergify[bot]
parent 8a599bbf4e
commit 02be7600e8
5 changed files with 19 additions and 45 deletions

View File

@ -40,7 +40,7 @@ import org.mozilla.fenix.wallpapers.Wallpaper
@Composable
fun HomeSectionHeader(
headerText: String,
description: String,
description: String = "",
onShowAllClick: (() -> Unit)? = null
) {
if (inComposePreview) {
@ -80,7 +80,7 @@ fun HomeSectionHeader(
@Composable
private fun HomeSectionHeaderContent(
headerText: String,
description: String,
description: String = "",
showAllTextColor: Color = FirefoxTheme.colors.textAccent,
onShowAllClick: (() -> Unit)? = null,
) {

View File

@ -9,9 +9,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
@ -23,7 +21,7 @@ import mozilla.components.lib.state.ext.observeAsComposableState
import org.mozilla.fenix.R
import org.mozilla.fenix.components.components
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.compose.SectionHeader
import org.mozilla.fenix.compose.home.HomeSectionHeader
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme
@ -82,11 +80,8 @@ private fun PocketTopics(
onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit
) {
Column {
SectionHeader(
text = stringResource(R.string.pocket_stories_categories_header),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(align = Alignment.Top)
HomeSectionHeader(
headerText = stringResource(R.string.pocket_stories_categories_header),
)
Spacer(Modifier.height(16.dp))

View File

@ -13,7 +13,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@ -48,7 +47,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@ -211,7 +209,6 @@ fun PocketSponsoredStory(
@Composable
fun PocketStories(
@PreviewParameter(PocketStoryProvider::class) stories: List<PocketStory>,
contentPadding: Dp,
onStoryShown: (PocketStory, Pair<Int, Int>) -> Unit,
onStoryClicked: (PocketStory, Pair<Int, Int>) -> Unit,
onDiscoverMoreClicked: (String) -> Unit
@ -224,7 +221,6 @@ fun PocketStories(
val flingBehavior = EagerFlingBehavior(lazyRowState = listState)
LazyRow(
contentPadding = PaddingValues(horizontal = contentPadding),
state = listState,
flingBehavior = flingBehavior,
horizontalArrangement = Arrangement.spacedBy(8.dp)
@ -441,7 +437,6 @@ private fun PocketStoriesComposablesPreview() {
Column {
PocketStories(
stories = getFakePocketStories(8),
contentPadding = 0.dp,
onStoryShown = { _, _ -> },
onStoryClicked = { _, _ -> },
onDiscoverMoreClicked = {}

View File

@ -7,16 +7,12 @@ package org.mozilla.fenix.home.pocket
import android.view.View
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
@ -27,7 +23,7 @@ import mozilla.components.service.pocket.PocketStory.PocketRecommendedStory
import org.mozilla.fenix.R
import org.mozilla.fenix.components.components
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.compose.SectionHeader
import org.mozilla.fenix.compose.home.HomeSectionHeader
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme
@ -44,14 +40,18 @@ class PocketStoriesViewHolder(
private val interactor: PocketStoriesInteractor
) : ComposeViewHolder(composeView, viewLifecycleOwner) {
init {
val horizontalPadding =
composeView.resources.getDimensionPixelSize(R.dimen.home_item_horizontal_margin)
composeView.setPadding(horizontalPadding, 0, horizontalPadding, 0)
}
companion object {
val LAYOUT_ID = View.generateViewId()
}
@Composable
override fun Content() {
val horizontalPadding = dimensionResource(R.dimen.home_item_horizontal_margin)
val homeScreenReady = components.appStore
.observeAsComposableState { state -> state.firstFrameDrawn }.value ?: false
@ -79,19 +79,14 @@ class PocketStoriesViewHolder(
}
Column(modifier = Modifier.padding(top = 72.dp)) {
SectionHeader(
text = stringResource(R.string.pocket_stories_header_1),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = horizontalPadding)
.wrapContentHeight(align = Alignment.Top)
HomeSectionHeader(
headerText = stringResource(R.string.pocket_stories_header_1),
)
Spacer(Modifier.height(16.dp))
PocketStories(
stories ?: emptyList(),
horizontalPadding,
interactor::onStoryShown,
interactor::onStoryClicked,
interactor::onDiscoverMoreClicked
@ -105,12 +100,8 @@ class PocketStoriesViewHolder(
fun PocketStoriesViewHolderPreview() {
FirefoxTheme(theme = Theme.getTheme()) {
Column {
SectionHeader(
text = stringResource(R.string.pocket_stories_header_1),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
.wrapContentHeight(align = Alignment.Top)
HomeSectionHeader(
headerText = stringResource(R.string.pocket_stories_header_1),
)
Spacer(Modifier.height(16.dp))
@ -118,7 +109,6 @@ fun PocketStoriesViewHolderPreview() {
@Suppress("MagicNumber")
PocketStories(
stories = getFakePocketStories(8),
contentPadding = 0.dp,
onStoryShown = { _, _ -> },
onStoryClicked = { _, _ -> },
onDiscoverMoreClicked = {}

View File

@ -6,12 +6,9 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.view.View
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
@ -19,7 +16,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.LifecycleOwner
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.compose.SectionHeader
import org.mozilla.fenix.compose.home.HomeSectionHeader
/**
* View holder for the "Collections" section header with the "Show all" button.
@ -43,11 +40,8 @@ class CollectionHeaderViewHolder(
Column {
Spacer(Modifier.height(56.dp))
SectionHeader(
text = stringResource(R.string.collections_header),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(align = Alignment.Top),
HomeSectionHeader(
headerText = stringResource(R.string.collections_header),
)
Spacer(Modifier.height(10.dp))