Skip to content

Commit

Permalink
2.0.0 (#9)
Browse files Browse the repository at this point in the history
* Begin Implementing 2.0.0, Fixing issue related to header size

* Update Example to use UIScreen.main.bounds.width to calculate image height

* Update Unit tests for OKTableViewSection

* Add Estimated Height for OKTableViewSectionComponent

* Update Unit test for  test_reloadSection_reloadsSectionOfTableView()

* Update function declaration for setting heights for OKTableViewRow, update unit tests

* Update ReadMe to reflect 2.0.0 changes

* Update README for grammatical error
  • Loading branch information
dylanshine authored May 31, 2018
1 parent ae3ccf7 commit f8b53a5
Show file tree
Hide file tree
Showing 39 changed files with 1,341 additions and 1,153 deletions.
16 changes: 12 additions & 4 deletions Example/OKTableViewLiaison.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
FC6E84EC207EB29000BF0E58 /* PostTableViewSectionHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FC6E84E8207EB29000BF0E58 /* PostTableViewSectionHeaderView.xib */; };
FC6E84EE207EB29800BF0E58 /* TextTableViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC6E84ED207EB29800BF0E58 /* TextTableViewRow.swift */; };
FC6E84F1207EB2B600BF0E58 /* PostTableViewSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC6E84F0207EB2B600BF0E58 /* PostTableViewSection.swift */; };
FCAF2A4F20BEF74000DAD378 /* PostTableViewSectionHeaderViewComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF2A4E20BEF74000DAD378 /* PostTableViewSectionHeaderViewComponent.swift */; };
FCAF2A5120BEFD1000DAD378 /* TestTableViewSectionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF2A5020BEFD1000DAD378 /* TestTableViewSectionComponent.swift */; };
FCAF2A5320BF094500DAD378 /* OKTableViewSectionComponent+UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCAF2A5220BF094500DAD378 /* OKTableViewSectionComponent+UnitTests.swift */; };
FCF38FE3207EAEB300E119FB /* TestTableViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FDE207EAEB300E119FB /* TestTableViewRow.swift */; };
FCF38FE4207EAEB300E119FB /* TestTableViewLiaisonPaginationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FDF207EAEB300E119FB /* TestTableViewLiaisonPaginationDelegate.swift */; };
FCF38FE5207EAEB300E119FB /* TestTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FE0207EAEB300E119FB /* TestTableViewCell.swift */; };
FCF38FE6207EAEB300E119FB /* TestTableViewSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FE1207EAEB300E119FB /* TestTableViewSection.swift */; };
FCF38FE7207EAEB300E119FB /* UITableView+SwizzleTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FE2207EAEB300E119FB /* UITableView+SwizzleTesting.swift */; };
FCF38FEB207EAF5500E119FB /* OKTableViewSection+UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FE8207EAF5400E119FB /* OKTableViewSection+UnitTests.swift */; };
FCF38FEC207EAF5500E119FB /* OKTableViewRow+UnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCF38FE9207EAF5400E119FB /* OKTableViewRow+UnitTests.swift */; };
Expand Down Expand Up @@ -87,10 +89,12 @@
FC6E84E8207EB29000BF0E58 /* PostTableViewSectionHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PostTableViewSectionHeaderView.xib; sourceTree = "<group>"; };
FC6E84ED207EB29800BF0E58 /* TextTableViewRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextTableViewRow.swift; sourceTree = "<group>"; };
FC6E84F0207EB2B600BF0E58 /* PostTableViewSection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostTableViewSection.swift; sourceTree = "<group>"; };
FCAF2A4E20BEF74000DAD378 /* PostTableViewSectionHeaderViewComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTableViewSectionHeaderViewComponent.swift; sourceTree = "<group>"; };
FCAF2A5020BEFD1000DAD378 /* TestTableViewSectionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTableViewSectionComponent.swift; sourceTree = "<group>"; };
FCAF2A5220BF094500DAD378 /* OKTableViewSectionComponent+UnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OKTableViewSectionComponent+UnitTests.swift"; sourceTree = "<group>"; };
FCF38FDE207EAEB300E119FB /* TestTableViewRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTableViewRow.swift; sourceTree = "<group>"; };
FCF38FDF207EAEB300E119FB /* TestTableViewLiaisonPaginationDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTableViewLiaisonPaginationDelegate.swift; sourceTree = "<group>"; };
FCF38FE0207EAEB300E119FB /* TestTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTableViewCell.swift; sourceTree = "<group>"; };
FCF38FE1207EAEB300E119FB /* TestTableViewSection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTableViewSection.swift; sourceTree = "<group>"; };
FCF38FE2207EAEB300E119FB /* UITableView+SwizzleTesting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+SwizzleTesting.swift"; sourceTree = "<group>"; };
FCF38FE8207EAF5400E119FB /* OKTableViewSection+UnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OKTableViewSection+UnitTests.swift"; sourceTree = "<group>"; };
FCF38FE9207EAF5400E119FB /* OKTableViewRow+UnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OKTableViewRow+UnitTests.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -172,6 +176,7 @@
FCF38FEA207EAF5500E119FB /* OKTableViewLiaison+UnitTests.swift */,
FCF38FE9207EAF5400E119FB /* OKTableViewRow+UnitTests.swift */,
FCF38FE8207EAF5400E119FB /* OKTableViewSection+UnitTests.swift */,
FCAF2A5220BF094500DAD378 /* OKTableViewSectionComponent+UnitTests.swift */,
FCF38FDD207EAE9900E119FB /* Fixtures */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
Expand Down Expand Up @@ -271,6 +276,7 @@
isa = PBXGroup;
children = (
FC6E84F0207EB2B600BF0E58 /* PostTableViewSection.swift */,
FCAF2A4E20BEF74000DAD378 /* PostTableViewSectionHeaderViewComponent.swift */,
);
name = Sections;
sourceTree = "<group>";
Expand All @@ -281,7 +287,7 @@
FCF38FE0207EAEB300E119FB /* TestTableViewCell.swift */,
FCF38FDF207EAEB300E119FB /* TestTableViewLiaisonPaginationDelegate.swift */,
FCF38FDE207EAEB300E119FB /* TestTableViewRow.swift */,
FCF38FE1207EAEB300E119FB /* TestTableViewSection.swift */,
FCAF2A5020BEFD1000DAD378 /* TestTableViewSectionComponent.swift */,
FCF38FE2207EAEB300E119FB /* UITableView+SwizzleTesting.swift */,
);
name = Fixtures;
Expand Down Expand Up @@ -479,6 +485,7 @@
FC6E84E9207EB29000BF0E58 /* PostTableViewSectionHeaderView.swift in Sources */,
FC6E84EE207EB29800BF0E58 /* TextTableViewRow.swift in Sources */,
FC6E84F1207EB2B600BF0E58 /* PostTableViewSection.swift in Sources */,
FCAF2A4F20BEF74000DAD378 /* PostTableViewSectionHeaderViewComponent.swift in Sources */,
FC4A048920AB3B3700B692EC /* ImageTableViewRow.swift in Sources */,
FC6E84E4207EB28100BF0E58 /* ImageTableViewCell.swift in Sources */,
FC6E84E2207EB28100BF0E58 /* ActionButtonsTableViewCell.swift in Sources */,
Expand All @@ -497,14 +504,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FCAF2A5120BEFD1000DAD378 /* TestTableViewSectionComponent.swift in Sources */,
FCF38FE3207EAEB300E119FB /* TestTableViewRow.swift in Sources */,
FCF38FE5207EAEB300E119FB /* TestTableViewCell.swift in Sources */,
FCF38FE4207EAEB300E119FB /* TestTableViewLiaisonPaginationDelegate.swift in Sources */,
FCF38FE6207EAEB300E119FB /* TestTableViewSection.swift in Sources */,
FCF38FEB207EAF5500E119FB /* OKTableViewSection+UnitTests.swift in Sources */,
FCF38FE7207EAEB300E119FB /* UITableView+SwizzleTesting.swift in Sources */,
FCF38FED207EAF5500E119FB /* OKTableViewLiaison+UnitTests.swift in Sources */,
FCF38FEC207EAF5500E119FB /* OKTableViewRow+UnitTests.swift in Sources */,
FCAF2A5320BF094500DAD378 /* OKTableViewSectionComponent+UnitTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion Example/OKTableViewLiaison/ActionButtonsTableViewRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ActionButtonsTableViewRow: OKTableViewRow<ActionButtonsTableViewCell
init() {
super.init((), registrationType: ActionButtonsTableViewRow.defaultNibRegistrationType)

set(height: .height, value: 30)
set(height: .height, 30)
set(command: .configuration) { cell, _, _ in
cell.likeButton.setTitle("❤️", for: .normal)
cell.commentButton.setTitle("💬", for: .normal)
Expand Down
13 changes: 4 additions & 9 deletions Example/OKTableViewLiaison/ContentFeedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,19 @@ final class ContentFeedViewController: UIViewController {
private let liaison = OKTableViewLiaison()
private let refreshControl = UIRefreshControl()

private var initialSections: [OKAnyTableViewSection] {
private var initialSections: [PostTableViewSection] {
return Post.initialPosts()
.map(section(for:))
}

private func section(for post: Post) -> PostTableViewSection {
return PostTableViewSectionFactory.section(for: post, width: tableView.frame.width)
.map(PostTableViewSectionFactory.section(for:))
}

override func viewDidLoad() {
super.viewDidLoad()

refreshControl.addTarget(self, action: #selector(refreshSections), for: .valueChanged)
tableView.addSubview(refreshControl)

liaison.paginationDelegate = self
liaison.liaise(tableView: tableView)

liaison.append(sections: initialSections)
}

Expand All @@ -55,7 +50,7 @@ extension ContentFeedViewController: OKTableViewLiaisonPaginationDelegate {
liaison.scroll(to: indexPath)

let sections = Post.paginatedPosts()
.map(section(for:))
.map(PostTableViewSectionFactory.section(for:))

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.liaison.append(sections: sections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import OKTableViewLiaison

enum PostTableViewSectionFactory {

static func section(for post: Post, width: CGFloat) -> PostTableViewSection {
let rows: [OKAnyTableViewRow] = [ImageTableViewRow(image: post.content,
width: width),
ActionButtonsTableViewRow(),
TextTableViewRowFactory.likesRow(numberOfLikes: post.numberOfLikes),
TextTableViewRowFactory.captionRow(user: post.user.username, caption: post.caption),
TextTableViewRowFactory.commentRow(commentCount: post.numberOfComments),
TextTableViewRowFactory.timeRow(numberOfSeconds: post.timePosted)]
static func section(for post: Post) -> PostTableViewSection {
let rows: [OKAnyTableViewRow] = [
ImageTableViewRow(image: post.content),
ActionButtonsTableViewRow(),
TextTableViewRowFactory.likesRow(numberOfLikes: post.numberOfLikes),
TextTableViewRowFactory.captionRow(user: post.user.username, caption: post.caption),
TextTableViewRowFactory.commentRow(commentCount: post.numberOfComments),
TextTableViewRowFactory.timeRow(numberOfSeconds: post.timePosted)
]

return PostTableViewSection(user: post.user, rows: rows)
}
Expand Down
4 changes: 2 additions & 2 deletions Example/OKTableViewLiaison/ImageTableViewRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import OKTableViewLiaison

final class ImageTableViewRow: OKTableViewRow<ImageTableViewCell, UIImage> {

init(image: UIImage, width: CGFloat) {
init(image: UIImage) {

super.init(image, registrationType: ImageTableViewRow.defaultNibRegistrationType)

set(height: .height) { image -> CGFloat in
let ratio = image.size.width / image.size.height
return width / ratio
return UIScreen.main.bounds.width / ratio
}

set(command: .configuration) { cell, image, indexPath in
Expand Down
17 changes: 2 additions & 15 deletions Example/OKTableViewLiaison/PostTableViewSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,10 @@
import UIKit
import OKTableViewLiaison

final class PostTableViewSection: OKTableViewSection<PostTableViewSectionHeaderView, UITableViewHeaderFooterView, User> {
final class PostTableViewSection: OKTableViewSection {

init(user: User, rows: [OKAnyTableViewRow] = []) {

super.init(user, rows: rows, supplementaryViewDisplay: .header(registrationType: PostTableViewSection.defaultHeaderNibRegistrationType))

setHeight(for: .header, value: 70)

setHeader(command: .configuration) { header, user, section in
header.imageView.image = user.avatar
header.imageView.layer.borderColor = UIColor.gray.cgColor
header.imageView.layer.borderWidth = 1

header.titleLabel.text = user.username
header.titleLabel.font = .systemFont(ofSize: 13, weight: .medium)
header.titleLabel.textColor = .black
}
super.init(rows: rows, componentDisplayOption: .header(component: PostTableViewSectionHeaderViewComponent(user: user)))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// PostTableViewSectionHeaderViewComponent.swift
// OKTableViewLiaison_Example
//
// Created by Dylan Shine on 5/30/18.
// Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import OKTableViewLiaison

final class PostTableViewSectionHeaderViewComponent: OKTableViewSectionComponent<PostTableViewSectionHeaderView, User> {

public init(user: User) {

super.init(user, registrationType: PostTableViewSectionHeaderViewComponent.defaultNibRegistrationType)

set(height: .height, 70)

set(command: .configuration) { view, user, section in
view.imageView.image = user.avatar
view.imageView.layer.borderColor = UIColor.gray.cgColor
view.imageView.layer.borderWidth = 1

view.titleLabel.text = user.username
view.titleLabel.font = .systemFont(ofSize: 13, weight: .medium)
view.titleLabel.textColor = .black
}
}
}
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- OKTableViewLiaison (1.4.0)
- OKTableViewLiaison (2.0.0)

DEPENDENCIES:
- OKTableViewLiaison (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
OKTableViewLiaison: 1f5b71721c98b4a3141a0a32d0c73296c2c21e61
OKTableViewLiaison: 8eeb53b4d8b9bf21d5b0c1aed856923c3e1d82cb

PODFILE CHECKSUM: 9150dd9310401db4896273bd584c73be0d2714d2

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/OKTableViewLiaison.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f8b53a5

Please sign in to comment.