Skip to content

Commit

Permalink
Add FXIOS-10165 [Homepage] Add initial Top Sites Section
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin committed Nov 4, 2024
1 parent 0a40835 commit 76317f4
Show file tree
Hide file tree
Showing 14 changed files with 730 additions and 14 deletions.
36 changes: 36 additions & 0 deletions firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@
8A454D322CB8170D009436D9 /* PocketManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D312CB8170D009436D9 /* PocketManager.swift */; };
8A454D362CB86993009436D9 /* PocketStoryState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D352CB86993009436D9 /* PocketStoryState.swift */; };
8A454D372CB86B86009436D9 /* PocketStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D332CB85C7D009436D9 /* PocketStateTests.swift */; };
8A454D3F2CB9B8A0009436D9 /* TopSitesSectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D3E2CB9B8A0009436D9 /* TopSitesSectionState.swift */; };
8A454D412CB9B8AA009436D9 /* TopSitesAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D402CB9B8AA009436D9 /* TopSitesAction.swift */; };
8A454D432CB9B8F5009436D9 /* TopSitesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D422CB9B8F5009436D9 /* TopSitesManager.swift */; };
8A454D462CB9C83F009436D9 /* TopSitesMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A454D452CB9C83F009436D9 /* TopSitesMiddleware.swift */; };
8A4593C72BF7BECA002758DE /* MicrosurveyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A4593C32BF7BEC9002758DE /* MicrosurveyTableViewCell.swift */; };
8A4593C82BF7BECA002758DE /* MicrosurveyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A4593C42BF7BECA002758DE /* MicrosurveyViewController.swift */; };
8A4593C92BF7BECA002758DE /* MicrosurveyTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A4593C52BF7BECA002758DE /* MicrosurveyTableHeaderView.swift */; };
Expand Down Expand Up @@ -992,6 +996,9 @@
8AE80BBA2891C0C300BC12EA /* JumpBackInSectionLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BB92891C0C300BC12EA /* JumpBackInSectionLayout.swift */; };
8AE80BBC2891C20D00BC12EA /* JumpBackInList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BBB2891C20D00BC12EA /* JumpBackInList.swift */; };
8AE80BBE2891C21A00BC12EA /* JumpBackInSyncedTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE80BBD2891C21A00BC12EA /* JumpBackInSyncedTab.swift */; };
8AE938192CD91D5A0020E6CF /* TopSiteState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE938182CD91D5A0020E6CF /* TopSiteState.swift */; };
8AE9381B2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9381A2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift */; };
8AE9381D2CD920310020E6CF /* TopSiteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AE9381C2CD920310020E6CF /* TopSiteCell.swift */; };
8AEAD9F32C3D7B3E001A2C5A /* FeatureFlagsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AEAD9F22C3D7B3E001A2C5A /* FeatureFlagsSettings.swift */; };
8AEAD9F52C3D7BA9001A2C5A /* FeatureFlagsDebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AEAD9F42C3D7BA9001A2C5A /* FeatureFlagsDebugViewController.swift */; };
8AEAD9F92C3DB0CD001A2C5A /* MicrosurveyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AEAD9F62C3DB0BF001A2C5A /* MicrosurveyTests.swift */; };
Expand Down Expand Up @@ -7022,6 +7029,10 @@
8A454D312CB8170D009436D9 /* PocketManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PocketManager.swift; sourceTree = "<group>"; };
8A454D332CB85C7D009436D9 /* PocketStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PocketStateTests.swift; sourceTree = "<group>"; };
8A454D352CB86993009436D9 /* PocketStoryState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PocketStoryState.swift; sourceTree = "<group>"; };
8A454D3E2CB9B8A0009436D9 /* TopSitesSectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesSectionState.swift; sourceTree = "<group>"; };
8A454D402CB9B8AA009436D9 /* TopSitesAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesAction.swift; sourceTree = "<group>"; };
8A454D422CB9B8F5009436D9 /* TopSitesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesManager.swift; sourceTree = "<group>"; };
8A454D452CB9C83F009436D9 /* TopSitesMiddleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesMiddleware.swift; sourceTree = "<group>"; };
8A4593C32BF7BEC9002758DE /* MicrosurveyTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MicrosurveyTableViewCell.swift; sourceTree = "<group>"; };
8A4593C42BF7BECA002758DE /* MicrosurveyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MicrosurveyViewController.swift; sourceTree = "<group>"; };
8A4593C52BF7BECA002758DE /* MicrosurveyTableHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MicrosurveyTableHeaderView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7260,6 +7271,9 @@
8AE80BB92891C0C300BC12EA /* JumpBackInSectionLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumpBackInSectionLayout.swift; sourceTree = "<group>"; };
8AE80BBB2891C20D00BC12EA /* JumpBackInList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumpBackInList.swift; sourceTree = "<group>"; };
8AE80BBD2891C21A00BC12EA /* JumpBackInSyncedTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JumpBackInSyncedTab.swift; sourceTree = "<group>"; };
8AE938182CD91D5A0020E6CF /* TopSiteState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSiteState.swift; sourceTree = "<group>"; };
8AE9381A2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSitesSectionStateTests.swift; sourceTree = "<group>"; };
8AE9381C2CD920310020E6CF /* TopSiteCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopSiteCell.swift; sourceTree = "<group>"; };
8AEAD9F22C3D7B3E001A2C5A /* FeatureFlagsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlagsSettings.swift; sourceTree = "<group>"; };
8AEAD9F42C3D7BA9001A2C5A /* FeatureFlagsDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlagsDebugViewController.swift; sourceTree = "<group>"; };
8AEAD9F62C3DB0BF001A2C5A /* MicrosurveyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MicrosurveyTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11028,6 +11042,19 @@
path = Header;
sourceTree = "<group>";
};
8A454D3D2CB9B896009436D9 /* TopSites */ = {
isa = PBXGroup;
children = (
8A454D3E2CB9B8A0009436D9 /* TopSitesSectionState.swift */,
8A454D422CB9B8F5009436D9 /* TopSitesManager.swift */,
8A454D402CB9B8AA009436D9 /* TopSitesAction.swift */,
8A454D452CB9C83F009436D9 /* TopSitesMiddleware.swift */,
8AE938182CD91D5A0020E6CF /* TopSiteState.swift */,
8AE9381C2CD920310020E6CF /* TopSiteCell.swift */,
);
path = TopSites;
sourceTree = "<group>";
};
8A46F5A62C9E4389005B6422 /* RemoteRecords */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -11072,6 +11099,7 @@
8A552AC62CB43AB300564C98 /* HeaderStateTests.swift */,
8A552AC52CB43AB300564C98 /* HomepageStateTests.swift */,
8A454D332CB85C7D009436D9 /* PocketStateTests.swift */,
8AE9381A2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift */,
);
path = Redux;
sourceTree = "<group>";
Expand Down Expand Up @@ -11189,6 +11217,7 @@
8A7D08E12CAAF79F0035999C /* Homepage Rebuild */ = {
isa = PBXGroup;
children = (
8A454D3D2CB9B896009436D9 /* TopSites */,
8A454D2A2CB7079A009436D9 /* Header */,
8ABDBAA42CB6BF3A00B51F63 /* Pocket */,
8A7D08E22CAAF7C30035999C /* HomepageViewController.swift */,
Expand Down Expand Up @@ -15341,6 +15370,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8AE9381B2CD91FDB0020E6CF /* TopSitesSectionStateTests.swift in Sources */,
4590912E2A2E4F7700061F0C /* AutopushTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -15829,6 +15859,7 @@
8AAEBA062BF51141000C02B5 /* MicrosurveyMiddleware.swift in Sources */,
431C0CA925C890E500395CE4 /* DefaultBrowserOnboardingViewModel.swift in Sources */,
DFACBF81277B916B003D5F41 /* ConfigurableGradientView.swift in Sources */,
8A454D432CB9B8F5009436D9 /* TopSitesManager.swift in Sources */,
7482205C1DBAB56300EEEA72 /* MailProviders.swift in Sources */,
8A93F87029D3A597004159D9 /* SceneCoordinator.swift in Sources */,
C88E7A602A05551B0072E638 /* NimbusOnboardingFeatureLayerProtocol.swift in Sources */,
Expand Down Expand Up @@ -15939,6 +15970,7 @@
392ED7E61D0AEFEF009D9B62 /* HomePageAccessors.swift in Sources */,
8A0017C128A3FF6100FEFC8B /* MessageCardDataAdaptor.swift in Sources */,
7BA8D1C71BA037F500C8AE9E /* DownloadHelper.swift in Sources */,
8AE938192CD91D5A0020E6CF /* TopSiteState.swift in Sources */,
8A0D32842A61E1CC007D976D /* StatusBarOverlay.swift in Sources */,
8A5D1CA42A30D69A005AD35C /* SearchSetting.swift in Sources */,
74BBDF472A17979000D3BEFE /* OnboardingDefaultBrowserModelProtocol.swift in Sources */,
Expand Down Expand Up @@ -16203,6 +16235,7 @@
C8DC90C52A066B6A0008832B /* MarkupTokenizingUtility.swift in Sources */,
EBC4869D2195F58300CDA48D /* ErrorPageHelper.swift in Sources */,
C84655E8288739CB00861B4A /* WallpaperCollectionAvailability.swift in Sources */,
8A454D462CB9C83F009436D9 /* TopSitesMiddleware.swift in Sources */,
8ABC5AEE284532C900FEA552 /* PocketDiscoverCell.swift in Sources */,
ABE856AD2C75029F00C56F47 /* TrackingProtectionStatusView.swift in Sources */,
C834330026BAD32800ABAAA6 /* EnhancedTrackingProtectionDetailsVM.swift in Sources */,
Expand Down Expand Up @@ -16305,6 +16338,7 @@
E68AEDB01B18F81A00133D99 /* SwipeAnimator.swift in Sources */,
1DDE3DB32AC34E1E0039363B /* TabCell.swift in Sources */,
5A1947152B8FA9E0009C7A6C /* BrowserViewType.swift in Sources */,
8A454D412CB9B8AA009436D9 /* TopSitesAction.swift in Sources */,
3BF56D271CDBBE1F00AC4D75 /* SimpleToast.swift in Sources */,
8C4B0F5D2C076B12008B3E74 /* UpdatableAddressFields+Decodable.swift in Sources */,
C8B0F5F6283B7CCE007AE65D /* PocketStory.swift in Sources */,
Expand Down Expand Up @@ -16385,6 +16419,7 @@
0A6875152C91886A00606F53 /* CertificatesHeaderView.swift in Sources */,
C8445A14264428DC00B83F53 /* LibraryPanelViewState.swift in Sources */,
8A8158CB2C2C77B000281F72 /* MicrosurveyTelemetry.swift in Sources */,
8AE9381D2CD920310020E6CF /* TopSiteCell.swift in Sources */,
D5D052D92645ABF400759F85 /* ExperimentsSettingsView.swift in Sources */,
E134D5802B31FF3100C6B17B /* FakespotAdLinkButton.swift in Sources */,
8AE0BF4F2819B10E00F33EC4 /* TopSitesSettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -16493,6 +16528,7 @@
E4C358551AF144BA00299F7E /* FSReadingList.m in Sources */,
E17798A22BD804D300F6F0EB /* AddressToolbarContainerModel.swift in Sources */,
8AE1E1CB27B18F560024C45E /* SearchBarSettingsViewController.swift in Sources */,
8A454D3F2CB9B8A0009436D9 /* TopSitesSectionState.swift in Sources */,
8AD40FC527BADC1F00672675 /* TabToolbarHelper.swift in Sources */,
9609F4CA26B57CE800F81493 /* Calendar+Extension.swift in Sources */,
E663D5781BB341C4001EF30E /* ToggleButton.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ final class HomepageDiffableDataSource:

enum HomeItem: Hashable {
case header
case topSite(TopSiteState)
case topSiteEmpty
case pocket(PocketStoryState)
case pocketDiscover
case customizeHomepage

static var cellTypes: [ReusableCell.Type] {
return [
HomepageHeaderCell.self,
TopSiteCell.self,
EmptyTopSiteCell.self,
PocketStandardCell.self,
PocketDiscoverCell.self,
CustomizeHomepageSectionCell.self
Expand All @@ -41,6 +45,9 @@ final class HomepageDiffableDataSource:
snapshot.appendItems([.header], toSection: .header)
snapshot.appendItems([], toSection: .topSites)

let topSites: [HomeItem] = state.topSitesState.topSitesData.compactMap { .topSite($0) }
snapshot.appendItems(topSites, toSection: .topSites)

let stories: [HomeItem] = state.pocketState.pocketData.compactMap { .pocket($0) }
snapshot.appendItems(stories, toSection: .pocket)
snapshot.appendItems([.pocketDiscover], toSection: .pocket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Common
final class HomepageSectionLayoutProvider {
struct UX {
static let standardInset: CGFloat = 16
static let standardSpacing: CGFloat = 16
static let interGroupSpacing: CGFloat = 8
static let iPadInset: CGFloat = 50
static let spacingBetweenSections: CGFloat = 62

Expand All @@ -34,7 +36,6 @@ final class HomepageSectionLayoutProvider {
static let fractionalWidthiPhoneLandscape: CGFloat = 0.46
static let headerFooterHeight: CGFloat = 34
static let interItemSpacing = NSCollectionLayoutSpacing.fixed(8)
static let interGroupSpacing: CGFloat = 8

// The dimension of a cell
// Fractions for iPhone to only show a slight portion of the next column
Expand All @@ -49,6 +50,11 @@ final class HomepageSectionLayoutProvider {
}
}
}

struct TopSitesConstants {
static let cellEstimatedSize = CGSize(width: 85, height: 94)
static let numberOfTilesPerRow = 4
}
}

private var logger: Logger
Expand Down Expand Up @@ -80,7 +86,10 @@ final class HomepageSectionLayoutProvider {
case .header:
return createHeaderSectionLayout(for: traitCollection)
case .topSites:
return createDefaultSectionLayout()
return createTopSitesSectionLayout(
for: traitCollection,
numberOfTilesPerRow: UX.TopSitesConstants.numberOfTilesPerRow
)
case .pocket:
return createPocketSectionLayout(for: traitCollection)
case .customizeHomepage:
Expand Down Expand Up @@ -130,7 +139,7 @@ final class HomepageSectionLayoutProvider {
top: 0,
leading: 0,
bottom: 0,
trailing: UX.PocketConstants.interGroupSpacing)
trailing: UX.interGroupSpacing)

let section = NSCollectionLayoutSection(group: group)

Expand All @@ -153,18 +162,36 @@ final class HomepageSectionLayoutProvider {
return section
}

// TODO: FXIOS-10161 - Update with proper section layout
private func createDefaultSectionLayout() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
func createTopSitesSectionLayout(
for traitCollection: UITraitCollection,
numberOfTilesPerRow: Int
) -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .estimated(UX.TopSitesConstants.cellEstimatedSize.height)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)

item.contentInsets = NSDirectionalEdgeInsets(top: 4, leading: 0, bottom: 4, trailing: 0)
let groupSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .estimated(UX.TopSitesConstants.cellEstimatedSize.height)
)

let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(100))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,
subitem: item,
count: numberOfTilesPerRow)

group.interItemSpacing = NSCollectionLayoutSpacing.fixed(UX.standardSpacing)
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)

let leadingInset = UX.leadingInset(traitCollection: traitCollection)
section.contentInsets = NSDirectionalEdgeInsets(
top: 0,
leading: leadingInset,
bottom: UX.spacingBetweenSections - UX.interGroupSpacing,
trailing: leadingInset
)
section.interGroupSpacing = UX.standardSpacing

return section
}
Expand Down
Loading

0 comments on commit 76317f4

Please sign in to comment.