2
0
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/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 e0ec0fdb87
commit 8e99bc1852
5 changed files with 19 additions and 45 deletions

View File

@ -40,7 +40,7 @@ import org.mozilla.fenix.wallpapers.Wallpaper
@Composable @Composable
fun HomeSectionHeader( fun HomeSectionHeader(
headerText: String, headerText: String,
description: String, description: String = "",
onShowAllClick: (() -> Unit)? = null onShowAllClick: (() -> Unit)? = null
) { ) {
if (inComposePreview) { if (inComposePreview) {
@ -80,7 +80,7 @@ fun HomeSectionHeader(
@Composable @Composable
private fun HomeSectionHeaderContent( private fun HomeSectionHeaderContent(
headerText: String, headerText: String,
description: String, description: String = "",
showAllTextColor: Color = FirefoxTheme.colors.textAccent, showAllTextColor: Color = FirefoxTheme.colors.textAccent,
onShowAllClick: (() -> Unit)? = null, 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.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource 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.R
import org.mozilla.fenix.components.components import org.mozilla.fenix.components.components
import org.mozilla.fenix.compose.ComposeViewHolder 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.FirefoxTheme
import org.mozilla.fenix.theme.Theme import org.mozilla.fenix.theme.Theme
@ -82,11 +80,8 @@ private fun PocketTopics(
onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit onCategoryClick: (PocketRecommendedStoriesCategory) -> Unit
) { ) {
Column { Column {
SectionHeader( HomeSectionHeader(
text = stringResource(R.string.pocket_stories_categories_header), headerText = stringResource(R.string.pocket_stories_categories_header),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(align = Alignment.Top)
) )
Spacer(Modifier.height(16.dp)) 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.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth 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.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@ -211,7 +209,6 @@ fun PocketSponsoredStory(
@Composable @Composable
fun PocketStories( fun PocketStories(
@PreviewParameter(PocketStoryProvider::class) stories: List<PocketStory>, @PreviewParameter(PocketStoryProvider::class) stories: List<PocketStory>,
contentPadding: Dp,
onStoryShown: (PocketStory, Pair<Int, Int>) -> Unit, onStoryShown: (PocketStory, Pair<Int, Int>) -> Unit,
onStoryClicked: (PocketStory, Pair<Int, Int>) -> Unit, onStoryClicked: (PocketStory, Pair<Int, Int>) -> Unit,
onDiscoverMoreClicked: (String) -> Unit onDiscoverMoreClicked: (String) -> Unit
@ -224,7 +221,6 @@ fun PocketStories(
val flingBehavior = EagerFlingBehavior(lazyRowState = listState) val flingBehavior = EagerFlingBehavior(lazyRowState = listState)
LazyRow( LazyRow(
contentPadding = PaddingValues(horizontal = contentPadding),
state = listState, state = listState,
flingBehavior = flingBehavior, flingBehavior = flingBehavior,
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
@ -441,7 +437,6 @@ private fun PocketStoriesComposablesPreview() {
Column { Column {
PocketStories( PocketStories(
stories = getFakePocketStories(8), stories = getFakePocketStories(8),
contentPadding = 0.dp,
onStoryShown = { _, _ -> }, onStoryShown = { _, _ -> },
onStoryClicked = { _, _ -> }, onStoryClicked = { _, _ -> },
onDiscoverMoreClicked = {} onDiscoverMoreClicked = {}

View File

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

View File

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