Skip to content

Commit

Permalink
Merge release/v1.4.3 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmitchell committed Aug 14, 2020
2 parents 51863ec + 123b868 commit 0ce7454
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Thunder Table

[![Build Status](https://travis-ci.org/3sidedcube/ThunderTable.svg)](https://travis-ci.org/3sidedcube/ThunderTable) [![Swift 5.2](http://img.shields.io/badge/swift-5.1-brightgreen.svg)](https://swift.org/blog/swift-5-2-released/) [![Apache 2](https://img.shields.io/badge/license-Apache%202-brightgreen.svg)](LICENSE.md)
[![Build Status](https://travis-ci.org/3sidedcube/ThunderTable.svg)](https://travis-ci.org/3sidedcube/ThunderTable) [![Swift 5.2](http://img.shields.io/badge/swift-5.2-brightgreen.svg)](https://swift.org/blog/swift-5-2-released/) [![Apache 2](https://img.shields.io/badge/license-Apache%202-brightgreen.svg)](LICENSE.md)

Thunder Table is a useful framework which enables quick and easy creation of table views in iOS, making the process of creating complex tables as simple as a few lines of code; and removing the necessity for having long chains of index paths and if statements.

Expand Down
8 changes: 4 additions & 4 deletions ThunderTable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
INFOPLIST_FILE = ThunderTableDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.3sidedcube.ThunderTableDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -614,7 +614,7 @@
INFOPLIST_FILE = ThunderTableDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.3sidedcube.ThunderTableDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -754,7 +754,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.threesidedcube.ThunderTable;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -779,7 +779,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.threesidedcube.ThunderTable;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
12 changes: 9 additions & 3 deletions ThunderTable/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public extension UIImageView {
// If no remaining requests, call the completion
if welf.requests?.count == 0 {

welf.cancelCurrentRequestOperations()
welf.cancelCurrentRequestOperations(callingCompletion: false)
welf.imageURLS = nil
welf.completion?(image, error)
welf.completion = nil
Expand All @@ -210,12 +210,18 @@ public extension UIImageView {
})
}

private func cancelCurrentRequestOperations() {

private func cancelCurrentRequestOperations(callingCompletion: Bool = true) {
if callingCompletion {
completion?(nil, ImageViewError.cancelledDueToNewUrl)
}
requests?.forEach({ (request) in
ImageController.shared.cancel(imageRequest: request)
})
requests = nil
}
}

enum ImageViewError: Error {
case cancelledDueToNewUrl
}

13 changes: 13 additions & 0 deletions ThunderTable/TableViewController+Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation

extension TableViewController {

//MARK: - Subscript Functions

public subscript (index: IndexPath) -> (section: Section, row: Row)? {

guard index.section < data.count else {
Expand All @@ -36,4 +38,15 @@ extension TableViewController {

return data[index.section]
}

/// forEach Array equivalant for looping across all sections and rows of current `data`
/// - Parameter body: A closure that takes each row, indexPath and section as the parameters.
public func forEachRow(_ body: (Row, IndexPath, Section) -> Void) {

data.enumerated().forEach { (sectionIndex, section) in
section.rows.enumerated().forEach { (rowIndex, row) in
body(row, IndexPath(row: rowIndex, section: sectionIndex), section)
}
}
}
}
30 changes: 25 additions & 5 deletions ThunderTable/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,40 @@ open class TableViewController: UITableViewController, UIContentSizeCategoryAdju
size = imageSize
}

imageView?.set(imageURL: row.imageURL, withPlaceholder: row.image, imageSize: size, animated: true, completion: { [weak self] (image, error) -> (Void) in
// Only load image from url if we have an image url
if let imageURL = row.imageURL {

if let welf = self, _row.image == nil {
imageView?.set(imageURL: imageURL, withPlaceholder: row.image, imageSize: size, animated: true, completion: { [weak self] (image, error) -> (Void) in

guard let self = self else { return }
guard let image = image, _row.image == nil else { return }
_row.image = image
welf.tableView.reloadRows(at: [indexPath], with: .none)
}
})
// Try and find matching index paths with the same imageURL and reload it.
// We can't use `indexPath` provided to this function as it may have changed!
self.reloadRows(where: { $0.imageURL == imageURL })
})
}

textLabel?.paragraphStyle = ThemeManager.shared.theme.cellTitleParagraphStyle
detailLabel?.paragraphStyle = ThemeManager.shared.theme.cellDetailParagraphStyle

row.configure(cell: cell, at: indexPath, in: self)
}

/// Reloads all table rows where the row matches a certain predicate
/// - Parameter predicate: The predicate to match rows based on
/// - Parameter animation: The animation to run when reloading
public func reloadRows(where predicate: (Row) -> Bool, with animation: UITableView.RowAnimation = .none) {

var indexPathsToReload: [IndexPath] = []
self.forEachRow { (row, indexPath, _) in
guard predicate(row) else { return }
indexPathsToReload.append(indexPath)
}
guard !indexPathsToReload.isEmpty else { return }
self.tableView.reloadRows(at: indexPathsToReload, with: animation)
}

private func register(row: Row) {

guard let identifier = row.identifier else { return }
Expand Down

0 comments on commit 0ce7454

Please sign in to comment.