Skip to content

Commit

Permalink
Merge pull request #5 from giulio92/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
giulio92 authored Dec 19, 2016
2 parents 869b300 + c891a58 commit b1e26e1
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
- PROJECT=GLTableCollectionView.xcodeproj
- SCHEME=GLTableCollectionView
- SDK=iphonesimulator10.1
- DESTINATION="OS=10.1,name=iPhone 5"
- DESTINATION="platform=iOS Simulator,OS=latest,name=iPhone 5"

before_install:
- brew update
Expand Down
37 changes: 37 additions & 0 deletions GLTableCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,28 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
INFOPLIST_FILE = GLTableCollectionView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -373,9 +392,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEVELOPMENT_TEAM = "";
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
INFOPLIST_FILE = GLTableCollectionView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
28 changes: 15 additions & 13 deletions GLTableCollectionView/GLCollectionTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@ class GLIndexedCollectionViewFlowLayout: UICollectionViewFlowLayout {
}

// To make paginated scrolling work fine this CGFloat below must be
// equal to the value set in the insetForSectionAt method
// equal to the value set in the insetForSectionAt method of
// UICollectionView's UICollectionViewDelegate Flow Layout.
let collectionViewInsets: CGFloat = 10.0

// Since UICollectionViewFlowLayout proposedContentOffset coordinates
// won't take count of any UICollectionView UIEdgeInsets values we need
// to fix it by adding collectionViewInsets to .x coordinate.
// to fix it by adding collectionViewInsets to the .x coordinate.
//
// Note: This will cover horizonal scrolling and pagination, if you need
// vertical pagination replace the .x coordinate with .y and update
// Note: This will only cover horizonal scrolling and pagination, if you
// need vertical pagination replace the .x coordinate with .y and update
// collectionViewInsets value with the approriate one.
let proposedXCoordWithInsets = proposedContentOffset.x + collectionViewInsets

// We start by creating a variable and we assign a very high CGFloat to
// it, a big number here is needed to cover very large
// UICollectionViewContentSize cases.
// We now create a variable and we assign a very high CGFloat to it (a
// big number here is needed to cover very large
// UICollectionViewContentSize cases). This var will hold the needed
// horizontal adjustment to make the UICollectionView paginate scroll.
var offsetCorrection: CGFloat = .greatestFiniteMagnitude

