Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FXIOS-11046 [Homepage Rebuild] [TopSites] Try to improve topsite rendering on the homepage #24222

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Cramsden
Copy link
Contributor

📜 Tickets

Jira ticket
Github issue

💡 Description

In order to display top sites on the homepage we need to know the NumberOfRows which is configured via a user setting and NumberOfCellsPerRow which is only calculated via the width of the view. It makes sense that NumberOfRows would live on the state since it is configurable with information that is outside of the view, but there is really no reason for NumberOfCellsPerRow to live on the state since it is only a calculation based on information from the view. This PR attempts to simplify that logic so that NumberOfCellsPerRow is removed from the state and actions.

Simulator.Screen.Recording.-.iPhone.16.Plus.-.2025-01-17.at.12.25.46.mp4

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed, I updated documentation / comments for complex code and public methods
  • If needed, added a backport comment (example @Mergifyio backport release/v120)

@Cramsden Cramsden requested a review from a team as a code owner January 17, 2025 19:28
@Cramsden Cramsden requested review from PARAIPAN9 and cyndichin and removed request for PARAIPAN9 January 17, 2025 19:28
Comment on lines +87 to +91
let topSites: [HomeItem] = topSitesState.topSitesData.prefix(
topSitesState.numberOfRows * numberOfCellsPerRow
).compactMap {
.topSite($0, textColor)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 this makes sense to me to have the calculation here + the previous implementation had a bug

@@ -151,8 +153,16 @@ final class HomepageSectionLayoutProvider {

private func createTopSitesSectionLayout(
for traitCollection: UITraitCollection,
numberOfTilesPerRow: Int
size: CGSize,
numberOfRows: Int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not using numberOfRows here anymore, seems like we can remove this here and where its set in the diffable code

Comment on lines +159 to +164
let numberOfTilesPerRow = TopSitesDimensionCalculator.numberOfTilesPerRow(
availableWidth: size.width,
leadingInset: HomepageSectionLayoutProvider.UX.leadingInset(
traitCollection: traitCollection
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern here is that we're recalculating numberOfTilesPerRow, which may be separate from the numberOfCellsPerRow passed into the diffable datasource calculation. Instead of passing in numberOfRows, what about passing in the numberOfTilesPerRow which gets passed in the updateSnapshot method instead?

@@ -217,9 +207,9 @@ final class HomepageViewController: UIViewController,
}

func newState(state: HomepageState) {
homepageState = state
guard self.homepageState != state else { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to add this check here?

wallpaperView.wallpaperState = state.wallpaperState
dataSource?.updateSnapshot(state: state)
dataSource?.updateSnapshot(state: state, numberOfCellsPerRow: numberOfTilesPerRow(for: availableWidth))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot better! 🔥

@@ -66,36 +66,23 @@ final class TopSitesMiddleware {
return site
}

private func getTopSitesDataAndUpdateState(for action: Action, and numberOfTilesPerRow: Int? = nil) {
private func getTopSitesDataAndUpdateState(for action: Action) {
Task {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why we decided to break up into two separate tasks instead of using the task group instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants