Skip to content

Commit

Permalink
Initial layout work for Home content
Browse files Browse the repository at this point in the history
https://getpocket.atlassian.net/browse/IN-188

Co-authored-by: David Skuza <dskuza@getpocket.com>
  • Loading branch information
2 people authored and Jacob Morris committed Sep 23, 2021
1 parent 691fa39 commit c5405e3
Show file tree
Hide file tree
Showing 67 changed files with 2,448 additions and 183 deletions.
24 changes: 12 additions & 12 deletions Pocket.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/* Begin PBXBuildFile section */
160056F326CC7FFD00700A80 /* FavoriteAnItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 160056F226CC7FFD00700A80 /* FavoriteAnItemTests.swift */; };
1606F21B26EBC1A200238111 /* HomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1606F21A26EBC1A200238111 /* HomeTests.swift */; };
1612D7E426C32321009A5BFD /* ByteBuffer+read.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1612D7E326C32321009A5BFD /* ByteBuffer+read.swift */; };
166A81C52637406C0015AA1D /* Tests_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 166A81C42637406C0015AA1D /* Tests_iOS.swift */; };
166BACF62656E34B00E401F0 /* Fixtures in Resources */ = {isa = PBXBuildFile; fileRef = 166BACF52656E34B00E401F0 /* Fixtures */; };
Expand All @@ -38,9 +39,8 @@
1674057726CAC35F0061434E /* DeleteAnItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1674057626CAC35F0061434E /* DeleteAnItemTests.swift */; };
167F8084264B011600D8F507 /* Sails in Frameworks */ = {isa = PBXBuildFile; productRef = 167F8083264B011600D8F507 /* Sails */; };
168292C826CC64C300830140 /* ShareAnItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168292C726CC64C300830140 /* ShareAnItemTests.swift */; };
16A140E926E7E3BE002D8012 /* DiscoverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A140E826E7E3BE002D8012 /* DiscoverTests.swift */; };
16A140EB26E7E7A0002D8012 /* TabBarElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A140EA26E7E7A0002D8012 /* TabBarElement.swift */; };
16A140ED26E7E836002D8012 /* DiscoverViewElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A140EC26E7E836002D8012 /* DiscoverViewElement.swift */; };
16A6807F26EBC71300A64545 /* TabBarElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A6807E26EBC71300A64545 /* TabBarElement.swift */; };
16A6808126EBC78800A64545 /* HomeViewElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A6808026EBC78800A64545 /* HomeViewElement.swift */; };
16BA7D6326851513009A17C1 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16BA7D6226851513009A17C1 /* main.swift */; };
16BA7D6626851579009A17C1 /* PocketKit in Frameworks */ = {isa = PBXBuildFile; productRef = 16BA7D6526851579009A17C1 /* PocketKit */; };
16E32B0226851AEB000CC36D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16D47E7F26851AB40095D5A4 /* Assets.xcassets */; };
Expand Down Expand Up @@ -80,6 +80,7 @@

