-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: main
Are you sure you want to change the base?
Conversation
let topSites: [HomeItem] = topSitesState.topSitesData.prefix( | ||
topSitesState.numberOfRows * numberOfCellsPerRow | ||
).compactMap { | ||
.topSite($0, textColor) | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
let numberOfTilesPerRow = TopSitesDimensionCalculator.numberOfTilesPerRow( | ||
availableWidth: size.width, | ||
leadingInset: HomepageSectionLayoutProvider.UX.leadingInset( | ||
traitCollection: traitCollection | ||
) | ||
) |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
📜 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 andNumberOfCellsPerRow
which is only calculated via the width of the view. It makes sense thatNumberOfRows
would live on the state since it is configurable with information that is outside of the view, but there is really no reason forNumberOfCellsPerRow
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 thatNumberOfCellsPerRow
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
@Mergifyio backport release/v120
)