Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackjacx committed Aug 9, 2019
2 parents 7d0d148 + 8c7d283 commit 7c968c8
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [1.0.5] - 2019-08-09
* Use customized cells so the separator inset works correctly - [@Blackjacx](https://github.com/blackjacx).
* Call adjustCellSeparatorInsets in all Examples - [@Blackjacx](https://github.com/blackjacx).

## [1.0.4] - 2019-08-09
* Fix hiding last N separators - [@Blackjacx](https://github.com/blackjacx).

Expand Down
7 changes: 7 additions & 0 deletions Example/Source/MultiSectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,11 @@ extension MultiSectionViewController: UITableViewDelegate {
let model = dataSource.collection[indexPath]
model.didTap?(indexPath)
}

// Adjusting the seperator insets: http://stackoverflow.com/a/39005773/971329
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.adjustCellSeparatorInsets(at: indexPath,
for: dataSource.collection,
numberOfLastSeparatorsToHide: dataSource.numberOfLastSeparatorsToHide)
}
}
34 changes: 32 additions & 2 deletions Example/Source/MyConfigurableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,42 @@ import UIKit
import Source

class MyConfigurableCell: UITableViewCell, Reusable {
let titleLabel = UILabel()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

titleLabel.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(titleLabel)

setupLayoutConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupLayoutConstraints() {

let raster: CGFloat = 11

let constraints: [NSLayoutConstraint] = [
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: raster),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -raster),
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: raster),
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -raster)
]
NSLayoutConstraint.activate(constraints)
}
}


extension MyConfigurableCell: Configurable {

func configure(with model: ViewModel?) throws {
guard let myModel = model as? MyModel else { throw Source.Error.invalidModel(model) }
textLabel?.text = myModel.title
guard let myModel = model as? MyModel else {
throw Source.Error.invalidModel(model)
}
titleLabel.text = myModel.title
}
}
39 changes: 35 additions & 4 deletions Example/Source/MyDisclosureCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,44 @@
import UIKit
import Source

class MyDisclosureCell: UITableViewCell, Reusable {}
class MyDisclosureCell: UITableViewCell {
let titleLabel = UILabel()

extension MyDisclosureCell: Configurable {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

titleLabel.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(titleLabel)

setupLayoutConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupLayoutConstraints() {

let raster: CGFloat = 11

let constraints: [NSLayoutConstraint] = [
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: raster),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -raster),
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: raster),
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -raster)
]
NSLayoutConstraint.activate(constraints)
}
}


extension MyDisclosureCell: Configurable, Reusable {

func configure(with model: ViewModel?) throws {
guard let myModel = model as? MyModel else { throw Source.Error.invalidModel(model) }
guard let myModel = model as? MyModel else {
throw Source.Error.invalidModel(model)
}
titleLabel.text = myModel.title
accessoryType = .disclosureIndicator
textLabel?.text = myModel.title
}
}
7 changes: 7 additions & 0 deletions Example/Source/SimpleExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ extension SimpleExampleViewController: UITableViewDelegate {
let model = dataSource.collection[indexPath]
model.didTap?(indexPath)
}

// Adjusting the seperator insets: http://stackoverflow.com/a/39005773/971329
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.adjustCellSeparatorInsets(at: indexPath,
for: dataSource.collection,
numberOfLastSeparatorsToHide: dataSource.numberOfLastSeparatorsToHide)
}
}
4 changes: 3 additions & 1 deletion Example/Source/SingleSectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ extension SingleSectionViewController: UITableViewDelegate {

// Adjusting the seperator insets: http://stackoverflow.com/a/39005773/971329
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.adjustCellSeparatorInsets(at: indexPath, for: dataSource.collection)
cell.adjustCellSeparatorInsets(at: indexPath,
for: dataSource.collection,
numberOfLastSeparatorsToHide: dataSource.numberOfLastSeparatorsToHide)
}
}
2 changes: 1 addition & 1 deletion Source.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Source'
s.version = '1.0.4'
s.version = '1.0.5'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'The generic data source implementation for all your view controllers.'
s.description = <<-DESC
Expand Down
8 changes: 4 additions & 4 deletions Source.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Source/Info.plist;
Expand Down Expand Up @@ -368,11 +368,11 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Source/Info.plist;
Expand Down
8 changes: 4 additions & 4 deletions Source/Classes/UITableViewCell+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public extension UITableViewCell {

let model = modelCollection[indexPath]
var insets = model.separatorInsets

// Don't show the separator for the last N rows of the last section
let lastSection = modelCollection[modelCollection.sectionCount-1]
if indexPath.section == modelCollection.sectionCount-1
&& indexPath.row >= lastSection.count - numberOfLastSeparatorsToHide {
let shouldHideSeparator = indexPath.section == modelCollection.sectionCount-1
&& indexPath.row >= lastSection.count - numberOfLastSeparatorsToHide

// Don't show the separator for the last N rows of the last section
if shouldHideSeparator {
insets = NSDirectionalEdgeInsets(top: 0, leading: 9999, bottom: 0, trailing: 0)
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0.4</string>
<string>1.0.5</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
</dict>
</plist>

0 comments on commit 7c968c8

Please sign in to comment.