/* Begin PBXFileReference section */
160056F226CC7FFD00700A80 /* FavoriteAnItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteAnItemTests.swift; sourceTree = "<group>"; };
1606F21A26EBC1A200238111 /* HomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTests.swift; sourceTree = "<group>"; };
1612D7E326C32321009A5BFD /* ByteBuffer+read.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ByteBuffer+read.swift"; sourceTree = "<group>"; };
1624B85A268508180099B6EF /* PocketKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = PocketKit; sourceTree = "<group>"; };
166A81B02637406C0015AA1D /* Pocket.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Pocket.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -101,9 +102,8 @@
1674057626CAC35F0061434E /* DeleteAnItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAnItemTests.swift; sourceTree = "<group>"; };
168292C726CC64C300830140 /* ShareAnItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareAnItemTests.swift; sourceTree = "<group>"; };
16973355263CBB3F0003DE2A /* secrets.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = secrets.xcconfig; sourceTree = "<group>"; };
16A140E826E7E3BE002D8012 /* DiscoverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverTests.swift; sourceTree = "<group>"; };
16A140EA26E7E7A0002D8012 /* TabBarElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarElement.swift; sourceTree = "<group>"; };
16A140EC26E7E836002D8012 /* DiscoverViewElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverViewElement.swift; sourceTree = "<group>"; };
16A6807E26EBC71300A64545 /* TabBarElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarElement.swift; sourceTree = "<group>"; };
16A6808026EBC78800A64545 /* HomeViewElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewElement.swift; sourceTree = "<group>"; };
16BA7D6226851513009A17C1 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
16D47E7F26851AB40095D5A4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
16EE3F4F26CEC80900249AF4 /* PullToRefreshTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PullToRefreshTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -166,7 +166,7 @@
168292C726CC64C300830140 /* ShareAnItemTests.swift */,
160056F226CC7FFD00700A80 /* FavoriteAnItemTests.swift */,
16EE3F4F26CEC80900249AF4 /* PullToRefreshTests.swift */,
16A140E826E7E3BE002D8012 /* DiscoverTests.swift */,
1606F21A26EBC1A200238111 /* HomeTests.swift */,
);
path = "Tests iOS";
sourceTree = "<group>";
Expand All @@ -193,8 +193,8 @@
166BAD072656E76B00E401F0 /* UserListElement.swift */,
166EFAE92682821300A027CD /* WebReaderElement.swift */,
166F8F2626D0488900F898E3 /* XCUIElement+wait.swift */,
16A140EA26E7E7A0002D8012 /* TabBarElement.swift */,
16A140EC26E7E836002D8012 /* DiscoverViewElement.swift */,
16A6807E26EBC71300A64545 /* TabBarElement.swift */,
16A6808026EBC78800A64545 /* HomeViewElement.swift */,
);
path = Elements;
sourceTree = "<group>";
Expand Down Expand Up @@ -367,18 +367,18 @@
166BAD0D2656E76B00E401F0 /* PocketAppElement.swift in Sources */,
166BAD0B2656E76B00E401F0 /* ReaderElement.swift in Sources */,
166F8F2726D0488900F898E3 /* XCUIElement+wait.swift in Sources */,
1606F21B26EBC1A200238111 /* HomeTests.swift in Sources */,
166A81C52637406C0015AA1D /* Tests_iOS.swift in Sources */,
1612D7E426C32321009A5BFD /* ByteBuffer+read.swift in Sources */,
16FCADBF26CB04AC00906C03 /* ArchiveAnItemTests.swift in Sources */,
166EFAE8268281F300A027CD /* ReaderToolbarElement.swift in Sources */,
166EFAEA2682821300A027CD /* WebReaderElement.swift in Sources */,
16EE3F5026CEC80900249AF4 /* PullToRefreshTests.swift in Sources */,
160056F326CC7FFD00700A80 /* FavoriteAnItemTests.swift in Sources */,
16A140ED26E7E836002D8012 /* DiscoverViewElement.swift in Sources */,
166BAD0A2656E76B00E401F0 /* SignInFormElement.swift in Sources */,
16A6808126EBC78800A64545 /* HomeViewElement.swift in Sources */,
16A6807F26EBC71300A64545 /* TabBarElement.swift in Sources */,
168292C826CC64C300830140 /* ShareAnItemTests.swift in Sources */,
16A140EB26E7E7A0002D8012 /* TabBarElement.swift in Sources */,
16A140E926E7E3BE002D8012 /* DiscoverTests.swift in Sources */,
166BACF82656E3C600E401F0 /* Fixture.swift in Sources */,
166F8F2926D0494F00F898E3 /* PocketUIElement.swift in Sources */,
166BAD092656E76B00E401F0 /* ItemRowElement.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Pocket.xcodeproj/xcshareddata/xcschemes/Pocket (iOS).xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
argument = "clearCoreData"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "disableSentry"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "clearImageCache"
isEnabled = "NO">
Expand Down
3 changes: 2 additions & 1 deletion PocketKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ let package = Package(
dependencies: ["Kingfisher"],
resources: [
.copy("Style/Typography/Fonts"),
.process("Style/Colors/Colors.xcassets")
.process("Style/Colors/Colors.xcassets"),
.process("Style/Icons/Icons.xcassets"),
]
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class ArticleViewController: UICollectionViewController {
private func attributedText(textContent: TextContent, style: Style) -> NSAttributedString {
let adjustedStyle = style
.with(settings: readerSettings)
.with(paragraph: style.paragraph.with(
alignment: item?.textAlignment ?? .left
))
.with { paragraph in
paragraph.with(alignment: item?.textAlignment ?? .left)
}

return textContent.attributedString(baseStyle: adjustedStyle)
}
Expand Down
8 changes: 0 additions & 8 deletions PocketKit/Sources/PocketKit/Discover/DiscoverView.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import UIKit
import Sync


class HomeViewControllerSectionProvider {
func section(for slate: Slate?, width: CGFloat) -> NSCollectionLayoutSection {
let dividerHeight: CGFloat = 17
let margin: CGFloat = 8
let spacing: CGFloat = margin * 2

guard let slate = slate, !slate.recommendations.isEmpty else {
return NSCollectionLayoutSection(
group: .vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .absolute(0),
heightDimension: .absolute(0)
),
subitems: []
)
)
}

let hero = RecommendationPresenter(recommendation: slate.recommendations[0])
let heroHeight = RecommendationCell.fullHeight(width: width - spacing, recommendation: hero)
let heroItem = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(heroHeight)
)
)

let heroGroup = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(heroHeight + dividerHeight)
),
subitems: [heroItem]
)

heroGroup.supplementaryItems = [
NSCollectionLayoutSupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(dividerHeight)
),
elementKind: "divider",
containerAnchor: NSCollectionLayoutAnchor(edges: .bottom)
)
]

let twoUp = twoUpGroup(slate: slate, width: width, spacing: spacing, dividerHeight: dividerHeight)

let topLevelGroup = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(heroHeight + dividerHeight + (twoUp.height + dividerHeight) * 2)
),
subitems: [heroGroup, twoUp.group]
)

let section = NSCollectionLayoutSection(group: topLevelGroup)
let slatePresenter = SlateHeaderPresenter(slate: slate)

section.boundarySupplementaryItems = [
NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(SlateHeaderView.height(width: width, slate: slatePresenter))
),
elementKind: SlateHeaderView.kind,
alignment: .top
)
]

section.contentInsets = NSDirectionalEdgeInsets(
top: 0,
leading: margin,
bottom: 0,
trailing: margin
)

return section
}

func twoUpGroup(
slate: Slate,
width: CGFloat,
spacing: CGFloat,
dividerHeight: CGFloat
) -> (group: NSCollectionLayoutGroup, height: CGFloat) {
guard slate.recommendations.count > 1 else {
return (
group: NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .absolute(0),
heightDimension: .absolute(0)
),
subitems: []
),
height: 0
)
}

let endIndex = slate.recommendations.index(
1,
offsetBy: 3,
limitedBy: slate.recommendations.endIndex - 1
) ?? slate.recommendations.endIndex - 1
let recommendationsToShow = slate.recommendations[1...endIndex]

let miniCardHeight = recommendationsToShow.map {
RecommendationCell.miniHeight(
width: width - spacing,
recommendation: RecommendationPresenter(recommendation: $0)
)
}.max() ?? 0

let twoUpInner = NSCollectionLayoutGroup.horizontal(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(miniCardHeight)
),
subitem: NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(0.5),
heightDimension: .absolute(miniCardHeight)
)
),
count: 2
)

twoUpInner.supplementaryItems = [
NSCollectionLayoutSupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute(dividerHeight)
),
elementKind: "twoup-divider",
containerAnchor: NSCollectionLayoutAnchor(edges: .bottom),
itemAnchor: NSCollectionLayoutAnchor(edges: .bottom)
)
]

let numberOfRows = Int((Float(recommendationsToShow.count) / 2).rounded(.up))
return (
group: NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .absolute((miniCardHeight + dividerHeight) * 2)
),
subitem: twoUpInner,
count: numberOfRows
),
height: miniCardHeight
)
}
}
Loading

0 comments on commit c5405e3

Please sign in to comment.