// Now we loop through all the different layout attributes of the
// UICollectionViewCells contained between the .x value of the
// proposedContentOffset and collectionView's width looking for the cell
// which needs the least offsetCorrection value, it will mean that it's
// the first cell on the left of the screen which will give pagination.
// proposedContentOffset and collectionView's width, looking for the
// cell which needs the least offsetCorrection value: it will mean that
// it's the first cell on the left of the screen which will give
// pagination.
for layoutAttributes in super.layoutAttributesForElements(in: CGRect(x: proposedContentOffset.x, y: 0, width: collectionView!.bounds.width, height: collectionView!.bounds.height))! {
// Since layoutAttributesForElements may contain all sort of layout
// attributes we need to check if it belongs to a
Expand Down Expand Up @@ -169,11 +171,11 @@ class GLCollectionTableViewCell: UITableViewCell {

- Parameter dataSource: The `dataSource` class for the
GLIndexedCollectionView in the GLCollectionTableViewCell, it will be
responsible for the usual UICollectionView `dataSource` methods.
responsible for the UICollectionView's `dataSource` methods.

- Parameter delegate: The `delegate class` for the GLIndexedCollectionView
in the GLCollectionTableViewCell, it will be responsible for the usual
UICollectionView delegation methods.
in the GLCollectionTableViewCell, it will be responsible for the
UICollectionView's delegation methods.

- Parameter indexPath: The inner-`indexPath` of the GLIndexedCollectionView,
it's recommended to pass the same `indexPath` of the UITableViewCell to the
Expand Down
18 changes: 9 additions & 9 deletions GLTableCollectionView/GLTableCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class GLTableCollectionViewController: UITableViewController, UICollectionViewDa
// This string constant will be the cellIdentifier for the UITableViewCells
// holding the UICollectionView, it's important to append "_section#" to it
// so we can understand which cell is the one we are looking for in the
// debugger. Look in the UITableView's data source cellForRowAt method for
// more explaination about how we handle the cell reuse.
// debugger. Look in UITableView's data source cellForRowAt method for more
// explainations about the UITableViewCell reuse handling.
let tableCellID: String = "tableViewCellID_section_#"
let collectionCellID: String = "collectionViewCellID"

Expand All @@ -23,7 +23,7 @@ class GLTableCollectionViewController: UITableViewController, UICollectionViewDa

var colorsDict: [Int: [UIColor]] = [:]

// Set true to enable UICollectionViews scroll pagination
/// Set true to enable UICollectionViews scroll pagination
var paginationEnabled: Bool = true

override func viewDidLoad() {
Expand Down Expand Up @@ -72,18 +72,18 @@ class GLTableCollectionViewController: UITableViewController, UICollectionViewDa
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// As you can see below instead of having a single cellIdentifier for
// each type of UITableViewCells, as you would do with normally, we will
// have multiple IDs each related to a indexPath section. Doing so the
// UITableViewCells will still be recycled but it will be done only with
// dequeueReusableCell of a given section.
// Instead of having a single cellIdentifier for each type of
// UITableViewCells, like in a regular implementation, we have multiple
// cellIDs, each related to a indexPath section. By Doing so the
// UITableViewCells will still be recycled but only with
// dequeueReusableCell of that section.
//
// For example the cellIdentifier for section 4 cells will be:
// "tableViewCellID_section_#3"
// dequeueReusableCell will only reuse previous UITableViewCells with
// the same cellIdentifier instead of using any UITableViewCell as a
// regular UITableView would do, this is necessary because every cell
// will have a different UICollectionView and UICollectionViewCells in
// will have a different UICollectionView with UICollectionViewCells in
// it and UITableView reuse won't work as expected giving back wrong
// cells.
var cell: GLCollectionTableViewCell? = tableView.dequeueReusableCell(withIdentifier: tableCellID + indexPath.section.description) as? GLCollectionTableViewCell
Expand Down
Binary file modified GitHub Page/Images/Source/Diagram.graffle
Binary file not shown.
Binary file modified GitHub Page/Images/Source/Logo.pxm
Binary file not shown.
Binary file modified GitHub Page/Images/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GitHub Page/Images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
[![GitHub license](https://img.shields.io/badge/license-AGPL-blue.svg)](https://raw.githubusercontent.com/giulio92/GLTableCollectionView/master/LICENSE.txt)

## What it is
GLTableCollectionView is a ready-to-use ```UITableViewController``` with a ```UICollectionView``` for each ```UITableViewCell```, something like Netflix, Airbnb or the Apple's App Store are doing in their iOS apps. GLTableCollectionView is completely customizable in both his UITableView and UICollectionView parts since it has been made on the same Data Source and Delegate methods with no complicated additions.
GLTableCollectionView is a ready to use `UITableViewController` with a `UICollectionView` for each `UITableViewCell`, something like Netflix, Airbnb or the Apple's App Store are doing in their iOS apps. GLTableCollectionView is completely customizable in both his UITableView and UICollectionView parts since it has been made on the same Data Source and Delegate methods with no complicated additions.

||**GLTableCollectionView**|
|:---:|---|
|🔄|Uses the **same** ```UITableView``` reusable cells logic provided from Apple's implementation|
|♻️|```UICollectionView``` cell recycle|
|🆒|Both ```UITableView``` & ```UICollectionView``` can have their own sections and/or headers|
|🖼|Customization of ```UICollectionViewCell```s using the same ```UICollectionViewDelegate Flow Layout``` you already know|
||Previous ```UICollectionView``` **.contentOffset** value restoration after scroll|
|🔄|Uses the **same** `UITableView` reusable cells logic provided from Apple's implementation|
|♻️|`UICollectionView` cell recycle|
|🆒|Both `UITableView` & `UICollectionView` can have their own sections and/or headers|
|🎨|Customization of `UICollectionViewCell`s using the same `UICollectionViewDelegate Flow Layout` you already know|
||Previous `UICollectionView` **.contentOffset** value restoration after scroll|
|↔️|UICollectionView cell-size-based scroll pagination, see below for instructions|
|📐|Storyboard and Auto Layout compatibility|
|💎|Clean architecture|
|🔧|Unit Tests|

## Enable/disable scroll pagination
Set ```paginationEnabled``` variable ```true``` in GLTableCollectionViewController class, ```false``` to disable
Set `paginationEnabled` variable `true` in GLTableCollectionViewController class, `false` to disable. Default value is `true`.
```
// Set true to enable UICollectionViews scroll pagination
/// Set true to enable UICollectionViews scroll pagination
var paginationEnabled: Bool = true
```

Expand All @@ -52,4 +52,4 @@ var paginationEnabled: Bool = true
- iOS 8.0+

## Note
GLTableCollectionView is written using Swift 3.0 so it would only support iOS 8.0+ due to Swift 3 language compatibility, if you use Swift 2.0 in your project or you need iOS 7.0+ compatibility GLTableCollectionView will work too, but you **must** convert ```UITableView``` and ```UICollectionView``` Data Source and Delegate methods signatures before building your code or Xcode won't compile.
GLTableCollectionView is written using Swift 3.0 so it would only support iOS 8.0+ due to Swift 3 language compatibility, if you use Swift 2.0 in your project or you need iOS 7.0+ compatibility GLTableCollectionView will work too, but you **must** convert `UITableView` and `UICollectionView` Data Source and Delegate methods signatures before building your code or Xcode won't compile.

0 comments on commit b1e26e1

Please sign in to comment.