@@ -20,8 +20,6 @@ import androidx.compose.foundation.layout.height
2020import androidx.compose.foundation.layout.padding
2121import androidx.compose.foundation.layout.size
2222import androidx.compose.foundation.layout.width
23- import androidx.compose.foundation.pager.HorizontalPager
24- import androidx.compose.foundation.pager.rememberPagerState
2523import androidx.compose.foundation.shape.CircleShape
2624import androidx.compose.foundation.shape.RoundedCornerShape
2725import androidx.compose.material3.Card
@@ -54,20 +52,18 @@ import org.mozilla.fenix.R
5452import org.mozilla.fenix.compose.ContextualMenu
5553import org.mozilla.fenix.compose.Favicon
5654import org.mozilla.fenix.compose.MenuItem
57- import org.mozilla.fenix.compose.PagerIndicator
5855import org.mozilla.fenix.home.fake.FakeHomepagePreview
5956import org.mozilla.fenix.home.topsites.TopSitesTestTag.TOP_SITE_CARD_FAVICON
6057import org.mozilla.fenix.home.topsites.interactor.TopSiteInteractor
6158import org.mozilla.fenix.theme.FirefoxTheme
6259import org.mozilla.fenix.wallpapers.WallpaperState
63- import kotlin.math.ceil
6460
6561/* *
6662 * The size of a top site item.
6763 */
6864const val TOP_SITES_ITEM_SIZE = 84
6965
70- private const val TOP_SITES_PER_PAGE = 8
66+ private const val TOP_SITES_TO_SHOW = 8
7167private const val TOP_SITES_PER_ROW = 4
7268private const val TOP_SITES_ROW_WIDTH = TOP_SITES_PER_ROW * TOP_SITES_ITEM_SIZE
7369private const val TOP_SITES_FAVICON_CARD_SIZE = 60
@@ -140,11 +136,8 @@ fun TopSites(
140136 onSponsorPrivacyClicked : () -> Unit ,
141137 onTopSitesItemBound : () -> Unit ,
142138) {
143- val numberOfTopSites = topSites.size.toDouble()
144- val pageCount = ceil((numberOfTopSites / TOP_SITES_PER_PAGE )).toInt()
145-
146- val needsInvisibleRow =
147- numberOfTopSites > TOP_SITES_PER_PAGE && numberOfTopSites <= (TOP_SITES_PER_PAGE + TOP_SITES_PER_ROW )
139+ val topSitesToShow = topSites.take(TOP_SITES_TO_SHOW ).chunked(TOP_SITES_PER_ROW )
140+ val needsInvisibleRow = topSites.size <= (TOP_SITES_TO_SHOW - TOP_SITES_PER_ROW )
148141
149142 Column (
150143 modifier = Modifier
@@ -155,68 +148,46 @@ fun TopSites(
155148 .testTag(TopSitesTestTag .TOP_SITES ),
156149 horizontalAlignment = Alignment .CenterHorizontally ,
157150 ) {
158- val pagerState = rememberPagerState(
159- pageCount = { pageCount },
160- )
161-
162151 Box (
163152 modifier = Modifier .fillMaxWidth(),
164153 contentAlignment = Alignment .Center ,
165154 ) {
166- HorizontalPager (
167- state = pagerState,
168- ) { page ->
169- Column (
170- modifier = Modifier .fillMaxWidth(),
171- horizontalAlignment = Alignment .CenterHorizontally ,
172- ) {
173- val topSitesWindows = topSites.windowed(
174- size = TOP_SITES_PER_PAGE ,
175- step = TOP_SITES_PER_PAGE ,
176- partialWindows = true ,
177- )[page].chunked(TOP_SITES_PER_ROW )
178-
179- for (items in topSitesWindows) {
180- Row (modifier = Modifier .defaultMinSize(minWidth = TOP_SITES_ROW_WIDTH .dp)) {
181- items.forEachIndexed { position, topSite ->
182- TopSiteItem (
155+ Column (
156+ modifier = Modifier .fillMaxWidth(),
157+ horizontalAlignment = Alignment .CenterHorizontally ,
158+ ) {
159+ for (items in topSitesToShow) {
160+ Row (modifier = Modifier .defaultMinSize(minWidth = TOP_SITES_ROW_WIDTH .dp)) {
161+ items.forEachIndexed { position, topSite ->
162+ TopSiteItem (
163+ topSite = topSite,
164+ menuItems = getMenuItems(
183165 topSite = topSite,
184- menuItems = getMenuItems(
185- topSite = topSite,
186- onOpenInPrivateTabClicked = onOpenInPrivateTabClicked,
187- onEditTopSiteClicked = onEditTopSiteClicked,
188- onRemoveTopSiteClicked = onRemoveTopSiteClicked,
189- onSettingsClicked = onSettingsClicked,
190- onSponsorPrivacyClicked = onSponsorPrivacyClicked,
191- ),
192- position = position,
193- topSiteColors = topSiteColors,
194- onTopSiteClick = { item -> onTopSiteClick(item) },
195- onTopSiteLongClick = onTopSiteLongClick,
196- onTopSiteImpression = onTopSiteImpression,
197- onTopSitesItemBound = onTopSitesItemBound,
198- )
199- }
200- }
201-
202- if (items != topSitesWindows.last()) {
203- Spacer (modifier = Modifier .height(12 .dp))
166+ onOpenInPrivateTabClicked = onOpenInPrivateTabClicked,
167+ onEditTopSiteClicked = onEditTopSiteClicked,
168+ onRemoveTopSiteClicked = onRemoveTopSiteClicked,
169+ onSettingsClicked = onSettingsClicked,
170+ onSponsorPrivacyClicked = onSponsorPrivacyClicked,
171+ ),
172+ position = position,
173+ topSiteColors = topSiteColors,
174+ onTopSiteClick = { item -> onTopSiteClick(item) },
175+ onTopSiteLongClick = onTopSiteLongClick,
176+ onTopSiteImpression = onTopSiteImpression,
177+ onTopSitesItemBound = onTopSitesItemBound,
178+ )
204179 }
205180 }
206181
207- if (needsInvisibleRow && page > 0 ) {
208- InvisibleRow ( )
182+ if (items != topSitesToShow.last() ) {
183+ Spacer (modifier = Modifier .height( 12 .dp) )
209184 }
210185 }
211- }
212- }
213186
214- if (pagerState.pageCount > 1 ) {
215- PagerIndicator (
216- pagerState = pagerState,
217- modifier = Modifier .padding(horizontal = 16 .dp),
218- spacing = 4 .dp,
219- )
187+ if (needsInvisibleRow) {
188+ InvisibleRow ()
189+ }
190+ }
220191 }
221192 }
222193}
@@ -299,7 +270,11 @@ data class TopSiteColors(
299270 * @param onTopSiteImpression Invoked when the user sees a provided top site.
300271 * @param onTopSitesItemBound Invoked during the composition of a top site item.
301272 */
302- @Suppress(" LongMethod" , " LongParameterList" , " Deprecation" ) // https://bugzilla.mozilla.org/show_bug.cgi?id=1927713
273+ @Suppress(
274+ " LongMethod" ,
275+ " LongParameterList" ,
276+ " Deprecation" ,
277+ ) // https://bugzilla.mozilla.org/show_bug.cgi?id=1927713
303278@Composable
304279fun TopSiteItem (
305280 topSite : TopSite ,
@@ -530,7 +505,11 @@ internal fun getMenuItems(
530505@PreviewLightDark
531506private fun TopSitesPreview () {
532507 FirefoxTheme {
533- Box (modifier = Modifier .background(color = FirefoxTheme .colors.layer1).padding(16 .dp)) {
508+ Box (
509+ modifier = Modifier
510+ .background(color = FirefoxTheme .colors.layer1)
511+ .padding(16 .dp),
512+ ) {
534513 TopSites (
535514 topSites = FakeHomepagePreview .topSites(),
536515 onTopSiteClick = {},
0 commit comments