Browse Source

remove old library

Marino Faggiana 7 years ago
parent
commit
1039bf28a4
28 changed files with 0 additions and 5451 deletions
  1. 0 20
      Libraries external/PSTCollectionView/NSIndexPath+PSTCollectionViewAdditions.h
  2. 0 25
      Libraries external/PSTCollectionView/NSIndexPath+PSTCollectionViewAdditions.m
  3. 0 136
      Libraries external/PSTCollectionView/PSTCollectionView.h
  4. 0 2310
      Libraries external/PSTCollectionView/PSTCollectionView.m
  5. 0 49
      Libraries external/PSTCollectionView/PSTCollectionViewCell.h
  6. 0 267
      Libraries external/PSTCollectionView/PSTCollectionViewCell.m
  7. 0 73
      Libraries external/PSTCollectionView/PSTCollectionViewCommon.h
  8. 0 24
      Libraries external/PSTCollectionView/PSTCollectionViewController.h
  9. 0 145
      Libraries external/PSTCollectionView/PSTCollectionViewController.m
  10. 0 75
      Libraries external/PSTCollectionView/PSTCollectionViewData.h
  11. 0 235
      Libraries external/PSTCollectionView/PSTCollectionViewData.m
  12. 0 115
      Libraries external/PSTCollectionView/PSTCollectionViewFlowLayout.h
  13. 0 420
      Libraries external/PSTCollectionView/PSTCollectionViewFlowLayout.m
  14. 0 28
      Libraries external/PSTCollectionView/PSTCollectionViewItemKey.h
  15. 0 77
      Libraries external/PSTCollectionView/PSTCollectionViewItemKey.m
  16. 0 18
      Libraries external/PSTCollectionView/PSTCollectionViewLayout+Internals.h
  17. 0 128
      Libraries external/PSTCollectionView/PSTCollectionViewLayout.h
  18. 0 481
      Libraries external/PSTCollectionView/PSTCollectionViewLayout.m
  19. 0 41
      Libraries external/PSTCollectionView/PSTCollectionViewUpdateItem.h
  20. 0 117
      Libraries external/PSTCollectionView/PSTCollectionViewUpdateItem.m
  21. 0 43
      Libraries external/PSTCollectionView/PSTGridLayoutInfo.h
  22. 0 76
      Libraries external/PSTCollectionView/PSTGridLayoutInfo.m
  23. 0 19
      Libraries external/PSTCollectionView/PSTGridLayoutItem.h
  24. 0 19
      Libraries external/PSTCollectionView/PSTGridLayoutItem.m
  25. 0 43
      Libraries external/PSTCollectionView/PSTGridLayoutRow.h
  26. 0 193
      Libraries external/PSTCollectionView/PSTGridLayoutRow.m
  27. 0 64
      Libraries external/PSTCollectionView/PSTGridLayoutSection.h
  28. 0 210
      Libraries external/PSTCollectionView/PSTGridLayoutSection.m

+ 0 - 20
Libraries external/PSTCollectionView/NSIndexPath+PSTCollectionViewAdditions.h

@@ -1,20 +0,0 @@
-//
-//  NSIndexPath+PSTCollectionViewAdditions.h
-//  PSTCollectionView
-//
-//  Copyright (c) 2013 Peter Steinberger. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
-
-@interface NSIndexPath (PSTCollectionViewAdditions)
-
-+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;
-
-- (NSInteger)item;
-
-@end
-
-#endif

+ 0 - 25
Libraries external/PSTCollectionView/NSIndexPath+PSTCollectionViewAdditions.m

@@ -1,25 +0,0 @@
-//
-//  NSIndexPath+PSTCollectionViewAdditions.m
-//  PSTCollectionView
-//
-//  Copyright (c) 2013 Peter Steinberger. All rights reserved.
-//
-
-#import "NSIndexPath+PSTCollectionViewAdditions.h"
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
-
-@implementation NSIndexPath (PSTCollectionViewAdditions)
-
-// Simple NSIndexPath addition to allow using "item" instead of "row".
-+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section {
-    return [NSIndexPath indexPathForRow:item inSection:section];
-}
-
-- (NSInteger)item {
-    return self.row;
-}
-
-@end
-
-#endif

+ 0 - 136
Libraries external/PSTCollectionView/PSTCollectionView.h

@@ -1,136 +0,0 @@
-//
-//  PSTCollectionView.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewLayout.h"
-#import "PSTCollectionViewFlowLayout.h"
-#import "PSTCollectionViewCell.h"
-#import "PSTCollectionViewController.h"
-#import "PSTCollectionViewUpdateItem.h"
-
-@class PSTCollectionViewController;
-
-typedef NS_OPTIONS(NSUInteger, PSTCollectionViewScrollPosition) {
-    PSTCollectionViewScrollPositionNone                 = 0,
-
-    // The vertical positions are mutually exclusive to each other, but are bitwise or-able with the horizontal scroll positions.
-    // Combining positions from the same grouping (horizontal or vertical) will result in an NSInvalidArgumentException.
-    PSTCollectionViewScrollPositionTop                  = 1 << 0,
-    PSTCollectionViewScrollPositionCenteredVertically   = 1 << 1,
-    PSTCollectionViewScrollPositionBottom               = 1 << 2,
-
-    // Likewise, the horizontal positions are mutually exclusive to each other.
-    PSTCollectionViewScrollPositionLeft                 = 1 << 3,
-    PSTCollectionViewScrollPositionCenteredHorizontally = 1 << 4,
-    PSTCollectionViewScrollPositionRight                = 1 << 5
-};
-
-typedef NS_ENUM(NSUInteger, PSTCollectionElementCategory) {
-    PSTCollectionElementCategoryCell,
-    PSTCollectionElementCategorySupplementaryView,
-    PSTCollectionElementCategoryDecorationView
-};
-
-// Define the `PSTCollectionViewDisableForwardToUICollectionViewSentinel` to disable the automatic forwarding to UICollectionView on iOS 6+. (Copy below line into your AppDelegate.m)
-//@interface PSTCollectionViewDisableForwardToUICollectionViewSentinel : NSObject @end @implementation PSTCollectionViewDisableForwardToUICollectionViewSentinel @end
-
-// API-compatible replacement for UICollectionView.
-// Works on iOS 4.3 upwards (including iOS 6).
-@interface PSTCollectionView : UIScrollView
-
-- (id)initWithFrame:(CGRect)frame collectionViewLayout:(PSTCollectionViewLayout *)layout; // the designated initializer
-
-@property (nonatomic, strong) PSTCollectionViewLayout *collectionViewLayout;
-@property (nonatomic, assign) IBOutlet id<PSTCollectionViewDelegate> delegate;
-@property (nonatomic, assign) IBOutlet id<PSTCollectionViewDataSource> dataSource;
-@property (nonatomic, strong) UIView *backgroundView; // will be automatically resized to track the size of the collection view and placed behind all cells and supplementary views.
-
-// For each reuse identifier that the collection view will use, register either a class or a nib from which to instantiate a cell.
-// If a nib is registered, it must contain exactly 1 top level object which is a PSTCollectionViewCell.
-// If a class is registered, it will be instantiated via alloc/initWithFrame:
-- (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
-
-- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
-
-- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
-
-// TODO: implement!
-- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;
-
-- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
-
-- (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;
-
-// These properties control whether items can be selected, and if so, whether multiple items can be simultaneously selected.
-@property (nonatomic) BOOL allowsSelection; // default is YES
-@property (nonatomic) BOOL allowsMultipleSelection; // default is NO
-
-- (NSArray *)indexPathsForSelectedItems; // returns nil or an array of selected index paths
-- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition;
-
-- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
-
-- (void)reloadData; // discard the dataSource and delegate data and requery as necessary
-
-- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout animated:(BOOL)animated; // transition from one layout to another
-
-// Information about the current state of the collection view.
-
-- (NSInteger)numberOfSections;
-
-- (NSInteger)numberOfItemsInSection:(NSInteger)section;
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
-
-- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point;
-
-- (NSIndexPath *)indexPathForCell:(PSTCollectionViewCell *)cell;
-
-- (PSTCollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (NSArray *)visibleCells;
-
-- (NSArray *)indexPathsForVisibleItems;
-
-// Interacting with the collection view.
-
-- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(PSTCollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
-
-// These methods allow dynamic modification of the current set of items in the collection view
-- (void)insertSections:(NSIndexSet *)sections;
-- (void)deleteSections:(NSIndexSet *)sections;
-- (void)reloadSections:(NSIndexSet *)sections;
-- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;
-- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths;
-- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths;
-- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths;
-- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
-- (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion; // allows multiple insert/delete/reload/move calls to be animated simultaneously. Nestable.
-
-@end
-
-// To dynamically switch between PSTCollectionView and UICollectionView, use the PSUICollectionView* classes.
-#define PSUICollectionView PSUICollectionView_
-#define PSUICollectionViewCell PSUICollectionViewCell_
-#define PSUICollectionReusableView PSUICollectionReusableView_
-#define PSUICollectionViewDelegate PSTCollectionViewDelegate
-#define PSUICollectionViewDataSource PSTCollectionViewDataSource
-#define PSUICollectionViewLayout PSUICollectionViewLayout_
-#define PSUICollectionViewFlowLayout PSUICollectionViewFlowLayout_
-#define PSUICollectionViewDelegateFlowLayout PSTCollectionViewDelegateFlowLayout
-#define PSUICollectionViewLayoutAttributes PSUICollectionViewLayoutAttributes_
-#define PSUICollectionViewController PSUICollectionViewController_
-
-@interface PSUICollectionView_ : PSTCollectionView @end
-@interface PSUICollectionViewCell_ : PSTCollectionViewCell @end
-@interface PSUICollectionReusableView_ : PSTCollectionReusableView @end
-@interface PSUICollectionViewLayout_ : PSTCollectionViewLayout @end
-@interface PSUICollectionViewFlowLayout_ : PSTCollectionViewFlowLayout @end
-@protocol PSUICollectionViewDelegateFlowLayout_ <PSTCollectionViewDelegateFlowLayout> @end
-@interface PSUICollectionViewLayoutAttributes_ : PSTCollectionViewLayoutAttributes @end
-@interface PSUICollectionViewController_ : PSTCollectionViewController <PSUICollectionViewDelegate, PSUICollectionViewDataSource> @end

+ 0 - 2310
Libraries external/PSTCollectionView/PSTCollectionView.m

@@ -1,2310 +0,0 @@
-//
-//  PSTCollectionView.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionView.h"
-#import "PSTCollectionViewData.h"
-#import "PSTCollectionViewLayout+Internals.h"
-#import "PSTCollectionViewItemKey.h"
-
-#import <objc/runtime.h>
-#if TARGET_IPHONE_SIMULATOR
-#import <dlfcn.h>
-#endif
-#import <tgmath.h>
-
-@interface PSTCollectionViewLayout (Internal)
-@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
-@end
-
-@interface PSTCollectionViewData (Internal)
-- (void)prepareToLoadData;
-@end
-
-@interface PSTCollectionViewCell (Internal)
-- (void)performSelectionSegue;
-@end
-
-@interface PSTCollectionViewUpdateItem ()
-- (NSIndexPath *)indexPath;
-
-- (BOOL)isSectionOperation;
-@end
-
-@interface PSTCollectionViewLayoutAttributes () {
-    char junk[128];
-}
-@property (nonatomic, copy) NSString *elementKind;
-@end
-
-CGFloat PSTSimulatorAnimationDragCoefficient(void);
-
-@class PSTCollectionViewExt;
-
-@interface PSTCollectionView () <UIScrollViewDelegate> {
-    // ivar layout needs to EQUAL to UICollectionView.
-    PSTCollectionViewLayout *_layout;
-    __unsafe_unretained id<PSTCollectionViewDataSource> _dataSource;
-    UIView *_backgroundView;
-    NSMutableSet *_indexPathsForSelectedItems;
-    NSMutableDictionary *_cellReuseQueues;
-    NSMutableDictionary *_supplementaryViewReuseQueues;
-    NSMutableDictionary *_decorationViewReuseQueues;
-    NSMutableSet *_indexPathsForHighlightedItems;
-    int _reloadingSuspendedCount;
-    PSTCollectionReusableView *_firstResponderView;
-    UIView *_newContentView;
-    int _firstResponderViewType;
-    NSString *_firstResponderViewKind;
-    NSIndexPath *_firstResponderIndexPath;
-    NSMutableDictionary *_allVisibleViewsDict;
-    NSIndexPath *_pendingSelectionIndexPath;
-    NSMutableSet *_pendingDeselectionIndexPaths;
-    PSTCollectionViewData *_collectionViewData;
-    id _update;
-    CGRect _visibleBoundRects;
-    CGRect _preRotationBounds;
-    CGPoint _rotationBoundsOffset;
-    int _rotationAnimationCount;
-    int _updateCount;
-    NSMutableArray *_insertItems;
-    NSMutableArray *_deleteItems;
-    NSMutableArray *_reloadItems;
-    NSMutableArray *_moveItems;
-    NSArray *_originalInsertItems;
-    NSArray *_originalDeleteItems;
-    UITouch *_currentTouch;
-
-    void (^_updateCompletionHandler)(BOOL finished);
-
-    NSMutableDictionary *_cellClassDict;
-    NSMutableDictionary *_cellNibDict;
-    NSMutableDictionary *_supplementaryViewClassDict;
-    NSMutableDictionary *_supplementaryViewNibDict;
-    NSMutableDictionary *_cellNibExternalObjectsTables;
-    NSMutableDictionary *_supplementaryViewNibExternalObjectsTables;
-    struct {
-        unsigned int delegateShouldHighlightItemAtIndexPath : 1;
-        unsigned int delegateDidHighlightItemAtIndexPath : 1;
-        unsigned int delegateDidUnhighlightItemAtIndexPath : 1;
-        unsigned int delegateShouldSelectItemAtIndexPath : 1;
-        unsigned int delegateShouldDeselectItemAtIndexPath : 1;
-        unsigned int delegateDidSelectItemAtIndexPath : 1;
-        unsigned int delegateDidDeselectItemAtIndexPath : 1;
-        unsigned int delegateSupportsMenus : 1;
-        unsigned int delegateDidEndDisplayingCell : 1;
-        unsigned int delegateDidEndDisplayingSupplementaryView : 1;
-        unsigned int dataSourceNumberOfSections : 1;
-        unsigned int dataSourceViewForSupplementaryElement : 1;
-        unsigned int reloadSkippedDuringSuspension : 1;
-        unsigned int scheduledUpdateVisibleCells : 1;
-        unsigned int scheduledUpdateVisibleCellLayoutAttributes : 1;
-        unsigned int allowsSelection : 1;
-        unsigned int allowsMultipleSelection : 1;
-        unsigned int updating : 1;
-        unsigned int fadeCellsForBoundsChange : 1;
-        unsigned int updatingLayout : 1;
-        unsigned int needsReload : 1;
-        unsigned int reloading : 1;
-        unsigned int skipLayoutDuringSnapshotting : 1;
-        unsigned int layoutInvalidatedSinceLastCellUpdate : 1;
-        unsigned int doneFirstLayout : 1;
-    }_collectionViewFlags;
-    CGPoint _lastLayoutOffset;
-    char filler[232]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-@property (nonatomic, strong) PSTCollectionViewData *collectionViewData;
-@property (nonatomic, strong, readonly) PSTCollectionViewExt *extVars;
-@property (nonatomic, readonly) id currentUpdate;
-@property (nonatomic, readonly) NSDictionary *visibleViewsDict;
-@property (nonatomic, assign) CGRect visibleBoundRects;
-@end
-
-// Used by PSTCollectionView for external variables.
-// (We need to keep the total class size equal to the UICollectionView variant)
-@interface PSTCollectionViewExt : NSObject
-@property (nonatomic, unsafe_unretained) id<PSTCollectionViewDelegate> collectionViewDelegate;
-@property (nonatomic, strong) PSTCollectionViewLayout *nibLayout;
-@property (nonatomic, strong) NSDictionary *nibCellsExternalObjects;
-@property (nonatomic, strong) NSDictionary *supplementaryViewsExternalObjects;
-@property (nonatomic, strong) NSIndexPath *touchingIndexPath;
-@property (nonatomic, strong) NSIndexPath *currentIndexPath;
-@end
-
-@implementation PSTCollectionViewExt
-@end
-
-const char kPSTColletionViewExt;
-
-@implementation PSTCollectionView
-
-@synthesize collectionViewLayout = _layout;
-@synthesize currentUpdate = _update;
-@synthesize visibleViewsDict = _allVisibleViewsDict;
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-static void PSTCollectionViewCommonSetup(PSTCollectionView *_self) {
-    _self.allowsSelection = YES;
-    _self->_indexPathsForSelectedItems = [NSMutableSet new];
-    _self->_indexPathsForHighlightedItems = [NSMutableSet new];
-    _self->_cellReuseQueues = [NSMutableDictionary new];
-    _self->_supplementaryViewReuseQueues = [NSMutableDictionary new];
-    _self->_decorationViewReuseQueues = [NSMutableDictionary new];
-    _self->_allVisibleViewsDict = [NSMutableDictionary new];
-    _self->_cellClassDict = [NSMutableDictionary new];
-    _self->_cellNibDict = [NSMutableDictionary new];
-    _self->_supplementaryViewClassDict = [NSMutableDictionary new];
-    _self->_supplementaryViewNibDict = [NSMutableDictionary new];
-
-    // add class that saves additional ivars
-    objc_setAssociatedObject(_self, &kPSTColletionViewExt, [PSTCollectionViewExt new], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-}
-
-- (id)initWithFrame:(CGRect)frame {
-    return [self initWithFrame:frame collectionViewLayout:nil];
-}
-
-- (id)initWithFrame:(CGRect)frame collectionViewLayout:(PSTCollectionViewLayout *)layout {
-    if ((self = [super initWithFrame:frame])) {
-        // Set self as the UIScrollView's delegate
-        [super setDelegate:self];
-
-        PSTCollectionViewCommonSetup(self);
-        self.collectionViewLayout = layout;
-        _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)inCoder {
-    if ((self = [super initWithCoder:inCoder])) {
-        // Set self as the UIScrollView's delegate
-        [super setDelegate:self];
-
-        PSTCollectionViewCommonSetup(self);
-
-        self.extVars.nibLayout = [inCoder decodeObjectForKey:@"UICollectionLayout"];
-
-        NSDictionary *cellExternalObjects = [inCoder decodeObjectForKey:@"UICollectionViewCellPrototypeNibExternalObjects"];
-        NSDictionary *cellNibs = [inCoder decodeObjectForKey:@"UICollectionViewCellNibDict"];
-
-        for (NSString *identifier in cellNibs.allKeys) {
-            _cellNibDict[identifier] = cellNibs[identifier];
-        }
-
-        self.extVars.nibCellsExternalObjects = cellExternalObjects;
-
-        NSDictionary *supplementaryViewExternalObjects = [inCoder decodeObjectForKey:@"UICollectionViewSupplementaryViewPrototypeNibExternalObjects"];
-        NSDictionary *supplementaryViewNibs = [inCoder decodeObjectForKey:@"UICollectionViewSupplementaryViewNibDict"];
-
-        for (NSString *identifier in supplementaryViewNibs.allKeys) {
-            _supplementaryViewNibDict[identifier] = supplementaryViewNibs[identifier];
-        }
-
-        self.extVars.supplementaryViewsExternalObjects = supplementaryViewExternalObjects;
-    }
-    return self;
-}
-
-- (void)awakeFromNib {
-    [super awakeFromNib];
-
-    PSTCollectionViewLayout *nibLayout = self.extVars.nibLayout;
-    if (nibLayout) {
-        self.collectionViewLayout = nibLayout;
-        self.extVars.nibLayout = nil;
-    }
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"%@ collection view layout: %@", [super description], self.collectionViewLayout];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - UIView
-
-- (void)layoutSubviews {
-    [super layoutSubviews];
-
-    // Adding alpha animation to make the relayouting smooth
-    if (_collectionViewFlags.fadeCellsForBoundsChange) {
-        CATransition *transition = [CATransition animation];
-        transition.duration = 0.25f * PSTSimulatorAnimationDragCoefficient();
-        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
-        transition.type = kCATransitionFade;
-        [self.layer addAnimation:transition forKey:@"rotationAnimation"];
-    }
-
-    [_collectionViewData validateLayoutInRect:self.bounds];
-
-    // update cells
-    if (_collectionViewFlags.fadeCellsForBoundsChange) {
-        [CATransaction begin];
-        [CATransaction setDisableActions:YES];
-    }
-
-    if (!_collectionViewFlags.updatingLayout)
-        [self updateVisibleCellsNow:YES];
-
-    if (_collectionViewFlags.fadeCellsForBoundsChange) {
-        [CATransaction commit];
-    }
-
-    // do we need to update contentSize?
-    CGSize contentSize = [_collectionViewData collectionViewContentRect].size;
-    if (!CGSizeEqualToSize(self.contentSize, contentSize)) {
-        self.contentSize = contentSize;
-
-        // if contentSize is different, we need to re-evaluate layout, bounds (contentOffset) might changed
-        [_collectionViewData validateLayoutInRect:self.bounds];
-        [self updateVisibleCellsNow:YES];
-    }
-
-    if (_backgroundView) {
-        _backgroundView.frame = (CGRect){.origin=self.contentOffset, .size=self.bounds.size};
-    }
-
-    _collectionViewFlags.fadeCellsForBoundsChange = NO;
-    _collectionViewFlags.doneFirstLayout = YES;
-}
-
-- (void)setFrame:(CGRect)frame {
-    if (!CGRectEqualToRect(frame, self.frame)) {
-        CGRect bounds = (CGRect){.origin=self.contentOffset, .size=frame.size};
-        BOOL shouldInvalidate = [self.collectionViewLayout shouldInvalidateLayoutForBoundsChange:bounds];
-        [super setFrame:frame];
-        if (shouldInvalidate) {
-            [self invalidateLayout];
-            _collectionViewFlags.fadeCellsForBoundsChange = YES;
-        }
-    }
-}
-
-- (void)setBounds:(CGRect)bounds {
-    if (!CGRectEqualToRect(bounds, self.bounds)) {
-        BOOL shouldInvalidate = [self.collectionViewLayout shouldInvalidateLayoutForBoundsChange:bounds];
-        [super setBounds:bounds];
-        if (shouldInvalidate) {
-            [self invalidateLayout];
-            _collectionViewFlags.fadeCellsForBoundsChange = YES;
-        }
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - UIScrollViewDelegate
-
-- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
-        [delegate scrollViewDidScroll:scrollView];
-    }
-}
-
-- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidZoom:)]) {
-        [delegate scrollViewDidZoom:scrollView];
-    }
-}
-
-- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
-        [delegate scrollViewWillBeginDragging:scrollView];
-    }
-}
-
-- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
-    // Let collectionViewLayout decide where to stop.
-    *targetContentOffset = [[self collectionViewLayout] targetContentOffsetForProposedContentOffset:*targetContentOffset withScrollingVelocity:velocity];
-
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
-        //if collectionViewDelegate implements this method, it may modify targetContentOffset as well
-        [delegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
-    }
-}
-
-- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)]) {
-        [delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
-    }
-
-    // if we are in the middle of a cell touch event, perform the "touchEnded" simulation
-    if (self.extVars.touchingIndexPath) {
-        [self cellTouchCancelled];
-    }
-}
-
-- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)]) {
-        [delegate scrollViewWillBeginDecelerating:scrollView];
-    }
-}
-
-- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
-        [delegate scrollViewDidEndDecelerating:scrollView];
-    }
-}
-
-- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) {
-        [delegate scrollViewDidEndScrollingAnimation:scrollView];
-    }
-}
-
-- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(viewForZoomingInScrollView:)]) {
-        return [delegate viewForZoomingInScrollView:scrollView];
-    }
-    return nil;
-}
-
-- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) {
-        [delegate scrollViewWillBeginZooming:scrollView withView:view];
-    }
-}
-
-- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidEndZooming:withView:atScale:)]) {
-        [delegate scrollViewDidEndZooming:scrollView withView:view atScale:scale];
-    }
-}
-
-- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewShouldScrollToTop:)]) {
-        return [delegate scrollViewShouldScrollToTop:scrollView];
-    }
-    return YES;
-}
-
-- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
-    id<PSTCollectionViewDelegate> delegate = self.extVars.collectionViewDelegate;
-    if ((id)delegate != self && [delegate respondsToSelector:@selector(scrollViewDidScrollToTop:)]) {
-        [delegate scrollViewDidScrollToTop:scrollView];
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier {
-    NSParameterAssert(cellClass);
-    NSParameterAssert(identifier);
-    _cellClassDict[identifier] = cellClass;
-}
-
-- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier {
-    NSParameterAssert(viewClass);
-    NSParameterAssert(elementKind);
-    NSParameterAssert(identifier);
-    NSString *kindAndIdentifier = [NSString stringWithFormat:@"%@/%@", elementKind, identifier];
-    _supplementaryViewClassDict[kindAndIdentifier] = viewClass;
-}
-
-- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier {
-    NSArray *topLevelObjects = [nib instantiateWithOwner:nil options:nil];
-#pragma unused(topLevelObjects)
-    NSAssert(topLevelObjects.count == 1 && [topLevelObjects[0] isKindOfClass:PSTCollectionViewCell.class], @"must contain exactly 1 top level object which is a PSTCollectionViewCell");
-
-    _cellNibDict[identifier] = nib;
-}
-
-- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier {
-    NSArray *topLevelObjects = [nib instantiateWithOwner:nil options:nil];
-#pragma unused(topLevelObjects)
-    NSAssert(topLevelObjects.count == 1 && [topLevelObjects[0] isKindOfClass:PSTCollectionReusableView.class], @"must contain exactly 1 top level object which is a PSTCollectionReusableView");
-
-    NSString *kindAndIdentifier = [NSString stringWithFormat:@"%@/%@", kind, identifier];
-    _supplementaryViewNibDict[kindAndIdentifier] = nib;
-}
-
-- (id)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
-    // de-queue cell (if available)
-    NSMutableArray *reusableCells = _cellReuseQueues[identifier];
-    PSTCollectionViewCell *cell = [reusableCells lastObject];
-    PSTCollectionViewLayoutAttributes *attributes = [self.collectionViewLayout layoutAttributesForItemAtIndexPath:indexPath];
-
-    if (cell) {
-        [reusableCells removeObjectAtIndex:reusableCells.count - 1];
-    }else {
-        if (_cellNibDict[identifier]) {
-            // Cell was registered via registerNib:forCellWithReuseIdentifier:
-            UINib *cellNib = _cellNibDict[identifier];
-            NSDictionary *externalObjects = self.extVars.nibCellsExternalObjects[identifier];
-            if (externalObjects) {
-                cell = [cellNib instantiateWithOwner:self options:@{UINibExternalObjects : externalObjects}][0];
-            }else {
-                cell = [cellNib instantiateWithOwner:self options:nil][0];
-            }
-        }else {
-            Class cellClass = _cellClassDict[identifier];
-            // compatibility layer
-            Class collectionViewCellClass = NSClassFromString(@"UICollectionViewCell");
-            if (collectionViewCellClass && [cellClass isEqual:collectionViewCellClass]) {
-                cellClass = PSTCollectionViewCell.class;
-            }
-            if (cellClass == nil) {
-                @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"Class not registered for identifier %@", identifier] userInfo:nil];
-            }
-            if (attributes) {
-                cell = [[cellClass alloc] initWithFrame:attributes.frame];
-            }else {
-                cell = [cellClass new];
-            }
-        }
-        cell.collectionView = self;
-        cell.reuseIdentifier = identifier;
-    }
-
-    [cell applyLayoutAttributes:attributes];
-
-    return cell;
-}
-
-- (id)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
-    NSString *kindAndIdentifier = [NSString stringWithFormat:@"%@/%@", elementKind, identifier];
-    NSMutableArray *reusableViews = _supplementaryViewReuseQueues[kindAndIdentifier];
-    PSTCollectionReusableView *view = [reusableViews lastObject];
-    if (view) {
-        [reusableViews removeObjectAtIndex:reusableViews.count - 1];
-    }else {
-        if (_supplementaryViewNibDict[kindAndIdentifier]) {
-            // supplementary view was registered via registerNib:forCellWithReuseIdentifier:
-            UINib *supplementaryViewNib = _supplementaryViewNibDict[kindAndIdentifier];
-            NSDictionary *externalObjects = self.extVars.supplementaryViewsExternalObjects[kindAndIdentifier];
-            if (externalObjects) {
-                view = [supplementaryViewNib instantiateWithOwner:self options:@{UINibExternalObjects : externalObjects}][0];
-            }else {
-                view = [supplementaryViewNib instantiateWithOwner:self options:nil][0];
-            }
-        }else {
-            Class viewClass = _supplementaryViewClassDict[kindAndIdentifier];
-            Class reusableViewClass = NSClassFromString(@"UICollectionReusableView");
-            if (reusableViewClass && [viewClass isEqual:reusableViewClass]) {
-                viewClass = PSTCollectionReusableView.class;
-            }
-            if (viewClass == nil) {
-                @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"Class not registered for kind/identifier %@", kindAndIdentifier] userInfo:nil];
-            }
-            if (self.collectionViewLayout) {
-                PSTCollectionViewLayoutAttributes *attributes = [self.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:elementKind atIndexPath:indexPath];
-                if (attributes) {
-                    view = [[viewClass alloc] initWithFrame:attributes.frame];
-                }
-            }else {
-                view = [viewClass new];
-            }
-        }
-        view.collectionView = self;
-        view.reuseIdentifier = identifier;
-    }
-
-    return view;
-}
-
-- (id)dequeueReusableOrCreateDecorationViewOfKind:(NSString *)elementKind forIndexPath:(NSIndexPath *)indexPath {
-    NSMutableArray *reusableViews = _decorationViewReuseQueues[elementKind];
-    PSTCollectionReusableView *view = [reusableViews lastObject];
-    PSTCollectionViewLayout *collectionViewLayout = self.collectionViewLayout;
-    PSTCollectionViewLayoutAttributes *attributes = [collectionViewLayout layoutAttributesForDecorationViewOfKind:elementKind atIndexPath:indexPath];
-
-    if (view) {
-        [reusableViews removeObjectAtIndex:reusableViews.count - 1];
-    }else {
-        NSDictionary *decorationViewNibDict = collectionViewLayout.decorationViewNibDict;
-        NSDictionary *decorationViewExternalObjects = collectionViewLayout.decorationViewExternalObjectsTables;
-        if (decorationViewNibDict[elementKind]) {
-            // supplementary view was registered via registerNib:forCellWithReuseIdentifier:
-            UINib *supplementaryViewNib = decorationViewNibDict[elementKind];
-            NSDictionary *externalObjects = decorationViewExternalObjects[elementKind];
-            if (externalObjects) {
-                view = [supplementaryViewNib instantiateWithOwner:self options:@{UINibExternalObjects : externalObjects}][0];
-            }else {
-                view = [supplementaryViewNib instantiateWithOwner:self options:nil][0];
-            }
-        }else {
-            NSDictionary *decorationViewClassDict = collectionViewLayout.decorationViewClassDict;
-            Class viewClass = decorationViewClassDict[elementKind];
-            Class reusableViewClass = NSClassFromString(@"UICollectionReusableView");
-            if (reusableViewClass && [viewClass isEqual:reusableViewClass]) {
-                viewClass = PSTCollectionReusableView.class;
-            }
-            if (viewClass == nil) {
-                @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"Class not registered for identifier %@", elementKind] userInfo:nil];
-            }
-            if (attributes) {
-                view = [[viewClass alloc] initWithFrame:attributes.frame];
-            }else {
-                view = [viewClass new];
-            }
-        }
-        view.collectionView = self;
-        view.reuseIdentifier = elementKind;
-    }
-
-    [view applyLayoutAttributes:attributes];
-
-    return view;
-}
-
-- (NSArray *)allCells {
-    return [[_allVisibleViewsDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
-        return [evaluatedObject isKindOfClass:PSTCollectionViewCell.class];
-    }]];
-}
-
-- (NSArray *)visibleCells {
-    return [[_allVisibleViewsDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
-        return [evaluatedObject isKindOfClass:PSTCollectionViewCell.class] && CGRectIntersectsRect(self.bounds, [evaluatedObject frame]);
-    }]];
-}
-
-- (void)reloadData {
-    if (_reloadingSuspendedCount != 0) return;
-    [self invalidateLayout];
-    [_allVisibleViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
-        if ([obj isKindOfClass:UIView.class]) {
-            [obj removeFromSuperview];
-        }
-    }];
-    [_allVisibleViewsDict removeAllObjects];
-
-    for (NSIndexPath *indexPath in _indexPathsForSelectedItems) {
-        PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath:indexPath];
-        selectedCell.selected = NO;
-        selectedCell.highlighted = NO;
-    }
-    [_indexPathsForSelectedItems removeAllObjects];
-    [_indexPathsForHighlightedItems removeAllObjects];
-
-    [self setNeedsLayout];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Query Grid
-
-- (NSInteger)numberOfSections {
-    return [_collectionViewData numberOfSections];
-}
-
-- (NSInteger)numberOfItemsInSection:(NSInteger)section {
-    return [_collectionViewData numberOfItemsInSection:section];
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
-    return [[self collectionViewLayout] layoutAttributesForItemAtIndexPath:indexPath];
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
-    return [[self collectionViewLayout] layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath];
-}
-
-- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point {
-    PSTCollectionViewLayoutAttributes *attributes = [[self.collectionViewLayout layoutAttributesForElementsInRect:CGRectMake(point.x, point.y, 1, 1)] lastObject];
-    return attributes.indexPath;
-}
-
-- (NSIndexPath *)indexPathForCell:(PSTCollectionViewCell *)cell {
-    __block NSIndexPath *indexPath = nil;
-    [_allVisibleViewsDict enumerateKeysAndObjectsWithOptions:kNilOptions usingBlock:^(id key, id obj, BOOL *stop) {
-        PSTCollectionViewItemKey *itemKey = (PSTCollectionViewItemKey *)key;
-        if (itemKey.type == PSTCollectionViewItemTypeCell) {
-            PSTCollectionViewCell *currentCell = (PSTCollectionViewCell *)obj;
-            if (currentCell == cell) {
-                indexPath = itemKey.indexPath;
-                *stop = YES;
-            }
-        }
-    }];
-    return indexPath;
-}
-
-- (PSTCollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-    // NSInteger index = [_collectionViewData globalIndexForItemAtIndexPath:indexPath];
-    // TODO Apple uses some kind of globalIndex for this.
-    __block PSTCollectionViewCell *cell = nil;
-    [_allVisibleViewsDict enumerateKeysAndObjectsWithOptions:0 usingBlock:^(id key, id obj, BOOL *stop) {
-        PSTCollectionViewItemKey *itemKey = (PSTCollectionViewItemKey *)key;
-        if (itemKey.type == PSTCollectionViewItemTypeCell) {
-            if ([itemKey.indexPath isEqual:indexPath]) {
-                cell = obj;
-                *stop = YES;
-            }
-        }
-    }];
-    return cell;
-}
-
-- (NSArray *)indexPathsForVisibleItems {
-    NSArray *visibleCells = self.visibleCells;
-    NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:visibleCells.count];
-
-    [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
-        PSTCollectionViewCell *cell = (PSTCollectionViewCell *)obj;
-        [indexPaths addObject:cell.layoutAttributes.indexPath];
-    }];
-
-    return indexPaths;
-}
-
-// returns nil or an array of selected index paths
-- (NSArray *)indexPathsForSelectedItems {
-    return [_indexPathsForSelectedItems allObjects];
-}
-
-// Interacting with the collection view.
-- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(PSTCollectionViewScrollPosition)scrollPosition animated:(BOOL)animated {
-    // Ensure grid is laid out; else we can't scroll.
-    [self layoutSubviews];
-
-    PSTCollectionViewLayoutAttributes *layoutAttributes = [self.collectionViewLayout layoutAttributesForItemAtIndexPath:indexPath];
-    if (layoutAttributes) {
-        CGRect targetRect = [self makeRect:layoutAttributes.frame toScrollPosition:scrollPosition];
-        [self scrollRectToVisible:targetRect animated:animated];
-    }
-}
-
-- (CGRect)makeRect:(CGRect)targetRect toScrollPosition:(PSTCollectionViewScrollPosition)scrollPosition {
-    // split parameters
-    NSUInteger verticalPosition = scrollPosition&0x07; // 0000 0111
-    NSUInteger horizontalPosition = scrollPosition&0x38; // 0011 1000
-
-    if (verticalPosition != PSTCollectionViewScrollPositionNone
-            && verticalPosition != PSTCollectionViewScrollPositionTop
-            && verticalPosition != PSTCollectionViewScrollPositionCenteredVertically
-            && verticalPosition != PSTCollectionViewScrollPositionBottom) {
-        @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"PSTCollectionViewScrollPosition: attempt to use a scroll position with multiple vertical positioning styles" userInfo:nil];
-    }
-
-    if (horizontalPosition != PSTCollectionViewScrollPositionNone
-            && horizontalPosition != PSTCollectionViewScrollPositionLeft
-            && horizontalPosition != PSTCollectionViewScrollPositionCenteredHorizontally
-            && horizontalPosition != PSTCollectionViewScrollPositionRight) {
-        @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"PSTCollectionViewScrollPosition: attempt to use a scroll position with multiple horizontal positioning styles" userInfo:nil];
-    }
-
-    CGRect frame = self.layer.bounds;
-    CGFloat calculateX;
-    CGFloat calculateY;
-
-    switch (verticalPosition) {
-        case PSTCollectionViewScrollPositionCenteredVertically:
-            calculateY = fmax(targetRect.origin.y - ((frame.size.height / 2) - (targetRect.size.height / 2)), -self.contentInset.top);
-            targetRect = CGRectMake(targetRect.origin.x, calculateY, targetRect.size.width, frame.size.height);
-            break;
-        case PSTCollectionViewScrollPositionTop:
-            targetRect = CGRectMake(targetRect.origin.x, targetRect.origin.y, targetRect.size.width, frame.size.height);
-            break;
-
-        case PSTCollectionViewScrollPositionBottom:
-            calculateY = fmax(targetRect.origin.y - (frame.size.height - targetRect.size.height), -self.contentInset.top);
-            targetRect = CGRectMake(targetRect.origin.x, calculateY, targetRect.size.width, frame.size.height);
-            break;
-    }
-
-    switch (horizontalPosition) {
-        case PSTCollectionViewScrollPositionCenteredHorizontally:
-            calculateX = targetRect.origin.x - ((frame.size.width / 2) - (targetRect.size.width / 2));
-            targetRect = CGRectMake(calculateX, targetRect.origin.y, frame.size.width, targetRect.size.height);
-            break;
-
-        case PSTCollectionViewScrollPositionLeft:
-            targetRect = CGRectMake(targetRect.origin.x, targetRect.origin.y, frame.size.width, targetRect.size.height);
-            break;
-
-        case PSTCollectionViewScrollPositionRight:
-            calculateX = targetRect.origin.x - (frame.size.width - targetRect.size.width);
-            targetRect = CGRectMake(calculateX, targetRect.origin.y, frame.size.width, targetRect.size.height);
-            break;
-    }
-
-    return targetRect;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Touch Handling
-
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
-    [super touchesBegan:touches withEvent:event];
-
-    // reset touching state vars
-    self.extVars.touchingIndexPath = nil;
-    self.extVars.currentIndexPath = nil;
-
-    CGPoint touchPoint = [[touches anyObject] locationInView:self];
-    NSIndexPath *indexPath = [self indexPathForItemAtPoint:touchPoint];
-    if (indexPath && self.allowsSelection) {
-        if (![self highlightItemAtIndexPath:indexPath animated:YES scrollPosition:PSTCollectionViewScrollPositionNone notifyDelegate:YES])
-            return;
-
-        self.extVars.touchingIndexPath = indexPath;
-        self.extVars.currentIndexPath = indexPath;
-
-        if (!self.allowsMultipleSelection) {
-            // temporally unhighlight background on touchesBegan (keeps selected by _indexPathsForSelectedItems)
-            // single-select only mode only though
-            NSIndexPath *tempDeselectIndexPath = _indexPathsForSelectedItems.anyObject;
-            if (tempDeselectIndexPath && ![tempDeselectIndexPath isEqual:self.extVars.touchingIndexPath]) {
-                // iOS6 UICollectionView deselects cell without notification
-                PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath:tempDeselectIndexPath];
-                selectedCell.selected = NO;
-            }
-        }
-    }
-}
-
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
-    [super touchesMoved:touches withEvent:event];
-
-    // allows moving between highlight and unhighlight state only if setHighlighted is not overwritten
-    if (self.extVars.touchingIndexPath) {
-        CGPoint touchPoint = [[touches anyObject] locationInView:self];
-        NSIndexPath *indexPath = [self indexPathForItemAtPoint:touchPoint];
-
-        // moving out of bounds
-        if ([self.extVars.currentIndexPath isEqual:self.extVars.touchingIndexPath] &&
-                ![indexPath isEqual:self.extVars.touchingIndexPath] &&
-                [self unhighlightItemAtIndexPath:self.extVars.touchingIndexPath animated:YES notifyDelegate:YES shouldCheckHighlight:YES]) {
-            self.extVars.currentIndexPath = indexPath;
-            // moving back into the original touching cell
-        }else if (![self.extVars.currentIndexPath isEqual:self.extVars.touchingIndexPath] &&
-                [indexPath isEqual:self.extVars.touchingIndexPath]) {
-            [self highlightItemAtIndexPath:self.extVars.touchingIndexPath animated:YES scrollPosition:PSTCollectionViewScrollPositionNone notifyDelegate:YES];
-            self.extVars.currentIndexPath = self.extVars.touchingIndexPath;
-        }
-    }
-}
-
-- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
-    [super touchesEnded:touches withEvent:event];
-
-    if (self.extVars.touchingIndexPath) {
-        // first unhighlight the touch operation
-        [self unhighlightItemAtIndexPath:self.extVars.touchingIndexPath animated:YES notifyDelegate:YES];
-
-        CGPoint touchPoint = [[touches anyObject] locationInView:self];
-        NSIndexPath *indexPath = [self indexPathForItemAtPoint:touchPoint];
-        if ([indexPath isEqual:self.extVars.touchingIndexPath]) {
-            [self userSelectedItemAtIndexPath:indexPath];
-        }
-        else if (!self.allowsMultipleSelection) {
-            NSIndexPath *tempDeselectIndexPath = _indexPathsForSelectedItems.anyObject;
-            if (tempDeselectIndexPath && ![tempDeselectIndexPath isEqual:self.extVars.touchingIndexPath]) {
-                [self cellTouchCancelled];
-            }
-        }
-
-        // for pedantic reasons only - always set to nil on touchesBegan
-        self.extVars.touchingIndexPath = nil;
-        self.extVars.currentIndexPath = nil;
-    }
-}
-
-- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
-    [super touchesCancelled:touches withEvent:event];
-
-    // do not mark touchingIndexPath as nil because whoever cancelled this touch will need to signal a touch up event later
-    if (self.extVars.touchingIndexPath) {
-        // first unhighlight the touch operation
-        [self unhighlightItemAtIndexPath:self.extVars.touchingIndexPath animated:YES notifyDelegate:YES];
-    }
-}
-
-- (void)cellTouchCancelled {
-    // turn on ALL the *should be selected* cells (iOS6 UICollectionView does no state keeping or other fancy optimizations)
-    // there should be no notifications as this is a silent "turn everything back on"
-    for (NSIndexPath *tempDeselectedIndexPath in [_indexPathsForSelectedItems copy]) {
-        PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath:tempDeselectedIndexPath];
-        selectedCell.selected = YES;
-    }
-}
-
-- (void)userSelectedItemAtIndexPath:(NSIndexPath *)indexPath {
-    if (self.allowsMultipleSelection && [_indexPathsForSelectedItems containsObject:indexPath]) {
-        [self deselectItemAtIndexPath:indexPath animated:YES notifyDelegate:YES];
-    }
-    else if (self.allowsSelection) {
-        [self selectItemAtIndexPath:indexPath animated:YES scrollPosition:PSTCollectionViewScrollPositionNone notifyDelegate:YES];
-    }
-}
-
-// select item, notify delegate (internal)
-- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition notifyDelegate:(BOOL)notifyDelegate {
-    if (self.allowsMultipleSelection && [_indexPathsForSelectedItems containsObject:indexPath]) {
-        BOOL shouldDeselect = YES;
-        if (notifyDelegate && _collectionViewFlags.delegateShouldDeselectItemAtIndexPath) {
-            shouldDeselect = [self.delegate collectionView:self shouldDeselectItemAtIndexPath:indexPath];
-        }
-
-        if (shouldDeselect) {
-            [self deselectItemAtIndexPath:indexPath animated:animated notifyDelegate:notifyDelegate];
-        }
-    }
-    else {
-        // either single selection, or wasn't already selected in multiple selection mode
-        BOOL shouldSelect = YES;
-        if (notifyDelegate && _collectionViewFlags.delegateShouldSelectItemAtIndexPath) {
-            shouldSelect = [self.delegate collectionView:self shouldSelectItemAtIndexPath:indexPath];
-        }
-
-        if (!self.allowsMultipleSelection) {
-            // now unselect the previously selected cell for single selection
-            NSIndexPath *tempDeselectIndexPath = _indexPathsForSelectedItems.anyObject;
-            if (tempDeselectIndexPath && ![tempDeselectIndexPath isEqual:indexPath]) {
-                [self deselectItemAtIndexPath:tempDeselectIndexPath animated:YES notifyDelegate:YES];
-            }
-        }
-
-        if (shouldSelect) {
-            PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath:indexPath];
-            selectedCell.selected = YES;
-
-            [_indexPathsForSelectedItems addObject:indexPath];
-
-            [selectedCell performSelectionSegue];
-
-            if (scrollPosition != PSTCollectionViewScrollPositionNone) {
-                [self scrollToItemAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
-            }
-
-            if (notifyDelegate && _collectionViewFlags.delegateDidSelectItemAtIndexPath) {
-                [self.delegate collectionView:self didSelectItemAtIndexPath:indexPath];
-            }
-        }
-    }
-}
-
-- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition {
-    [self selectItemAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition notifyDelegate:NO];
-}
-
-- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated {
-    [self deselectItemAtIndexPath:indexPath animated:animated notifyDelegate:NO];
-}
-
-- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate {
-    BOOL shouldDeselect = YES;
-    // deselect only relevant during multi mode
-    if (self.allowsMultipleSelection && notifyDelegate && _collectionViewFlags.delegateShouldDeselectItemAtIndexPath) {
-        shouldDeselect = [self.delegate collectionView:self shouldDeselectItemAtIndexPath:indexPath];
-    }
-
-    if (shouldDeselect && [_indexPathsForSelectedItems containsObject:indexPath]) {
-        PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath:indexPath];
-        if (selectedCell) {
-            if (selectedCell.selected) {
-                selectedCell.selected = NO;
-            }
-        }
-        [_indexPathsForSelectedItems removeObject:indexPath];
-
-        if (notifyDelegate && _collectionViewFlags.delegateDidDeselectItemAtIndexPath) {
-            [self.delegate collectionView:self didDeselectItemAtIndexPath:indexPath];
-        }
-    }
-}
-
-- (BOOL)highlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(PSTCollectionViewScrollPosition)scrollPosition notifyDelegate:(BOOL)notifyDelegate {
-    BOOL shouldHighlight = YES;
-    if (notifyDelegate && _collectionViewFlags.delegateShouldHighlightItemAtIndexPath) {
-        shouldHighlight = [self.delegate collectionView:self shouldHighlightItemAtIndexPath:indexPath];
-    }
-
-    if (shouldHighlight) {
-        PSTCollectionViewCell *highlightedCell = [self cellForItemAtIndexPath:indexPath];
-        highlightedCell.highlighted = YES;
-        [_indexPathsForHighlightedItems addObject:indexPath];
-
-        if (scrollPosition != PSTCollectionViewScrollPositionNone) {
-            [self scrollToItemAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
-        }
-
-        if (notifyDelegate && _collectionViewFlags.delegateDidHighlightItemAtIndexPath) {
-            [self.delegate collectionView:self didHighlightItemAtIndexPath:indexPath];
-        }
-    }
-    return shouldHighlight;
-}
-
-- (BOOL)unhighlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate {
-    return [self unhighlightItemAtIndexPath:indexPath animated:animated notifyDelegate:notifyDelegate shouldCheckHighlight:NO];
-}
-
-- (BOOL)unhighlightItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate shouldCheckHighlight:(BOOL)check {
-    if ([_indexPathsForHighlightedItems containsObject:indexPath]) {
-        PSTCollectionViewCell *highlightedCell = [self cellForItemAtIndexPath:indexPath];
-        // iOS6 does not notify any delegate if the cell was never highlighted (setHighlighted overwritten) during touchMoved
-        if (check && !highlightedCell.highlighted) {
-            return NO;
-        }
-
-        // if multiple selection or not unhighlighting a selected item we don't perform any op
-        if (highlightedCell.highlighted && [_indexPathsForSelectedItems containsObject:indexPath]) {
-            highlightedCell.highlighted = YES;
-        }else {
-            highlightedCell.highlighted = NO;
-        }
-
-        [_indexPathsForHighlightedItems removeObject:indexPath];
-
-        if (notifyDelegate && _collectionViewFlags.delegateDidUnhighlightItemAtIndexPath) {
-            [self.delegate collectionView:self didUnhighlightItemAtIndexPath:indexPath];
-        }
-
-        return YES;
-    }
-    return NO;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Update Grid
-
-- (void)insertSections:(NSIndexSet *)sections {
-    [self updateSections:sections updateAction:PSTCollectionUpdateActionInsert];
-}
-
-- (void)deleteSections:(NSIndexSet *)sections {
-    // First delete all items
-    NSMutableArray *paths = [NSMutableArray new];
-    [sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
-        for (int i = 0; i < [self numberOfItemsInSection:(NSInteger)idx]; ++i) {
-            [paths addObject:[NSIndexPath indexPathForItem:i inSection:(NSInteger)idx]];
-        }
-    }];
-    [self deleteItemsAtIndexPaths:paths];
-    // Then delete the section.
-    [self updateSections:sections updateAction:PSTCollectionUpdateActionDelete];
-}
-
-- (void)reloadSections:(NSIndexSet *)sections {
-    [self updateSections:sections updateAction:PSTCollectionUpdateActionReload];
-}
-
-- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection {
-    NSMutableArray *moveUpdateItems = [self arrayForUpdateAction:PSTCollectionUpdateActionMove];
-    [moveUpdateItems addObject:
-            [[PSTCollectionViewUpdateItem alloc] initWithInitialIndexPath:[NSIndexPath indexPathForItem:NSNotFound inSection:section]
-                    finalIndexPath:[NSIndexPath indexPathForItem:NSNotFound inSection:newSection]
-                    updateAction:PSTCollectionUpdateActionMove]];
-    if (!_collectionViewFlags.updating) {
-        [self setupCellAnimations];
-        [self endItemAnimations];
-    }
-}
-
-- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths {
-    [self updateRowsAtIndexPaths:indexPaths updateAction:PSTCollectionUpdateActionInsert];
-}
-
-- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths {
-    [self updateRowsAtIndexPaths:indexPaths updateAction:PSTCollectionUpdateActionDelete];
-
-}
-
-- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths {
-    [self updateRowsAtIndexPaths:indexPaths updateAction:PSTCollectionUpdateActionReload];
-}
-
-- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath {
-    NSMutableArray *moveUpdateItems = [self arrayForUpdateAction:PSTCollectionUpdateActionMove];
-    [moveUpdateItems addObject:
-            [[PSTCollectionViewUpdateItem alloc] initWithInitialIndexPath:indexPath
-                    finalIndexPath:newIndexPath
-                    updateAction:PSTCollectionUpdateActionMove]];
-    if (!_collectionViewFlags.updating) {
-        [self setupCellAnimations];
-        [self endItemAnimations];
-    }
-}
-
-- (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion {
-    [self setupCellAnimations];
-
-    if (updates) updates();
-    if (completion) _updateCompletionHandler = completion;
-
-    [self endItemAnimations];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Properties
-
-- (void)setBackgroundView:(UIView *)backgroundView {
-    if (backgroundView != _backgroundView) {
-        [_backgroundView removeFromSuperview];
-        _backgroundView = backgroundView;
-        backgroundView.frame = (CGRect){.origin=self.contentOffset, .size=self.bounds.size};
-        backgroundView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
-        [self addSubview:backgroundView];
-        [self sendSubviewToBack:backgroundView];
-    }
-}
-
-- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout animated:(BOOL)animated {
-    if (layout == _layout) return;
-
-    // not sure it was it original code, but here this prevents crash
-    // in case we switch layout before previous one was initially loaded
-    if (CGRectIsEmpty(self.bounds) || !_collectionViewFlags.doneFirstLayout) {
-        _layout.collectionView = nil;
-        _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
-        layout.collectionView = self;
-        _layout = layout;
-
-        // originally the use method
-        // _setNeedsVisibleCellsUpdate:withLayoutAttributes:
-        // here with CellsUpdate set to YES and LayoutAttributes parameter set to NO
-        // inside this method probably some flags are set and finally
-        // setNeedsDisplay is called
-
-        _collectionViewFlags.scheduledUpdateVisibleCells = YES;
-        _collectionViewFlags.scheduledUpdateVisibleCellLayoutAttributes = NO;
-
-        [self setNeedsDisplay];
-    }
-    else {
-        layout.collectionView = self;
-        
-        _layout.collectionView = nil;
-        _layout = layout;
-
-        _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:layout];
-        [_collectionViewData prepareToLoadData];
-
-        NSArray *previouslySelectedIndexPaths = [self indexPathsForSelectedItems];
-        NSMutableSet *selectedCellKeys = [NSMutableSet setWithCapacity:previouslySelectedIndexPaths.count];
-
-        for (NSIndexPath *indexPath in previouslySelectedIndexPaths) {
-            [selectedCellKeys addObject:[PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPath]];
-        }
-
-        NSArray *previouslyVisibleItemsKeys = [_allVisibleViewsDict allKeys];
-        NSSet *previouslyVisibleItemsKeysSet = [NSSet setWithArray:previouslyVisibleItemsKeys];
-        NSMutableSet *previouslyVisibleItemsKeysSetMutable = [NSMutableSet setWithArray:previouslyVisibleItemsKeys];
-
-        if ([selectedCellKeys intersectsSet:selectedCellKeys]) {
-            [previouslyVisibleItemsKeysSetMutable intersectSet:previouslyVisibleItemsKeysSetMutable];
-        }
-
-        [self bringSubviewToFront:_allVisibleViewsDict[[previouslyVisibleItemsKeysSetMutable anyObject]]];
-
-        CGPoint targetOffset = self.contentOffset;
-        CGPoint centerPoint = CGPointMake(self.bounds.origin.x + self.bounds.size.width / 2.f,
-                self.bounds.origin.y + self.bounds.size.height / 2.f);
-        NSIndexPath *centerItemIndexPath = [self indexPathForItemAtPoint:centerPoint];
-
-        if (!centerItemIndexPath) {
-            NSArray *visibleItems = [self indexPathsForVisibleItems];
-            if (visibleItems.count > 0) {
-                centerItemIndexPath = visibleItems[visibleItems.count / 2];
-            }
-        }
-
-        if (centerItemIndexPath) {
-            PSTCollectionViewLayoutAttributes *layoutAttributes = [layout layoutAttributesForItemAtIndexPath:centerItemIndexPath];
-            if (layoutAttributes) {
-                PSTCollectionViewScrollPosition scrollPosition = PSTCollectionViewScrollPositionCenteredVertically|PSTCollectionViewScrollPositionCenteredHorizontally;
-                CGRect targetRect = [self makeRect:layoutAttributes.frame toScrollPosition:scrollPosition];
-                targetOffset = CGPointMake(fmax(0.f, targetRect.origin.x), fmax(0.f, targetRect.origin.y));
-            }
-        }
-
-        CGRect newlyBounds = CGRectMake(targetOffset.x, targetOffset.y, self.bounds.size.width, self.bounds.size.height);
-        NSArray *newlyVisibleLayoutAttrs = [_collectionViewData layoutAttributesForElementsInRect:newlyBounds];
-
-        NSMutableDictionary *layoutInterchangeData = [NSMutableDictionary dictionaryWithCapacity:
-                newlyVisibleLayoutAttrs.count + previouslyVisibleItemsKeysSet.count];
-
-        NSMutableSet *newlyVisibleItemsKeys = [NSMutableSet set];
-        for (PSTCollectionViewLayoutAttributes *attr in newlyVisibleLayoutAttrs) {
-            PSTCollectionViewItemKey *newKey = [PSTCollectionViewItemKey collectionItemKeyForLayoutAttributes:attr];
-            [newlyVisibleItemsKeys addObject:newKey];
-
-            PSTCollectionViewLayoutAttributes *prevAttr = nil;
-            PSTCollectionViewLayoutAttributes *newAttr = nil;
-
-            if (newKey.type == PSTCollectionViewItemTypeDecorationView) {
-                prevAttr = [self.collectionViewLayout layoutAttributesForDecorationViewOfKind:attr.representedElementKind
-                        atIndexPath:newKey.indexPath];
-                newAttr = [layout layoutAttributesForDecorationViewOfKind:attr.representedElementKind
-                        atIndexPath:newKey.indexPath];
-            }
-            else if (newKey.type == PSTCollectionViewItemTypeCell) {
-                prevAttr = [self.collectionViewLayout layoutAttributesForItemAtIndexPath:newKey.indexPath];
-                newAttr = [layout layoutAttributesForItemAtIndexPath:newKey.indexPath];
-            }
-            else {
-                prevAttr = [self.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:attr.representedElementKind
-                        atIndexPath:newKey.indexPath];
-                newAttr = [layout layoutAttributesForSupplementaryViewOfKind:attr.representedElementKind
-                        atIndexPath:newKey.indexPath];
-            }
-
-            if (prevAttr != nil && newAttr != nil) {
-                layoutInterchangeData[newKey] = @{@"previousLayoutInfos": prevAttr, @"newLayoutInfos": newAttr};
-            }
-        }
-
-        for (PSTCollectionViewItemKey *key in previouslyVisibleItemsKeysSet) {
-            PSTCollectionViewLayoutAttributes *prevAttr = nil;
-            PSTCollectionViewLayoutAttributes *newAttr = nil;
-
-            if (key.type == PSTCollectionViewItemTypeDecorationView) {
-                PSTCollectionReusableView *decorView = _allVisibleViewsDict[key];
-                prevAttr = [self.collectionViewLayout layoutAttributesForDecorationViewOfKind:decorView.reuseIdentifier
-                        atIndexPath:key.indexPath];
-                newAttr = [layout layoutAttributesForDecorationViewOfKind:decorView.reuseIdentifier
-                        atIndexPath:key.indexPath];
-            }
-            else if (key.type == PSTCollectionViewItemTypeCell) {
-                prevAttr = [self.collectionViewLayout layoutAttributesForItemAtIndexPath:key.indexPath];
-                newAttr = [layout layoutAttributesForItemAtIndexPath:key.indexPath];
-            }
-            else if (key.type == PSTCollectionViewItemTypeSupplementaryView) {
-                PSTCollectionReusableView *suuplView = _allVisibleViewsDict[key];
-                prevAttr = [self.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:suuplView.layoutAttributes.representedElementKind
-                        atIndexPath:key.indexPath];
-                newAttr = [layout layoutAttributesForSupplementaryViewOfKind:suuplView.layoutAttributes.representedElementKind
-                        atIndexPath:key.indexPath];
-            }
-
-            NSMutableDictionary *layoutInterchangeDataValue = [NSMutableDictionary dictionary];
-            if (prevAttr) layoutInterchangeDataValue[@"previousLayoutInfos"] = prevAttr;
-            if (newAttr) layoutInterchangeDataValue[@"newLayoutInfos"] = newAttr;
-            layoutInterchangeData[key] = layoutInterchangeDataValue;
-        }
-
-        for (PSTCollectionViewItemKey *key in [layoutInterchangeData keyEnumerator]) {
-            if (key.type == PSTCollectionViewItemTypeCell) {
-                PSTCollectionViewCell *cell = _allVisibleViewsDict[key];
-
-                if (!cell) {
-                    cell = [self createPreparedCellForItemAtIndexPath:key.indexPath
-                            withLayoutAttributes:layoutInterchangeData[key][@"previousLayoutInfos"]];
-                    _allVisibleViewsDict[key] = cell;
-                    [self addControlledSubview:cell];
-                }
-                else [cell applyLayoutAttributes:layoutInterchangeData[key][@"previousLayoutInfos"]];
-            }
-            else if (key.type == PSTCollectionViewItemTypeSupplementaryView) {
-                PSTCollectionReusableView *view = _allVisibleViewsDict[key];
-                if (!view) {
-                    PSTCollectionViewLayoutAttributes *attrs = layoutInterchangeData[key][@"previousLayoutInfos"];
-                    view = [self createPreparedSupplementaryViewForElementOfKind:attrs.representedElementKind
-                            atIndexPath:attrs.indexPath
-                            withLayoutAttributes:attrs];
-                    _allVisibleViewsDict[key] = view;
-                    [self addControlledSubview:view];
-                }
-            }
-            else if (key.type == PSTCollectionViewItemTypeDecorationView) {
-                PSTCollectionReusableView *view = _allVisibleViewsDict[key];
-                if (!view) {
-                    PSTCollectionViewLayoutAttributes *attrs = layoutInterchangeData[key][@"previousLayoutInfos"];
-                    view = [self dequeueReusableOrCreateDecorationViewOfKind:attrs.representedElementKind forIndexPath:attrs.indexPath];
-                    _allVisibleViewsDict[key] = view;
-                    [self addControlledSubview:view];
-                }
-            }
-        };
-
-        CGRect contentRect = [_collectionViewData collectionViewContentRect];
-
-        void (^applyNewLayoutBlock)(void) = ^{
-            NSEnumerator *keys = [layoutInterchangeData keyEnumerator];
-            for (PSTCollectionViewItemKey *key in keys) {
-                // TODO: This is most likely not 100% the same time as in UICollectionView. Needs to be investigated.
-                PSTCollectionViewCell *cell = (PSTCollectionViewCell *)_allVisibleViewsDict[key];
-                [cell willTransitionFromLayout:_layout toLayout:layout];
-                [cell applyLayoutAttributes:layoutInterchangeData[key][@"newLayoutInfos"]];
-                [cell didTransitionFromLayout:_layout toLayout:layout];
-            }
-        };
-
-        void (^freeUnusedViews)(void) = ^{
-            NSMutableSet *toRemove = [NSMutableSet set];
-            for (PSTCollectionViewItemKey *key in [_allVisibleViewsDict keyEnumerator]) {
-                if (![newlyVisibleItemsKeys containsObject:key]) {
-                    if (key.type == PSTCollectionViewItemTypeCell) {
-                        [self reuseCell:_allVisibleViewsDict[key]];
-                        [toRemove addObject:key];
-                    }
-                    else if (key.type == PSTCollectionViewItemTypeSupplementaryView) {
-                        [self reuseSupplementaryView:_allVisibleViewsDict[key]];
-                        [toRemove addObject:key];
-                    }
-                    else if (key.type == PSTCollectionViewItemTypeDecorationView) {
-                        [self reuseDecorationView:_allVisibleViewsDict[key]];
-                        [toRemove addObject:key];
-                    }
-                }
-            }
-
-            for (id key in toRemove)
-                [_allVisibleViewsDict removeObjectForKey:key];
-        };
-
-        if (animated) {
-            [UIView animateWithDuration:.3 animations:^{
-                _collectionViewFlags.updatingLayout = YES;
-                self.contentOffset = targetOffset;
-                self.contentSize = contentRect.size;
-                applyNewLayoutBlock();
-            } completion:^(BOOL finished) {
-                freeUnusedViews();
-                _collectionViewFlags.updatingLayout = NO;
-
-                // layout subviews for updating content offset or size while updating layout
-                if (!CGPointEqualToPoint(self.contentOffset, targetOffset)
-                        || !CGSizeEqualToSize(self.contentSize, contentRect.size)) {
-                    [self layoutSubviews];
-                }
-            }];
-        }
-        else {
-            self.contentOffset = targetOffset;
-            self.contentSize = contentRect.size;
-            applyNewLayoutBlock();
-            freeUnusedViews();
-        }
-    }
-}
-
-- (void)setCollectionViewLayout:(PSTCollectionViewLayout *)layout {
-    [self setCollectionViewLayout:layout animated:NO];
-}
-
-- (id<PSTCollectionViewDelegate>)delegate {
-    return self.extVars.collectionViewDelegate;
-}
-
-- (void)setDelegate:(id<PSTCollectionViewDelegate>)delegate {
-    self.extVars.collectionViewDelegate = delegate;
-
-    //  Managing the Selected Cells
-    _collectionViewFlags.delegateShouldSelectItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:shouldSelectItemAtIndexPath:)];
-    _collectionViewFlags.delegateDidSelectItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didSelectItemAtIndexPath:)];
-    _collectionViewFlags.delegateShouldDeselectItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:shouldDeselectItemAtIndexPath:)];
-    _collectionViewFlags.delegateDidDeselectItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didDeselectItemAtIndexPath:)];
-
-    //  Managing Cell Highlighting
-    _collectionViewFlags.delegateShouldHighlightItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:shouldHighlightItemAtIndexPath:)];
-    _collectionViewFlags.delegateDidHighlightItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didHighlightItemAtIndexPath:)];
-    _collectionViewFlags.delegateDidUnhighlightItemAtIndexPath = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didUnhighlightItemAtIndexPath:)];
-
-    //  Tracking the Removal of Views
-    _collectionViewFlags.delegateDidEndDisplayingCell = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)];
-    _collectionViewFlags.delegateDidEndDisplayingSupplementaryView = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:)];
-
-    //  Managing Actions for Cells
-    _collectionViewFlags.delegateSupportsMenus = (unsigned int)[self.delegate respondsToSelector:@selector(collectionView:shouldShowMenuForItemAtIndexPath:)];
-
-    // These aren't present in the flags which is a little strange. Not adding them because that will mess with byte alignment which will affect cross compatibility.
-    // The flag names are guesses and are there for documentation purposes.
-    // _collectionViewFlags.delegateCanPerformActionForItemAtIndexPath = [self.delegate respondsToSelector:@selector(collectionView:canPerformAction:forItemAtIndexPath:withSender:)];
-    // _collectionViewFlags.delegatePerformActionForItemAtIndexPath    = [self.delegate respondsToSelector:@selector(collectionView:performAction:forItemAtIndexPath:withSender:)];
-}
-
-// Might be overkill since two are required and two are handled by PSTCollectionViewData leaving only one flag we actually need to check for
-- (void)setDataSource:(id<PSTCollectionViewDataSource>)dataSource {
-    if (dataSource != _dataSource) {
-        _dataSource = dataSource;
-
-        //  Getting Item and Section Metrics
-        _collectionViewFlags.dataSourceNumberOfSections = (unsigned int)[_dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)];
-
-        //  Getting Views for Items
-        _collectionViewFlags.dataSourceViewForSupplementaryElement = (unsigned int)[_dataSource respondsToSelector:@selector(collectionView:viewForSupplementaryElementOfKind:atIndexPath:)];
-    }
-}
-
-- (BOOL)allowsSelection {
-    return _collectionViewFlags.allowsSelection;
-}
-
-- (void)setAllowsSelection:(BOOL)allowsSelection {
-    _collectionViewFlags.allowsSelection = (unsigned int)allowsSelection;
-}
-
-- (BOOL)allowsMultipleSelection {
-    return _collectionViewFlags.allowsMultipleSelection;
-}
-
-- (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection {
-    _collectionViewFlags.allowsMultipleSelection = (unsigned int)allowsMultipleSelection;
-
-    // Deselect all objects if allows multiple selection is false
-    if (!allowsMultipleSelection && _indexPathsForSelectedItems.count) {
-
-        // Note: Apple's implementation leaves a mostly random item selected. Presumably they
-        //       have a good reason for this, but I guess it's just skipping the last or first index.
-        for (NSIndexPath *selectedIndexPath in [_indexPathsForSelectedItems copy]) {
-            if (_indexPathsForSelectedItems.count == 1) continue;
-            [self deselectItemAtIndexPath:selectedIndexPath animated:YES notifyDelegate:YES];
-        }
-    }
-}
-
-- (CGRect)visibleBoundRects {
-    // in original UICollectionView implementation they
-    // check for _visibleBounds and can union self.bounds
-    // with this value. Don't know the meaning of _visibleBounds however.
-    return self.bounds;
-}
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Private
-
-- (PSTCollectionViewExt *)extVars {
-    return objc_getAssociatedObject(self, &kPSTColletionViewExt);
-}
-
-- (void)invalidateLayout {
-    [self.collectionViewLayout invalidateLayout];
-    [self.collectionViewData invalidate]; // invalidate layout cache
-}
-
-// update currently visible cells, fetches new cells if needed
-// TODO: use now parameter.
-- (void)updateVisibleCellsNow:(BOOL)now {
-    NSArray *layoutAttributesArray = [_collectionViewData layoutAttributesForElementsInRect:self.bounds];
-
-    if (layoutAttributesArray == nil || layoutAttributesArray.count == 0) {
-        // If our layout source isn't providing any layout information, we should just
-        // stop, otherwise we'll blow away all the currently existing cells.
-        return;
-    }
-
-    // create ItemKey/Attributes dictionary
-    NSMutableDictionary *itemKeysToAddDict = [NSMutableDictionary dictionary];
-
-    // Add new cells.
-    for (PSTCollectionViewLayoutAttributes *layoutAttributes in layoutAttributesArray) {
-        PSTCollectionViewItemKey *itemKey = [PSTCollectionViewItemKey collectionItemKeyForLayoutAttributes:layoutAttributes];
-        itemKeysToAddDict[itemKey] = layoutAttributes;
-
-        // check if cell is in visible dict; add it if not.
-        PSTCollectionReusableView *view = _allVisibleViewsDict[itemKey];
-        if (!view) {
-            if (itemKey.type == PSTCollectionViewItemTypeCell) {
-                view = [self createPreparedCellForItemAtIndexPath:itemKey.indexPath withLayoutAttributes:layoutAttributes];
-
-            }else if (itemKey.type == PSTCollectionViewItemTypeSupplementaryView) {
-                view = [self createPreparedSupplementaryViewForElementOfKind:layoutAttributes.representedElementKind
-                        atIndexPath:layoutAttributes.indexPath
-                        withLayoutAttributes:layoutAttributes];
-            }else if (itemKey.type == PSTCollectionViewItemTypeDecorationView) {
-                view = [self dequeueReusableOrCreateDecorationViewOfKind:layoutAttributes.representedElementKind forIndexPath:layoutAttributes.indexPath];
-            }
-
-            // Supplementary views are optional
-            if (view) {
-                _allVisibleViewsDict[itemKey] = view;
-                [self addControlledSubview:view];
-
-                // Always apply attributes. Fixes #203.
-                [view applyLayoutAttributes:layoutAttributes];
-            }
-        }else {
-            // just update cell
-            [view applyLayoutAttributes:layoutAttributes];
-        }
-    }
-
-    // Detect what items should be removed and queued back.
-    NSMutableSet *allVisibleItemKeys = [NSMutableSet setWithArray:[_allVisibleViewsDict allKeys]];
-    [allVisibleItemKeys minusSet:[NSSet setWithArray:[itemKeysToAddDict allKeys]]];
-
-    // Finally remove views that have not been processed and prepare them for re-use.
-    for (PSTCollectionViewItemKey *itemKey in allVisibleItemKeys) {
-        PSTCollectionReusableView *reusableView = _allVisibleViewsDict[itemKey];
-        if (reusableView) {
-            [reusableView removeFromSuperview];
-            [_allVisibleViewsDict removeObjectForKey:itemKey];
-            if (itemKey.type == PSTCollectionViewItemTypeCell) {
-                if (_collectionViewFlags.delegateDidEndDisplayingCell) {
-                    [self.delegate collectionView:self didEndDisplayingCell:(PSTCollectionViewCell *)reusableView forItemAtIndexPath:itemKey.indexPath];
-                }
-                [self reuseCell:(PSTCollectionViewCell *)reusableView];
-            }
-            else if (itemKey.type == PSTCollectionViewItemTypeSupplementaryView) {
-                if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) {
-                    [self.delegate collectionView:self didEndDisplayingSupplementaryView:reusableView forElementOfKind:itemKey.identifier atIndexPath:itemKey.indexPath];
-                }
-                [self reuseSupplementaryView:reusableView];
-            }
-            else if (itemKey.type == PSTCollectionViewItemTypeDecorationView) {
-                [self reuseDecorationView:reusableView];
-            }
-        }
-    }
-}
-
-// fetches a cell from the dataSource and sets the layoutAttributes
-- (PSTCollectionViewCell *)createPreparedCellForItemAtIndexPath:(NSIndexPath *)indexPath withLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes {
-    PSTCollectionViewCell *cell = [self.dataSource collectionView:self cellForItemAtIndexPath:indexPath];
-
-    // Apply attributes
-    [cell applyLayoutAttributes:layoutAttributes];
-
-    // reset selected/highlight state
-    [cell setHighlighted:[_indexPathsForHighlightedItems containsObject:indexPath]];
-    [cell setSelected:[_indexPathsForSelectedItems containsObject:indexPath]];
-
-    // voiceover support
-    cell.isAccessibilityElement = YES;
-
-    return cell;
-}
-
-- (PSTCollectionReusableView *)createPreparedSupplementaryViewForElementOfKind:(NSString *)kind
-        atIndexPath:(NSIndexPath *)indexPath
-        withLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes {
-    if (_collectionViewFlags.dataSourceViewForSupplementaryElement) {
-        PSTCollectionReusableView *view = [self.dataSource collectionView:self
-                viewForSupplementaryElementOfKind:kind
-                atIndexPath:indexPath];
-        [view applyLayoutAttributes:layoutAttributes];
-        return view;
-    }
-    return nil;
-}
-
-// @steipete optimization
-- (void)queueReusableView:(PSTCollectionReusableView *)reusableView inQueue:(NSMutableDictionary *)queue withIdentifier:(NSString *)identifier {
-    NSParameterAssert(identifier.length > 0);
-
-    [reusableView removeFromSuperview];
-    [reusableView prepareForReuse];
-
-    // enqueue cell
-    NSMutableArray *reuseableViews = queue[identifier];
-    if (!reuseableViews) {
-        reuseableViews = [NSMutableArray array];
-        queue[identifier] = reuseableViews;
-    }
-    [reuseableViews addObject:reusableView];
-}
-
-// enqueue cell for reuse
-- (void)reuseCell:(PSTCollectionViewCell *)cell {
-    [self queueReusableView:cell inQueue:_cellReuseQueues withIdentifier:cell.reuseIdentifier];
-}
-
-// enqueue supplementary view for reuse
-- (void)reuseSupplementaryView:(PSTCollectionReusableView *)supplementaryView {
-    NSString *kindAndIdentifier = [NSString stringWithFormat:@"%@/%@", supplementaryView.layoutAttributes.elementKind, supplementaryView.reuseIdentifier];
-    [self queueReusableView:supplementaryView inQueue:_supplementaryViewReuseQueues withIdentifier:kindAndIdentifier];
-}
-
-// enqueue decoration view for reuse
-- (void)reuseDecorationView:(PSTCollectionReusableView *)decorationView {
-    [self queueReusableView:decorationView inQueue:_decorationViewReuseQueues withIdentifier:decorationView.reuseIdentifier];
-}
-
-- (void)addControlledSubview:(PSTCollectionReusableView *)subview {
-    // avoids placing views above the scroll indicator
-    // If the collection view is not displaying scrollIndicators then self.subviews.count can be 0.
-    // We take the max to ensure we insert at a non negative index because a negative index will silently fail to insert the view
-    NSInteger insertionIndex = MAX((NSInteger)(self.subviews.count - (self.dragging ? 1 : 0)), 0);
-    [self insertSubview:subview atIndex:insertionIndex];
-    UIView *scrollIndicatorView = nil;
-    if (self.dragging) {
-        scrollIndicatorView = [self.subviews lastObject];
-    }
-
-    NSMutableArray *floatingViews = [[NSMutableArray alloc] init];
-    for (UIView *uiView in self.subviews) {
-        if ([uiView isKindOfClass:PSTCollectionReusableView.class] && [[(PSTCollectionReusableView *)uiView layoutAttributes] zIndex] > 0) {
-            [floatingViews addObject:uiView];
-        }
-    }
-
-    [floatingViews sortUsingComparator:^NSComparisonResult(PSTCollectionReusableView *obj1, PSTCollectionReusableView *obj2) {
-        CGFloat z1 = [[obj1 layoutAttributes] zIndex];
-        CGFloat z2 = [[obj2 layoutAttributes] zIndex];
-        if (z1 > z2) {
-            return (NSComparisonResult)NSOrderedDescending;
-        }else if (z1 < z2) {
-            return (NSComparisonResult)NSOrderedAscending;
-        }else {
-            return (NSComparisonResult)NSOrderedSame;
-        }
-    }];
-
-    for (PSTCollectionReusableView *uiView in floatingViews) {
-        [self bringSubviewToFront:uiView];
-    }
-
-    if (floatingViews.count && scrollIndicatorView) {
-        [self bringSubviewToFront:scrollIndicatorView];
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Updating grid internal functionality
-
-- (void)suspendReloads {
-    _reloadingSuspendedCount++;
-}
-
-- (void)resumeReloads {
-    if (0 < _reloadingSuspendedCount) _reloadingSuspendedCount--;
-}
-
-- (NSMutableArray *)arrayForUpdateAction:(PSTCollectionUpdateAction)updateAction {
-    NSMutableArray *updateActions = nil;
-
-    switch (updateAction) {
-        case PSTCollectionUpdateActionInsert:
-            if (!_insertItems) _insertItems = [NSMutableArray new];
-            updateActions = _insertItems;
-            break;
-        case PSTCollectionUpdateActionDelete:
-            if (!_deleteItems) _deleteItems = [NSMutableArray new];
-            updateActions = _deleteItems;
-            break;
-        case PSTCollectionUpdateActionMove:
-            if (!_moveItems) _moveItems = [NSMutableArray new];
-            updateActions = _moveItems;
-            break;
-        case PSTCollectionUpdateActionReload:
-            if (!_reloadItems) _reloadItems = [NSMutableArray new];
-            updateActions = _reloadItems;
-            break;
-        default: break;
-    }
-    return updateActions;
-}
-
-- (void)prepareLayoutForUpdates {
-    NSMutableArray *array = [[NSMutableArray alloc] init];
-    [array addObjectsFromArray:[_originalDeleteItems sortedArrayUsingSelector:@selector(inverseCompareIndexPaths:)]];
-    [array addObjectsFromArray:[_originalInsertItems sortedArrayUsingSelector:@selector(compareIndexPaths:)]];
-    [array addObjectsFromArray:[_reloadItems sortedArrayUsingSelector:@selector(compareIndexPaths:)]];
-    [array addObjectsFromArray:[_moveItems sortedArrayUsingSelector:@selector(compareIndexPaths:)]];
-    [_layout prepareForCollectionViewUpdates:array];
-}
-
-- (void)updateWithItems:(NSArray *)items {
-    [self prepareLayoutForUpdates];
-
-    NSMutableArray *animations = [[NSMutableArray alloc] init];
-    NSMutableDictionary *newAllVisibleView = [[NSMutableDictionary alloc] init];
-
-    NSMutableDictionary *viewsToRemove = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-            [NSMutableArray array], @(PSTCollectionViewItemTypeCell),
-            [NSMutableArray array], @(PSTCollectionViewItemTypeDecorationView),
-            [NSMutableArray array], @(PSTCollectionViewItemTypeSupplementaryView), nil];
-
-    for (PSTCollectionViewUpdateItem *updateItem in items) {
-        if (updateItem.isSectionOperation && updateItem.updateAction != PSTCollectionUpdateActionDelete) continue;
-        if (updateItem.isSectionOperation && updateItem.updateAction == PSTCollectionUpdateActionDelete) {
-            NSInteger numberOfBeforeSection = [_update[@"oldModel"] numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section];
-            for (NSInteger i = 0; i < numberOfBeforeSection; i++) {
-                NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:updateItem.indexPathBeforeUpdate.section];
-
-                PSTCollectionViewLayoutAttributes *finalAttrs = [_layout finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath];
-                PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPath];
-                PSTCollectionReusableView *view = _allVisibleViewsDict[key];
-                if (view) {
-                    PSTCollectionViewLayoutAttributes *startAttrs = view.layoutAttributes;
-
-                    if (!finalAttrs) {
-                        finalAttrs = [startAttrs copy];
-                        finalAttrs.alpha = 0;
-                    }
-                    [animations addObject:@{@"view" : view, @"previousLayoutInfos" : startAttrs, @"newLayoutInfos" : finalAttrs}];
-
-                    [_allVisibleViewsDict removeObjectForKey:key];
-
-                    [(NSMutableArray *)viewsToRemove[@(key.type)] addObject:view];
-
-                }
-            }
-            continue;
-        }
-
-        if (updateItem.updateAction == PSTCollectionUpdateActionDelete) {
-            NSIndexPath *indexPath = updateItem.indexPathBeforeUpdate;
-
-            PSTCollectionViewLayoutAttributes *finalAttrs = [_layout finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath];
-            PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPath];
-            PSTCollectionReusableView *view = _allVisibleViewsDict[key];
-            if (view) {
-                PSTCollectionViewLayoutAttributes *startAttrs = view.layoutAttributes;
-
-                if (!finalAttrs) {
-                    finalAttrs = [startAttrs copy];
-                    finalAttrs.alpha = 0;
-                }
-                [animations addObject:@{@"view" : view, @"previousLayoutInfos" : startAttrs, @"newLayoutInfos" : finalAttrs}];
-
-                [_allVisibleViewsDict removeObjectForKey:key];
-
-                [(NSMutableArray *)viewsToRemove[@(key.type)] addObject:view];
-
-            }
-        }
-        else if (updateItem.updateAction == PSTCollectionUpdateActionInsert) {
-            NSIndexPath *indexPath = updateItem.indexPathAfterUpdate;
-            PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPath];
-            PSTCollectionViewLayoutAttributes *startAttrs = [_layout initialLayoutAttributesForAppearingItemAtIndexPath:indexPath];
-            PSTCollectionViewLayoutAttributes *finalAttrs = [_layout layoutAttributesForItemAtIndexPath:indexPath];
-
-            CGRect startRect = startAttrs.frame;
-            CGRect finalRect = finalAttrs.frame;
-
-            if (CGRectIntersectsRect(self.visibleBoundRects, startRect) || CGRectIntersectsRect(self.visibleBoundRects, finalRect)) {
-
-                if (!startAttrs) {
-                    startAttrs = [finalAttrs copy];
-                    startAttrs.alpha = 0;
-                }
-
-                PSTCollectionReusableView *view = [self createPreparedCellForItemAtIndexPath:indexPath
-                        withLayoutAttributes:startAttrs];
-                [self addControlledSubview:view];
-
-                newAllVisibleView[key] = view;
-                [animations addObject:@{@"view" : view, @"previousLayoutInfos" : startAttrs, @"newLayoutInfos" : finalAttrs}];
-            }
-        }
-        else if (updateItem.updateAction == PSTCollectionUpdateActionMove) {
-            NSIndexPath *indexPathBefore = updateItem.indexPathBeforeUpdate;
-            NSIndexPath *indexPathAfter = updateItem.indexPathAfterUpdate;
-
-            PSTCollectionViewItemKey *keyBefore = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPathBefore];
-            PSTCollectionViewItemKey *keyAfter = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:indexPathAfter];
-            PSTCollectionReusableView *view = _allVisibleViewsDict[keyBefore];
-
-            PSTCollectionViewLayoutAttributes *startAttrs = nil;
-            PSTCollectionViewLayoutAttributes *finalAttrs = [_layout layoutAttributesForItemAtIndexPath:indexPathAfter];
-
-            if (view) {
-                startAttrs = view.layoutAttributes;
-                [_allVisibleViewsDict removeObjectForKey:keyBefore];
-                newAllVisibleView[keyAfter] = view;
-            }
-            else {
-                startAttrs = [finalAttrs copy];
-                startAttrs.alpha = 0;
-                view = [self createPreparedCellForItemAtIndexPath:indexPathAfter withLayoutAttributes:startAttrs];
-                [self addControlledSubview:view];
-                newAllVisibleView[keyAfter] = view;
-            }
-
-            [animations addObject:@{@"view" : view, @"previousLayoutInfos" : startAttrs, @"newLayoutInfos" : finalAttrs}];
-        }
-    }
-
-    for (PSTCollectionViewItemKey *key in [_allVisibleViewsDict keyEnumerator]) {
-        PSTCollectionReusableView *view = _allVisibleViewsDict[key];
-
-        if (key.type == PSTCollectionViewItemTypeCell) {
-            NSUInteger oldGlobalIndex = [_update[@"oldModel"] globalIndexForItemAtIndexPath:key.indexPath];
-            NSArray *oldToNewIndexMap = _update[@"oldToNewIndexMap"];
-            NSUInteger newGlobalIndex = NSNotFound;
-            if (NSNotFound != oldGlobalIndex && oldGlobalIndex < oldToNewIndexMap.count) {
-                newGlobalIndex = [oldToNewIndexMap[oldGlobalIndex] unsignedIntegerValue];
-            }
-            NSIndexPath *newIndexPath = newGlobalIndex == NSNotFound ? nil : [_update[@"newModel"] indexPathForItemAtGlobalIndex:(int)newGlobalIndex];
-            NSIndexPath *oldIndexPath = oldGlobalIndex == NSNotFound ? nil : [_update[@"oldModel"] indexPathForItemAtGlobalIndex:(int)oldGlobalIndex];
-
-            if (newIndexPath) {
-                PSTCollectionViewLayoutAttributes *startAttrs = nil;
-                PSTCollectionViewLayoutAttributes *finalAttrs = nil;
-
-                startAttrs = [_layout initialLayoutAttributesForAppearingItemAtIndexPath:oldIndexPath];
-                finalAttrs = [_layout layoutAttributesForItemAtIndexPath:newIndexPath];
-
-                NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"view" : view}];
-                if (startAttrs) dic[@"previousLayoutInfos"] = startAttrs;
-                if (finalAttrs) dic[@"newLayoutInfos"] = finalAttrs;
-
-                [animations addObject:dic];
-                PSTCollectionViewItemKey *newKey = [key copy];
-                [newKey setIndexPath:newIndexPath];
-                newAllVisibleView[newKey] = view;
-
-            }
-        }else if (key.type == PSTCollectionViewItemTypeSupplementaryView) {
-            PSTCollectionViewLayoutAttributes *startAttrs = nil;
-            PSTCollectionViewLayoutAttributes *finalAttrs = nil;
-
-            startAttrs = view.layoutAttributes;
-            finalAttrs = [_layout layoutAttributesForSupplementaryViewOfKind:view.layoutAttributes.representedElementKind atIndexPath:key.indexPath];
-
-            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"view" : view}];
-            if (startAttrs) dic[@"previousLayoutInfos"] = startAttrs;
-            if (finalAttrs) dic[@"newLayoutInfos"] = finalAttrs;
-
-            [animations addObject:dic];
-            PSTCollectionViewItemKey *newKey = [key copy];
-            newAllVisibleView[newKey] = view;
-
-        }
-    }
-    NSArray *allNewlyVisibleItems = [_layout layoutAttributesForElementsInRect:self.visibleBoundRects];
-    for (PSTCollectionViewLayoutAttributes *attrs in allNewlyVisibleItems) {
-        PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForLayoutAttributes:attrs];
-
-        if (key.type == PSTCollectionViewItemTypeCell && ![[newAllVisibleView allKeys] containsObject:key]) {
-            PSTCollectionViewLayoutAttributes *startAttrs =
-                    [_layout initialLayoutAttributesForAppearingItemAtIndexPath:attrs.indexPath];
-
-            PSTCollectionReusableView *view = [self createPreparedCellForItemAtIndexPath:attrs.indexPath
-                    withLayoutAttributes:startAttrs];
-            [self addControlledSubview:view];
-            newAllVisibleView[key] = view;
-
-            [animations addObject:@{@"view" : view, @"previousLayoutInfos" : startAttrs ? startAttrs : attrs, @"newLayoutInfos" : attrs}];
-        }
-    }
-
-	//In here I think it doesn't need the animation but the transaction, it would cause some issue of display.
-	//I resolve the bug when user insert the new sections, the cell will display with a blink animation at the first operation.
-	//But I don't know why the next operation wouldn't reproduction in the pre version.
-    _allVisibleViewsDict = newAllVisibleView;
-
-    for (NSDictionary *animation in animations) {
-        PSTCollectionReusableView *view = animation[@"view"];
-        PSTCollectionViewLayoutAttributes *attr = animation[@"previousLayoutInfos"];
-        [view applyLayoutAttributes:attr];
-    };
-
-    _collectionViewFlags.updatingLayout = YES;
-	
-	[CATransaction begin];
-	[CATransaction setAnimationDuration:0];
-	[CATransaction setCompletionBlock:^{
-		// Iterate through all the views that we are going to remove.
-		[viewsToRemove enumerateKeysAndObjectsUsingBlock:^(NSNumber *keyObj, NSArray *views, BOOL *stop) {
-			PSTCollectionViewItemType type = [keyObj unsignedIntegerValue];
-			for (PSTCollectionReusableView *view in views) {
-				if (type == PSTCollectionViewItemTypeCell) {
-					[self reuseCell:(PSTCollectionViewCell *)view];
-				} else if (type == PSTCollectionViewItemTypeSupplementaryView) {
-					[self reuseSupplementaryView:view];
-				} else if (type == PSTCollectionViewItemTypeDecorationView) {
-					[self reuseDecorationView:view];
-				}
-			}
-		}];
-		
-		_collectionViewFlags.updatingLayout = NO;
-		
-		//In here I think when the block is called, the flag is YES. So the _updateCopletionHandler's paramer is YES.
-		if (_updateCompletionHandler) {
-			_updateCompletionHandler(YES);
-			_updateCompletionHandler = nil;
-		}
-	}];
-	
-	for (NSDictionary *animation in animations) {
-		PSTCollectionReusableView *view = animation[@"view"];
-		PSTCollectionViewLayoutAttributes *attrs = animation[@"newLayoutInfos"];
-		[view applyLayoutAttributes:attrs];
-	}
-	[CATransaction commit];
-	
-    [_layout finalizeCollectionViewUpdates];
-}
-
-- (void)setupCellAnimations {
-    [self updateVisibleCellsNow:YES];
-    [self suspendReloads];
-    _collectionViewFlags.updating = YES;
-}
-
-- (void)endItemAnimations {
-    _updateCount++;
-    PSTCollectionViewData *oldCollectionViewData = _collectionViewData;
-    _collectionViewData = [[PSTCollectionViewData alloc] initWithCollectionView:self layout:_layout];
-
-    [_layout invalidateLayout];
-    [_collectionViewData prepareToLoadData];
-
-    NSMutableArray *someMutableArr1 = [[NSMutableArray alloc] init];
-
-    NSArray *removeUpdateItems = [[self arrayForUpdateAction:PSTCollectionUpdateActionDelete]
-            sortedArrayUsingSelector:@selector(inverseCompareIndexPaths:)];
-
-    NSArray *insertUpdateItems = [[self arrayForUpdateAction:PSTCollectionUpdateActionInsert]
-            sortedArrayUsingSelector:@selector(compareIndexPaths:)];
-
-    NSMutableArray *sortedMutableReloadItems = [[_reloadItems sortedArrayUsingSelector:@selector(compareIndexPaths:)] mutableCopy];
-    NSMutableArray *sortedMutableMoveItems = [[_moveItems sortedArrayUsingSelector:@selector(compareIndexPaths:)] mutableCopy];
-
-    _originalDeleteItems = [removeUpdateItems copy];
-    _originalInsertItems = [insertUpdateItems copy];
-
-    NSMutableArray *someMutableArr2 = [[NSMutableArray alloc] init];
-    NSMutableArray *someMutableArr3 = [[NSMutableArray alloc] init];
-    NSMutableDictionary *operations = [[NSMutableDictionary alloc] init];
-
-    for (PSTCollectionViewUpdateItem *updateItem in sortedMutableReloadItems) {
-        NSAssert(updateItem.indexPathBeforeUpdate.section < [oldCollectionViewData numberOfSections],
-        @"attempt to reload item (%@) that doesn't exist (there are only %ld sections before update)",
-        updateItem.indexPathBeforeUpdate, (long)[oldCollectionViewData numberOfSections]);
-
-        if (updateItem.indexPathBeforeUpdate.item != NSNotFound) {
-            NSAssert(updateItem.indexPathBeforeUpdate.item < [oldCollectionViewData numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section],
-            @"attempt to reload item (%@) that doesn't exist (there are only %ld items in section %ld before update)",
-            updateItem.indexPathBeforeUpdate,
-            (long)[oldCollectionViewData numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section],
-            (long)updateItem.indexPathBeforeUpdate.section);
-        }
-
-        [someMutableArr2 addObject:[[PSTCollectionViewUpdateItem alloc] initWithAction:PSTCollectionUpdateActionDelete
-                forIndexPath:updateItem.indexPathBeforeUpdate]];
-        [someMutableArr3 addObject:[[PSTCollectionViewUpdateItem alloc] initWithAction:PSTCollectionUpdateActionInsert
-                forIndexPath:updateItem.indexPathAfterUpdate]];
-    }
-
-    NSMutableArray *sortedDeletedMutableItems = [[_deleteItems sortedArrayUsingSelector:@selector(inverseCompareIndexPaths:)] mutableCopy];
-    NSMutableArray *sortedInsertMutableItems = [[_insertItems sortedArrayUsingSelector:@selector(compareIndexPaths:)] mutableCopy];
-
-    for (PSTCollectionViewUpdateItem *deleteItem in sortedDeletedMutableItems) {
-        if ([deleteItem isSectionOperation]) {
-            NSAssert(deleteItem.indexPathBeforeUpdate.section < [oldCollectionViewData numberOfSections],
-            @"attempt to delete section (%ld) that doesn't exist (there are only %ld sections before update)",
-            (long)deleteItem.indexPathBeforeUpdate.section,
-            (long)[oldCollectionViewData numberOfSections]);
-
-            for (PSTCollectionViewUpdateItem *moveItem in sortedMutableMoveItems) {
-                if (moveItem.indexPathBeforeUpdate.section == deleteItem.indexPathBeforeUpdate.section) {
-                    if (moveItem.isSectionOperation)
-                    NSAssert(NO, @"attempt to delete and move from the same section %ld", (long)deleteItem.indexPathBeforeUpdate.section);
-                    else
-                            NSAssert(NO, @"attempt to delete and move from the same section (%@)", moveItem.indexPathBeforeUpdate);
-                }
-            }
-        }else {
-            NSAssert(deleteItem.indexPathBeforeUpdate.section < [oldCollectionViewData numberOfSections],
-            @"attempt to delete item (%@) that doesn't exist (there are only %ld sections before update)",
-            deleteItem.indexPathBeforeUpdate,
-            (long)[oldCollectionViewData numberOfSections]);
-            NSAssert(deleteItem.indexPathBeforeUpdate.item < [oldCollectionViewData numberOfItemsInSection:deleteItem.indexPathBeforeUpdate.section],
-            @"attempt to delete item (%@) that doesn't exist (there are only %ld items in section%ld before update)",
-            deleteItem.indexPathBeforeUpdate,
-            (long)[oldCollectionViewData numberOfItemsInSection:deleteItem.indexPathBeforeUpdate.section],
-            (long)deleteItem.indexPathBeforeUpdate.section);
-
-            for (PSTCollectionViewUpdateItem *moveItem in sortedMutableMoveItems) {
-                NSAssert(![deleteItem.indexPathBeforeUpdate isEqual:moveItem.indexPathBeforeUpdate],
-                @"attempt to delete and move the same item (%@)", deleteItem.indexPathBeforeUpdate);
-            }
-
-            if (!operations[@(deleteItem.indexPathBeforeUpdate.section)])
-                operations[@(deleteItem.indexPathBeforeUpdate.section)] = [NSMutableDictionary dictionary];
-
-            operations[@(deleteItem.indexPathBeforeUpdate.section)][@"deleted"] =
-                    @([operations[@(deleteItem.indexPathBeforeUpdate.section)][@"deleted"] intValue] + 1);
-        }
-    }
-
-    for (NSUInteger i = 0; i < sortedInsertMutableItems.count; i++) {
-        PSTCollectionViewUpdateItem *insertItem = sortedInsertMutableItems[i];
-        NSIndexPath *indexPath = insertItem.indexPathAfterUpdate;
-
-        BOOL sectionOperation = [insertItem isSectionOperation];
-        if (sectionOperation) {
-            NSAssert([indexPath section] < [_collectionViewData numberOfSections],
-            @"attempt to insert %ld but there are only %ld sections after update",
-            (long)[indexPath section], (long)[_collectionViewData numberOfSections]);
-
-            for (PSTCollectionViewUpdateItem *moveItem in sortedMutableMoveItems) {
-                if ([moveItem.indexPathAfterUpdate isEqual:indexPath]) {
-                    if (moveItem.isSectionOperation)
-                    NSAssert(NO, @"attempt to perform an insert and a move to the same section (%ld)", (long)indexPath.section);
-                }
-            }
-
-            NSUInteger j = i + 1;
-            while (j < sortedInsertMutableItems.count) {
-                PSTCollectionViewUpdateItem *nextInsertItem = sortedInsertMutableItems[j];
-
-                if (nextInsertItem.indexPathAfterUpdate.section == indexPath.section) {
-                    NSAssert(nextInsertItem.indexPathAfterUpdate.item < [_collectionViewData numberOfItemsInSection:indexPath.section],
-                    @"attempt to insert item %ld into section %ld, but there are only %ld items in section %ld after the update",
-                    (long)nextInsertItem.indexPathAfterUpdate.item,
-                    (long)indexPath.section,
-                    (long)[_collectionViewData numberOfItemsInSection:indexPath.section],
-                    (long)indexPath.section);
-                    [sortedInsertMutableItems removeObjectAtIndex:j];
-                }
-                else break;
-            }
-        }else {
-            NSAssert(indexPath.item < [_collectionViewData numberOfItemsInSection:indexPath.section],
-            @"attempt to insert item to (%@) but there are only %ld items in section %ld after update",
-            indexPath,
-            (long)[_collectionViewData numberOfItemsInSection:indexPath.section],
-            (long)indexPath.section);
-
-            if (!operations[@(indexPath.section)])
-                operations[@(indexPath.section)] = [NSMutableDictionary dictionary];
-
-            operations[@(indexPath.section)][@"inserted"] =
-                    @([operations[@(indexPath.section)][@"inserted"] intValue] + 1);
-        }
-    }
-
-    for (PSTCollectionViewUpdateItem *sortedItem in sortedMutableMoveItems) {
-        if (sortedItem.isSectionOperation) {
-            NSAssert(sortedItem.indexPathBeforeUpdate.section < [oldCollectionViewData numberOfSections],
-            @"attempt to move section (%ld) that doesn't exist (%ld sections before update)",
-            (long)sortedItem.indexPathBeforeUpdate.section,
-            (long)[oldCollectionViewData numberOfSections]);
-            NSAssert(sortedItem.indexPathAfterUpdate.section < [_collectionViewData numberOfSections],
-            @"attempt to move section to %ld but there are only %ld sections after update",
-            (long)sortedItem.indexPathAfterUpdate.section,
-            (long)[_collectionViewData numberOfSections]);
-        }else {
-            NSAssert(sortedItem.indexPathBeforeUpdate.section < [oldCollectionViewData numberOfSections],
-            @"attempt to move item (%@) that doesn't exist (%ld sections before update)",
-            sortedItem, (long)[oldCollectionViewData numberOfSections]);
-            NSAssert(sortedItem.indexPathBeforeUpdate.item < [oldCollectionViewData numberOfItemsInSection:sortedItem.indexPathBeforeUpdate.section],
-            @"attempt to move item (%@) that doesn't exist (%ld items in section %ld before update)",
-            sortedItem,
-            (long)[oldCollectionViewData numberOfItemsInSection:sortedItem.indexPathBeforeUpdate.section],
-            (long)sortedItem.indexPathBeforeUpdate.section);
-
-            NSAssert(sortedItem.indexPathAfterUpdate.section < [_collectionViewData numberOfSections],
-            @"attempt to move item to (%@) but there are only %ld sections after update",
-            sortedItem.indexPathAfterUpdate,
-            (long)[_collectionViewData numberOfSections]);
-            NSAssert(sortedItem.indexPathAfterUpdate.item < [_collectionViewData numberOfItemsInSection:sortedItem.indexPathAfterUpdate.section],
-            @"attempt to move item to (%@) but there are only %ld items in section %ld after update",
-            sortedItem,
-            (long)[_collectionViewData numberOfItemsInSection:sortedItem.indexPathAfterUpdate.section],
-            (long)sortedItem.indexPathAfterUpdate.section);
-        }
-
-        if (!operations[@(sortedItem.indexPathBeforeUpdate.section)])
-            operations[@(sortedItem.indexPathBeforeUpdate.section)] = [NSMutableDictionary dictionary];
-        if (!operations[@(sortedItem.indexPathAfterUpdate.section)])
-            operations[@(sortedItem.indexPathAfterUpdate.section)] = [NSMutableDictionary dictionary];
-
-        operations[@(sortedItem.indexPathBeforeUpdate.section)][@"movedOut"] =
-                @([operations[@(sortedItem.indexPathBeforeUpdate.section)][@"movedOut"] intValue] + 1);
-
-        operations[@(sortedItem.indexPathAfterUpdate.section)][@"movedIn"] =
-                @([operations[@(sortedItem.indexPathAfterUpdate.section)][@"movedIn"] intValue] + 1);
-    }
-
-#if !defined  NS_BLOCK_ASSERTIONS
-    for (NSNumber *sectionKey in [operations keyEnumerator]) {
-        NSInteger section = [sectionKey integerValue];
-
-        NSInteger insertedCount = [operations[sectionKey][@"inserted"] integerValue];
-        NSInteger deletedCount = [operations[sectionKey][@"deleted"] integerValue];
-        NSInteger movedInCount = [operations[sectionKey][@"movedIn"] integerValue];
-        NSInteger movedOutCount = [operations[sectionKey][@"movedOut"] integerValue];
-
-        NSAssert([oldCollectionViewData numberOfItemsInSection:section] + insertedCount - deletedCount + movedInCount - movedOutCount ==
-                [_collectionViewData numberOfItemsInSection:section],
-        @"invalid update in section %ld: number of items after update (%ld) should be equal to the number of items before update (%ld) "\
-                 "plus count of inserted items (%ld), minus count of deleted items (%ld), plus count of items moved in (%ld), minus count of items moved out (%ld)",
-        (long)section,
-        (long)[_collectionViewData numberOfItemsInSection:section],
-        (long)[oldCollectionViewData numberOfItemsInSection:section],
-        (long)insertedCount, (long)deletedCount, (long)movedInCount, (long)movedOutCount);
-    }
-#endif
-
-    [someMutableArr2 addObjectsFromArray:sortedDeletedMutableItems];
-    [someMutableArr3 addObjectsFromArray:sortedInsertMutableItems];
-    [someMutableArr1 addObjectsFromArray:[someMutableArr2 sortedArrayUsingSelector:@selector(inverseCompareIndexPaths:)]];
-    [someMutableArr1 addObjectsFromArray:sortedMutableMoveItems];
-    [someMutableArr1 addObjectsFromArray:[someMutableArr3 sortedArrayUsingSelector:@selector(compareIndexPaths:)]];
-
-    NSMutableArray *layoutUpdateItems = [[NSMutableArray alloc] init];
-
-    [layoutUpdateItems addObjectsFromArray:sortedDeletedMutableItems];
-    [layoutUpdateItems addObjectsFromArray:sortedMutableMoveItems];
-    [layoutUpdateItems addObjectsFromArray:sortedInsertMutableItems];
-
-
-    NSMutableArray *newModel = [NSMutableArray array];
-    for (NSInteger i = 0; i < [oldCollectionViewData numberOfSections]; i++) {
-        NSMutableArray *sectionArr = [NSMutableArray array];
-        for (NSInteger j = 0; j < [oldCollectionViewData numberOfItemsInSection:i]; j++)
-            [sectionArr addObject:@([oldCollectionViewData globalIndexForItemAtIndexPath:[NSIndexPath indexPathForItem:j inSection:i]])];
-        [newModel addObject:sectionArr];
-    }
-
-    for (PSTCollectionViewUpdateItem *updateItem in layoutUpdateItems) {
-        switch (updateItem.updateAction) {
-            case PSTCollectionUpdateActionDelete: {
-                if (updateItem.isSectionOperation) {
-                    // section updates are ignored anyway in animation code. If not commented, mixing rows and section deletion causes crash in else below
-                    // [newModel removeObjectAtIndex:updateItem.indexPathBeforeUpdate.section];
-                }else {
-                    [(NSMutableArray *)newModel[(NSUInteger)updateItem.indexPathBeforeUpdate.section]
-                            removeObjectAtIndex:(NSUInteger)updateItem.indexPathBeforeUpdate.item];
-                }
-            }
-                break;
-            case PSTCollectionUpdateActionInsert: {
-                if (updateItem.isSectionOperation) {
-                    [newModel insertObject:[[NSMutableArray alloc] init]
-                            atIndex:(NSUInteger)updateItem.indexPathAfterUpdate.section];
-                }else {
-                    [(NSMutableArray *)newModel[(NSUInteger)updateItem.indexPathAfterUpdate.section]
-                            insertObject:@(NSNotFound)
-                            atIndex:(NSUInteger)updateItem.indexPathAfterUpdate.item];
-                }
-            }
-                break;
-
-            case PSTCollectionUpdateActionMove: {
-                if (updateItem.isSectionOperation) {
-                    id section = newModel[(NSUInteger)updateItem.indexPathBeforeUpdate.section];
-                    [newModel insertObject:section atIndex:(NSUInteger)updateItem.indexPathAfterUpdate.section];
-                }
-                else {
-                    id object = @([oldCollectionViewData globalIndexForItemAtIndexPath:updateItem.indexPathBeforeUpdate]);
-                    [newModel[(NSUInteger)updateItem.indexPathBeforeUpdate.section] removeObject:object];
-                    [newModel[(NSUInteger)updateItem.indexPathAfterUpdate.section] insertObject:object
-                                                                            atIndex:(NSUInteger)updateItem.indexPathAfterUpdate.item];
-                }
-            }
-                break;
-            default: break;
-        }
-    }
-
-    NSMutableArray *oldToNewMap = [NSMutableArray arrayWithCapacity:(NSUInteger)[oldCollectionViewData numberOfItems]];
-    NSMutableArray *newToOldMap = [NSMutableArray arrayWithCapacity:(NSUInteger)[_collectionViewData numberOfItems]];
-
-    for (NSInteger i = 0; i < [oldCollectionViewData numberOfItems]; i++)
-        [oldToNewMap addObject:@(NSNotFound)];
-
-    for (NSInteger i = 0; i < [_collectionViewData numberOfItems]; i++)
-        [newToOldMap addObject:@(NSNotFound)];
-
-    for (NSUInteger i = 0; i < newModel.count; i++) {
-        NSMutableArray *section = newModel[i];
-        for (NSUInteger j = 0; j < section.count; j++) {
-            NSUInteger newGlobalIndex = [_collectionViewData globalIndexForItemAtIndexPath:[NSIndexPath indexPathForItem:(NSInteger)j inSection:(NSInteger)i]];
-            if ([section[j] integerValue] != NSNotFound)
-                oldToNewMap[[section[j] unsignedIntegerValue]] = @(newGlobalIndex);
-            if (newGlobalIndex != NSNotFound)
-                newToOldMap[newGlobalIndex] = section[j];
-        }
-    }
-
-    _update = @{@"oldModel" : oldCollectionViewData, @"newModel" : _collectionViewData, @"oldToNewIndexMap" : oldToNewMap, @"newToOldIndexMap" : newToOldMap};
-
-    [self updateWithItems:someMutableArr1];
-
-    _originalInsertItems = nil;
-    _originalDeleteItems = nil;
-    _insertItems = nil;
-    _deleteItems = nil;
-    _moveItems = nil;
-    _reloadItems = nil;
-    _update = nil;
-    _updateCount--;
-    _collectionViewFlags.updating = NO;
-    [self resumeReloads];
-}
-
-- (void)updateRowsAtIndexPaths:(NSArray *)indexPaths updateAction:(PSTCollectionUpdateAction)updateAction {
-    BOOL updating = _collectionViewFlags.updating;
-    if (!updating) [self setupCellAnimations];
-
-    NSMutableArray *array = [self arrayForUpdateAction:updateAction]; //returns appropriate empty array if not exists
-
-    for (NSIndexPath *indexPath in indexPaths) {
-        PSTCollectionViewUpdateItem *updateItem = [[PSTCollectionViewUpdateItem alloc] initWithAction:updateAction forIndexPath:indexPath];
-        [array addObject:updateItem];
-    }
-
-    if (!updating) [self endItemAnimations];
-}
-
-
-- (void)updateSections:(NSIndexSet *)sections updateAction:(PSTCollectionUpdateAction)updateAction {
-    BOOL updating = _collectionViewFlags.updating;
-    if (!updating) [self setupCellAnimations];
-
-    NSMutableArray *updateActions = [self arrayForUpdateAction:updateAction];
-
-    [sections enumerateIndexesUsingBlock:^(NSUInteger section, BOOL *stop) {
-        PSTCollectionViewUpdateItem *updateItem = [[PSTCollectionViewUpdateItem alloc] initWithAction:updateAction forIndexPath:[NSIndexPath indexPathForItem:NSNotFound inSection:(NSInteger)section]];
-        [updateActions addObject:updateItem];
-    }];
-
-    if (!updating) [self endItemAnimations];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollection/UICollection interoperability
-
-#ifdef kPSUIInteroperabilityEnabled
-#import <objc/message.h>
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
-    NSMethodSignature *sig = [super methodSignatureForSelector:selector];
-    if(!sig) {
-        NSString *selString = NSStringFromSelector(selector);
-        if ([selString hasPrefix:@"_"]) {
-            SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-            sig = [super methodSignatureForSelector:cleanedSelector];
-        }
-    }
-    return sig;
-}
-- (void)forwardInvocation:(NSInvocation *)inv {
-    NSString *selString = NSStringFromSelector([inv selector]);
-    if ([selString hasPrefix:@"_"]) {
-        SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-        if ([self respondsToSelector:cleanedSelector]) {
-            // dynamically add method for faster resolving
-            Method newMethod = class_getInstanceMethod(self.class, [inv selector]);
-            IMP underscoreIMP = imp_implementationWithBlock(^(id _self) {
-                return objc_msgSend(_self, cleanedSelector);
-            });
-            class_addMethod(self.class, [inv selector], underscoreIMP, method_getTypeEncoding(newMethod));
-            // invoke now
-            inv.selector = cleanedSelector;
-            [inv invokeWithTarget:self];
-        }
-    }else {
-        [super forwardInvocation:inv];
-    }
-}
-#endif
-
-@end
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Runtime Additions to create UICollectionView
-
-@implementation PSUICollectionView_ @end
-@implementation PSUICollectionViewCell_ @end
-@implementation PSUICollectionReusableView_ @end
-@implementation PSUICollectionViewLayout_ @end
-@implementation PSUICollectionViewFlowLayout_ @end
-@implementation PSUICollectionViewLayoutAttributes_ @end
-@implementation PSUICollectionViewController_ @end
-
-static void PSTRegisterClasses() {
-    NSDictionary *map = @{
-        @"UICollectionView": PSUICollectionView_.class,
-        @"UICollectionViewCell": PSUICollectionViewCell_.class,
-        @"UICollectionReusableView": PSUICollectionReusableView_.class,
-        @"UICollectionViewLayout": PSUICollectionViewLayout_.class,
-        @"UICollectionViewFlowLayout": PSUICollectionViewFlowLayout_.class,
-        @"UICollectionViewLayoutAttributes": PSUICollectionViewLayoutAttributes_.class,
-        @"UICollectionViewController": PSUICollectionViewController_.class
-    };
-
-    // Ensure that superclass replacement is all-or-nothing for the PSUI*_ types. Either use exclusively
-    // UICollectionView*, or exclusively PSTCollectionView*.
-    __block BOOL canOverwrite = YES;
-    [map enumerateKeysAndObjectsUsingBlock:^(NSString* UIClassName, id PSTClass, BOOL *stop) {
-        Class UIClass = NSClassFromString(UIClassName);
-        if (UIClass) {
-            // Class size need to be the same for class_setSuperclass to work.
-            // If the UIKit class is smaller then our subclass, ivars won't clash, so there's no issue.
-            long sizeDifference = (long)class_getInstanceSize(UIClass) - class_getInstanceSize(PSTClass);
-            if (sizeDifference > 0) {
-                canOverwrite = NO;
-                NSLog(@"Warning! ivar size mismatch in %@ of %tu bytes - can't change the superclass.", PSTClass, sizeDifference);
-            }
-        } else {
-            canOverwrite = NO;
-            // We're most likely on iOS5, the requested UIKit class doesn't exist, so we create it dynamically.
-            if ((UIClass = objc_allocateClassPair(PSTClass, UIClassName.UTF8String, 0))) {
-                objc_registerClassPair(UIClass);
-            }
-        }
-    }];
-
-    if (canOverwrite) {
-        // All UICollectionView types were found and appropriately sized, so it is safe to replace the super-class.
-        [map enumerateKeysAndObjectsUsingBlock:^(NSString* UIClassName, id PSTClass, BOOL *stop) {
-            Class UIClass = NSClassFromString(UIClassName);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-            // class_setSuperclass is deprecated, but still exists and works on iOS6/7.
-            class_setSuperclass(PSTClass, UIClass);
-#pragma clang diagnostic pop
-        }];
-    }
-}
-
-// Create subclasses that pose as UICollectionView et al, if not available at runtime.
-__attribute__((constructor)) static void PSTCreateUICollectionViewClasses(void) {
-    if (objc_getClass("PSTCollectionViewDisableForwardToUICollectionViewSentinel")) return;
-
-    @autoreleasepool {
-        // Change superclass at runtime. This allows seamless switching from PST* to UI* at runtime.
-        PSTRegisterClasses();
-
-        // add PSUI classes at runtime to make Interface Builder sane
-        // (IB doesn't allow adding the PSUICollectionView_ types but doesn't complain on unknown classes)
-        // The class name may already be in use. This may happen if this code is running for the second time (first for an app bundle, then again for a unit test bundle).
-        Class c;
-        if ((c = objc_allocateClassPair(PSUICollectionView_.class, "PSUICollectionView", 0))) objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionViewCell_.class, "PSUICollectionViewCell", 0))) objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionReusableView_.class, "PSUICollectionReusableView", 0))) objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionViewLayout_.class, "PSUICollectionViewLayout", 0))) objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionViewFlowLayout_.class, "PSUICollectionViewFlowLayout", 0))) objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionViewLayoutAttributes_.class, "PSUICollectionViewLayoutAttributes", 0)))objc_registerClassPair(c);
-        if ((c = objc_allocateClassPair(PSUICollectionViewController_.class, "PSUICollectionViewController", 0))) objc_registerClassPair(c);
-    }
-}
-
-CGFloat PSTSimulatorAnimationDragCoefficient(void) {
-    static CGFloat (*UIAnimationDragCoefficient)(void) = NULL;
-#if TARGET_IPHONE_SIMULATOR
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        UIAnimationDragCoefficient = (CGFloat (*)(void))dlsym(RTLD_DEFAULT, "UIAnimationDragCoefficient");
-    });
-#endif
-    return UIAnimationDragCoefficient ? UIAnimationDragCoefficient() : 1.f;
-}
-
-// helper to check for ivar layout
-#if 0
-static void PSTPrintIvarsForClass(Class aClass) {
-    unsigned int varCount;
-    Ivar *vars = class_copyIvarList(aClass, &varCount);
-    for (int i = 0; i < varCount; i++) {
-        NSLog(@"%s %s", ivar_getTypeEncoding(vars[i]), ivar_getName(vars[i]));
-    }
-    free(vars);
-}
-
-__attribute__((constructor)) static void PSTCheckIfIVarLayoutIsEqualSize(void) {
-    @autoreleasepool {
-        NSLog(@"PSTCollectionView size = %zd, UICollectionView size = %zd", class_getInstanceSize(PSTCollectionView.class),class_getInstanceSize(UICollectionView.class));
-        NSLog(@"PSTCollectionViewCell size = %zd, UICollectionViewCell size = %zd", class_getInstanceSize(PSTCollectionViewCell.class),class_getInstanceSize(UICollectionViewCell.class));
-        NSLog(@"PSTCollectionViewController size = %zd, UICollectionViewController size = %zd", class_getInstanceSize(PSTCollectionViewController.class),class_getInstanceSize(UICollectionViewController.class));
-        NSLog(@"PSTCollectionViewLayout size = %zd, UICollectionViewLayout size = %zd", class_getInstanceSize(PSTCollectionViewLayout.class),class_getInstanceSize(UICollectionViewLayout.class));
-        NSLog(@"PSTCollectionViewFlowLayout size = %zd, UICollectionViewFlowLayout size = %zd", class_getInstanceSize(PSTCollectionViewFlowLayout.class),class_getInstanceSize(UICollectionViewFlowLayout.class));
-        //PSTPrintIvarsForClass(PSTCollectionViewFlowLayout.class); NSLog(@"\n\n\n");PSTPrintIvarsForClass(UICollectionViewFlowLayout.class);
-    }
-}
-#endif

+ 0 - 49
Libraries external/PSTCollectionView/PSTCollectionViewCell.h

@@ -1,49 +0,0 @@
-//
-//  PSTCollectionViewCell.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewCommon.h"
-
-@class PSTCollectionViewLayout, PSTCollectionView, PSTCollectionViewLayoutAttributes;
-
-@interface PSTCollectionReusableView : UIView
-
-@property (nonatomic, readonly, copy) NSString *reuseIdentifier;
-
-// Override in subclasses. Called before instance is returned to the reuse queue.
-- (void)prepareForReuse;
-
-// Apply layout attributes on cell.
-- (void)applyLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes;
-- (void)willTransitionFromLayout:(PSTCollectionViewLayout *)oldLayout toLayout:(PSTCollectionViewLayout *)newLayout;
-- (void)didTransitionFromLayout:(PSTCollectionViewLayout *)oldLayout toLayout:(PSTCollectionViewLayout *)newLayout;
-
-@end
-
-@interface PSTCollectionReusableView (Internal)
-@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
-@property (nonatomic, copy) NSString *reuseIdentifier;
-@property (nonatomic, strong, readonly) PSTCollectionViewLayoutAttributes *layoutAttributes;
-@end
-
-
-@interface PSTCollectionViewCell : PSTCollectionReusableView
-
-@property (nonatomic, readonly) UIView *contentView; // add custom subviews to the cell's contentView
-
-// Cells become highlighted when the user touches them.
-// The selected state is toggled when the user lifts up from a highlighted cell.
-// Override these methods to provide custom UI for a selected or highlighted state.
-// The collection view may call the setters inside an animation block.
-@property (nonatomic, getter=isSelected) BOOL selected;
-@property (nonatomic, getter=isHighlighted) BOOL highlighted;
-
-// The background view is a subview behind all other views.
-// If selectedBackgroundView is different than backgroundView, it will be placed above the background view and animated in on selection.
-@property (nonatomic, strong) UIView *backgroundView;
-@property (nonatomic, strong) UIView *selectedBackgroundView;
-
-@end

+ 0 - 267
Libraries external/PSTCollectionView/PSTCollectionViewCell.m

@@ -1,267 +0,0 @@
-//
-//  PSTCollectionViewCell.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionView.h"
-
-@interface PSTCollectionReusableView () {
-    PSTCollectionViewLayoutAttributes *_layoutAttributes;
-    NSString *_reuseIdentifier;
-    __unsafe_unretained PSTCollectionView *_collectionView;
-    struct {
-        unsigned int inUpdateAnimation : 1;
-    }_reusableViewFlags;
-    char filler[50]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-@property (nonatomic, copy) NSString *reuseIdentifier;
-@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
-@property (nonatomic, strong) PSTCollectionViewLayoutAttributes *layoutAttributes;
-@end
-
-@implementation PSTCollectionReusableView
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)initWithFrame:(CGRect)frame {
-    if ((self = [super initWithFrame:frame])) {
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)aDecoder {
-    if ((self = [super initWithCoder:aDecoder])) {
-        self.reuseIdentifier = [aDecoder decodeObjectForKey:@"UIReuseIdentifier"];
-    }
-    return self;
-}
-
-- (void)awakeFromNib {
-    
-    [super awakeFromNib];
-    
-    self.reuseIdentifier = [self valueForKeyPath:@"reuseIdentifier"];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)prepareForReuse {
-    self.layoutAttributes = nil;
-}
-
-- (void)applyLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes {
-    if (layoutAttributes != _layoutAttributes) {
-        _layoutAttributes = layoutAttributes;
-
-        self.bounds = (CGRect){.origin = self.bounds.origin, .size = layoutAttributes.size};
-        self.center = layoutAttributes.center;
-        self.hidden = layoutAttributes.hidden;
-        self.layer.transform = layoutAttributes.transform3D;
-        self.layer.zPosition = layoutAttributes.zIndex;
-        self.layer.opacity = layoutAttributes.alpha;
-    }
-}
-
-- (void)willTransitionFromLayout:(PSTCollectionViewLayout *)oldLayout toLayout:(PSTCollectionViewLayout *)newLayout {
-    _reusableViewFlags.inUpdateAnimation = YES;
-}
-
-- (void)didTransitionFromLayout:(PSTCollectionViewLayout *)oldLayout toLayout:(PSTCollectionViewLayout *)newLayout {
-    _reusableViewFlags.inUpdateAnimation = NO;
-}
-
-- (BOOL)isInUpdateAnimation {
-    return _reusableViewFlags.inUpdateAnimation;
-}
-
-- (void)setInUpdateAnimation:(BOOL)inUpdateAnimation {
-    _reusableViewFlags.inUpdateAnimation = (unsigned int)inUpdateAnimation;
-}
-
-@end
-
-
-@implementation PSTCollectionViewCell {
-    UIView *_contentView;
-    UIView *_backgroundView;
-    UIView *_selectedBackgroundView;
-    UILongPressGestureRecognizer *_menuGesture;
-    id _selectionSegueTemplate;
-    id _highlightingSupport;
-    struct {
-        unsigned int selected : 1;
-        unsigned int highlighted : 1;
-        unsigned int showingMenu : 1;
-        unsigned int clearSelectionWhenMenuDisappears : 1;
-        unsigned int waitingForSelectionAnimationHalfwayPoint : 1;
-    }_collectionCellFlags;
-    BOOL _selected;
-    BOOL _highlighted;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)initWithFrame:(CGRect)frame {
-    if ((self = [super initWithFrame:frame])) {
-        _backgroundView = [[UIView alloc] initWithFrame:self.bounds];
-        _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        [self addSubview:_backgroundView];
-
-        _contentView = [[UIView alloc] initWithFrame:self.bounds];
-        _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        [self addSubview:_contentView];
-
-        _menuGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(menuGesture:)];
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)aDecoder {
-    if ((self = [super initWithCoder:aDecoder])) {
-        if (self.subviews.count > 0) {
-            _contentView = self.subviews[0];
-        }else {
-            _contentView = [[UIView alloc] initWithFrame:self.bounds];
-            _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-            [self addSubview:_contentView];
-        }
-
-        _backgroundView = [[UIView alloc] initWithFrame:self.bounds];
-        _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        [self insertSubview:_backgroundView belowSubview:_contentView];
-
-        _menuGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(menuGesture:)];
-    }
-    return self;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)prepareForReuse {
-    self.layoutAttributes = nil;
-    self.selected = NO;
-    self.highlighted = NO;
-    self.accessibilityTraits = UIAccessibilityTraitNone;
-}
-
-// Selection highlights underlying contents
-- (void)setSelected:(BOOL)selected {
-    _collectionCellFlags.selected = (unsigned int)selected;
-    self.accessibilityTraits = selected ? UIAccessibilityTraitSelected : UIAccessibilityTraitNone;
-    [self updateBackgroundView:selected];
-}
-
-// Cell highlighting only highlights the cell itself
-- (void)setHighlighted:(BOOL)highlighted {
-    _collectionCellFlags.highlighted = (unsigned int)highlighted;
-    [self updateBackgroundView:highlighted];
-}
-
-- (void)updateBackgroundView:(BOOL)highlight {
-    _selectedBackgroundView.alpha = highlight ? 1.0f : 0.0f;
-    [self setHighlighted:highlight forViews:self.contentView.subviews];
-}
-
-- (void)setHighlighted:(BOOL)highlighted forViews:(id)subviews {
-    for (id view in subviews) {
-        // Ignore the events if view wants to
-        if (!((UIView *)view).isUserInteractionEnabled &&
-                [view respondsToSelector:@selector(setHighlighted:)] &&
-                ![view isKindOfClass:UIControl.class]) {
-            [view setHighlighted:highlighted];
-
-            [self setHighlighted:highlighted forViews:[view subviews]];
-        }
-    }
-}
-
-- (void)menuGesture:(UILongPressGestureRecognizer *)recognizer {
-    NSLog(@"Not yet implemented: %@", NSStringFromSelector(_cmd));
-}
-
-- (void)setBackgroundView:(UIView *)backgroundView {
-    if (_backgroundView != backgroundView) {
-        [_backgroundView removeFromSuperview];
-        _backgroundView = backgroundView;
-        _backgroundView.frame = self.bounds;
-        _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
-        [self insertSubview:_backgroundView atIndex:0];
-    }
-}
-
-- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView {
-    if (_selectedBackgroundView != selectedBackgroundView) {
-        [_selectedBackgroundView removeFromSuperview];
-        _selectedBackgroundView = selectedBackgroundView;
-        _selectedBackgroundView.frame = self.bounds;
-        _selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        _selectedBackgroundView.alpha = self.selected ? 1.0f : 0.0f;
-        if (_backgroundView) {
-            [self insertSubview:_selectedBackgroundView aboveSubview:_backgroundView];
-        }
-        else {
-            [self insertSubview:_selectedBackgroundView atIndex:0];
-        }
-    }
-}
-
-- (BOOL)isSelected {
-    return _collectionCellFlags.selected;
-}
-
-- (BOOL)isHighlighted {
-    return _collectionCellFlags.highlighted;
-}
-
-- (void)performSelectionSegue {
-    /*
-        Currently there's no "official" way to trigger a storyboard segue
-        using UIStoryboardSegueTemplate, so we're doing it in a semi-legal way.
-     */
-    SEL selector = NSSelectorFromString([NSString stringWithFormat:@"per%@", @"form:"]);
-    if ([self->_selectionSegueTemplate respondsToSelector:selector]) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
-        [self->_selectionSegueTemplate performSelector:selector withObject:self];
-#pragma clang diagnostic pop
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollection/UICollection interoperability
-
-#ifdef kPSUIInteroperabilityEnabled
-#import <objc/runtime.h>
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
-    NSMethodSignature *sig = [super methodSignatureForSelector:selector];
-    if(!sig) {
-        NSString *selString = NSStringFromSelector(selector);
-        if ([selString hasPrefix:@"_"]) {
-            SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-            sig = [super methodSignatureForSelector:cleanedSelector];
-        }
-    }
-    return sig;
-}
-
-- (void)forwardInvocation:(NSInvocation *)inv {
-    NSString *selString = NSStringFromSelector([inv selector]);
-    if ([selString hasPrefix:@"_"]) {
-        SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-        if ([self respondsToSelector:cleanedSelector]) {
-            inv.selector = cleanedSelector;
-            [inv invokeWithTarget:self];
-        }
-    }else {
-        [super forwardInvocation:inv];
-    }
-}
-#endif
-
-@end

+ 0 - 73
Libraries external/PSTCollectionView/PSTCollectionViewCommon.h

@@ -1,73 +0,0 @@
-//
-//  PSTCollectionViewCommon.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
-
-// Mostly a debug feature, makes classes from UICollection* compatible with PSTCollection*
-// (e.g. adding the "real" UICollectionViewFlowLayout to PSTCollectionView.
-//#define kPSUIInteroperabilityEnabled
-
-@class PSTCollectionView, PSTCollectionViewCell, PSTCollectionReusableView;
-
-@protocol PSTCollectionViewDataSource <NSObject>
-@required
-
-- (NSInteger)collectionView:(PSTCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
-
-// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
-- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-@optional
-
-- (NSInteger)numberOfSectionsInCollectionView:(PSTCollectionView *)collectionView;
-
-// The view that is returned must be retrieved from a call to -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:
-- (PSTCollectionReusableView *)collectionView:(PSTCollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
-
-@end
-
-@protocol PSTCollectionViewDelegate <UIScrollViewDelegate>
-@optional
-
-// Methods for notification of selection/deselection and highlight/unhighlight events.
-// The sequence of calls leading to selection from a user touch is:
-//
-// (when the touch begins)
-// 1. -collectionView:shouldHighlightItemAtIndexPath:
-// 2. -collectionView:didHighlightItemAtIndexPath:
-//
-// (when the touch lifts)
-// 3. -collectionView:shouldSelectItemAtIndexPath: or -collectionView:shouldDeselectItemAtIndexPath:
-// 4. -collectionView:didSelectItemAtIndexPath: or -collectionView:didDeselectItemAtIndexPath:
-// 5. -collectionView:didUnhighlightItemAtIndexPath:
-- (BOOL)collectionView:(PSTCollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)collectionView:(PSTCollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)collectionView:(PSTCollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (BOOL)collectionView:(PSTCollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (BOOL)collectionView:(PSTCollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath; // called when the user taps on an already-selected item in multi-select mode
-- (void)collectionView:(PSTCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)collectionView:(PSTCollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)collectionView:(PSTCollectionView *)collectionView didEndDisplayingCell:(PSTCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)collectionView:(PSTCollectionView *)collectionView didEndDisplayingSupplementaryView:(PSTCollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;
-
-// These methods provide support for copy/paste actions on cells.
-// All three should be implemented if any are.
-- (BOOL)collectionView:(PSTCollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (BOOL)collectionView:(PSTCollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
-
-- (void)collectionView:(PSTCollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
-
-@end

+ 0 - 24
Libraries external/PSTCollectionView/PSTCollectionViewController.h

@@ -1,24 +0,0 @@
-//
-//  PSTCollectionViewController.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewCommon.h"
-
-@class PSTCollectionViewLayout, PSTCollectionViewController;
-
-// Simple controller-wrapper around PSTCollectionView.
-@interface PSTCollectionViewController : UIViewController <PSTCollectionViewDelegate, PSTCollectionViewDataSource>
-
-// Designated initializer.
-- (id)initWithCollectionViewLayout:(PSTCollectionViewLayout *)layout;
-
-// Internally used collection view. If not set, created during loadView.
-@property (nonatomic, strong) PSTCollectionView *collectionView;
-
-// Defaults to YES, and if YES, any selection is cleared in viewWillAppear:
-@property (nonatomic, assign) BOOL clearsSelectionOnViewWillAppear;
-
-@end

+ 0 - 145
Libraries external/PSTCollectionView/PSTCollectionViewController.m

@@ -1,145 +0,0 @@
-//
-//  PSTCollectionViewController.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewController.h"
-#import "PSTCollectionView.h"
-
-@interface PSTCollectionViewController () {
-    PSTCollectionViewLayout *_layout;
-    PSTCollectionView *_collectionView;
-    struct {
-        unsigned int clearsSelectionOnViewWillAppear : 1;
-        unsigned int appearsFirstTime : 1; // PST extension!
-    }_collectionViewControllerFlags;
-    char filler[100]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-@property (nonatomic, strong) PSTCollectionViewLayout *layout;
-@end
-
-@implementation PSTCollectionViewController
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)initWithCoder:(NSCoder *)coder {
-    self = [super initWithCoder:coder];
-    if (self) {
-        self.layout = [PSTCollectionViewFlowLayout new];
-        self.clearsSelectionOnViewWillAppear = YES;
-        _collectionViewControllerFlags.appearsFirstTime = YES;
-    }
-    return self;
-}
-
-- (id)initWithCollectionViewLayout:(PSTCollectionViewLayout *)layout {
-    if ((self = [super init])) {
-        self.layout = layout;
-        self.clearsSelectionOnViewWillAppear = YES;
-        _collectionViewControllerFlags.appearsFirstTime = YES;
-    }
-    return self;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - UIViewController
-
-- (void)loadView {
-    [super loadView];
-
-    // if this is restored from IB, we don't have plain main view.
-    if ([self.view isKindOfClass:PSTCollectionView.class]) {
-        _collectionView = (PSTCollectionView *)self.view;
-        self.view = [[UIView alloc] initWithFrame:self.view.bounds];
-        self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-    }
-
-    if (_collectionView.delegate == nil) _collectionView.delegate = self;
-    if (_collectionView.dataSource == nil) _collectionView.dataSource = self;
-
-    // only create the collection view if it is not already created (by IB)
-    if (!_collectionView) {
-        self.collectionView = [[PSTCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
-        self.collectionView.delegate = self;
-        self.collectionView.dataSource = self;
-    }
-}
-
-- (void)viewDidLoad {
-    [super viewDidLoad];
-
-    // This seems like a hack, but is needed for real compatibility
-    // There can be implementations of loadView that don't call super and don't set the view, yet it works in UICollectionViewController.
-    if (!self.isViewLoaded) {
-        self.view = [[UIView alloc] initWithFrame:CGRectZero];
-    }
-
-    // Attach the view
-    if (self.view != self.collectionView) {
-        [self.view addSubview:self.collectionView];
-        self.collectionView.frame = self.view.bounds;
-        self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-    }
-}
-
-- (void)viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
-
-    if (_collectionViewControllerFlags.appearsFirstTime) {
-        [_collectionView reloadData];
-        _collectionViewControllerFlags.appearsFirstTime = NO;
-    }
-
-    if (_collectionViewControllerFlags.clearsSelectionOnViewWillAppear) {
-        for (NSIndexPath *aIndexPath in [[_collectionView indexPathsForSelectedItems] copy]) {
-            [_collectionView deselectItemAtIndexPath:aIndexPath animated:animated];
-        }
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Lazy load the collection view
-
-- (PSTCollectionView *)collectionView {
-    if (!_collectionView) {
-        _collectionView = [[PSTCollectionView alloc] initWithFrame:UIScreen.mainScreen.bounds collectionViewLayout:self.layout];
-        _collectionView.delegate = self;
-        _collectionView.dataSource = self;
-
-        // If the collection view isn't the main view, add it.
-        if (self.isViewLoaded && self.view != self.collectionView) {
-            [self.view addSubview:self.collectionView];
-            self.collectionView.frame = self.view.bounds;
-            self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        }
-    }
-    return _collectionView;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Properties
-
-- (void)setClearsSelectionOnViewWillAppear:(BOOL)clearsSelectionOnViewWillAppear {
-    _collectionViewControllerFlags.clearsSelectionOnViewWillAppear = (unsigned int)clearsSelectionOnViewWillAppear;
-}
-
-- (BOOL)clearsSelectionOnViewWillAppear {
-    return _collectionViewControllerFlags.clearsSelectionOnViewWillAppear;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollectionViewDataSource
-
-- (NSInteger)collectionView:(PSTCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-    return 0;
-}
-
-- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-    [self doesNotRecognizeSelector:_cmd];
-    return nil;
-}
-
-@end

+ 0 - 75
Libraries external/PSTCollectionView/PSTCollectionViewData.h

@@ -1,75 +0,0 @@
-//
-//  PSTCollectionViewData.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewCommon.h"
-
-@class PSTCollectionView, PSTCollectionViewLayout, PSTCollectionViewLayoutAttributes;
-
-// https://github.com/steipete/iOS6-Runtime-Headers/blob/master/UICollectionViewData.h
-@interface PSTCollectionViewData : NSObject
-
-// Designated initializer.
-- (id)initWithCollectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout *)layout;
-
-// Ensure data is valid. may fetches items from dataSource and layout.
-- (void)validateLayoutInRect:(CGRect)rect;
-
-- (CGRect)rectForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-/*
- - (CGRect)rectForSupplementaryElementOfKind:(id)arg1 atIndexPath:(id)arg2;
- - (CGRect)rectForDecorationElementOfKind:(id)arg1 atIndexPath:(id)arg2;
- - (CGRect)rectForGlobalItemIndex:(int)arg1;
-*/
-
-// No fucking idea (yet)
-- (NSUInteger)globalIndexForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (NSIndexPath *)indexPathForItemAtGlobalIndex:(NSInteger)index;
-
-// Fetch layout attributes
-- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect;
-
-/*
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForElementsInSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForGlobalItemIndex:(NSInteger)index;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(id)arg1 atIndexPath:(NSIndexPath *)indexPath;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(id)arg1 atIndexPath:(NSIndexPath *)indexPath;
- - (id)existingSupplementaryLayoutAttributesInSection:(int)arg1;
-*/
-
-// Make data to re-evaluate dataSources.
-- (void)invalidate;
-
-// Access cached item data
-- (NSInteger)numberOfItemsBeforeSection:(NSInteger)section;
-
-- (NSInteger)numberOfItemsInSection:(NSInteger)section;
-
-- (NSInteger)numberOfItems;
-
-- (NSInteger)numberOfSections;
-
-// Total size of the content.
-- (CGRect)collectionViewContentRect;
-
-@property (readonly) BOOL layoutIsPrepared;
-
-/*
- - (void)_setLayoutAttributes:(id)arg1 atGlobalItemIndex:(int)arg2;
- - (void)_setupMutableIndexPath:(id*)arg1 forGlobalItemIndex:(int)arg2;
- - (id)_screenPageForPoint:(struct CGPoint { float x1; float x2; })arg1;
- - (void)_validateContentSize;
- - (void)_validateItemCounts;
- - (void)_updateItemCounts;
- - (void)_loadEverything;
- - (void)_prepareToLoadData;
- - (void)invalidate:(BOOL)arg1;
- */
-
-@end

+ 0 - 235
Libraries external/PSTCollectionView/PSTCollectionViewData.m

@@ -1,235 +0,0 @@
-//
-//  PSTCollectionViewData.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewData.h"
-#import "PSTCollectionView.h"
-
-@interface PSTCollectionViewData () {
-    CGRect _validLayoutRect;
-
-    NSInteger _numItems;
-    NSInteger _numSections;
-    NSInteger *_sectionItemCounts;
-//    id __strong* _globalItems; ///< _globalItems appears to be cached layoutAttributes. But adding that work in opens a can of worms, so deferring until later.
-
-/*
- // At this point, I've no idea how _screenPageDict is structured. Looks like some optimization for layoutAttributesForElementsInRect.
- And why UICGPointKey? Isn't that doable with NSValue?
-
- "<UICGPointKey: 0x11432d40>" = "<NSMutableIndexSet: 0x11432c60>[number of indexes: 9 (in 1 ranges), indexes: (0-8)]";
- "<UICGPointKey: 0xb94bf60>" = "<NSMutableIndexSet: 0x18dea7e0>[number of indexes: 11 (in 2 ranges), indexes: (6-15 17)]";
-
- (lldb) p (CGPoint)[[[[[collectionView valueForKey:@"_collectionViewData"] valueForKey:@"_screenPageDict"] allKeys] objectAtIndex:0] point]
- (CGPoint) $11 = (x=15, y=159)
- (lldb) p (CGPoint)[[[[[collectionView valueForKey:@"_collectionViewData"] valueForKey:@"_screenPageDict"] allKeys] objectAtIndex:1] point]
- (CGPoint) $12 = (x=15, y=1128)
-
- // https://github.com/steipete/iOS6-Runtime-Headers/blob/master/UICGPointKey.h
-
- NSMutableDictionary *_screenPageDict;
- */
-
-    // @steipete
-
-    CGSize _contentSize;
-    struct {
-        unsigned int contentSizeIsValid:1;
-        unsigned int itemCountsAreValid:1;
-        unsigned int layoutIsPrepared:1;
-    }_collectionViewDataFlags;
-}
-@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
-@property (nonatomic, unsafe_unretained) PSTCollectionViewLayout *layout;
-@property (nonatomic, strong) NSArray *cachedLayoutAttributes;
-
-@end
-
-@implementation PSTCollectionViewData
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)initWithCollectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout *)layout {
-    if ((self = [super init])) {
-        _collectionView = collectionView;
-        _layout = layout;
-    }
-    return self;
-}
-
-- (void)dealloc {
-    free(_sectionItemCounts);
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p numItems:%ld numSections:%ld>", NSStringFromClass(self.class), self, (long)self.numberOfItems, (long)self.numberOfSections];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)invalidate {
-    _collectionViewDataFlags.itemCountsAreValid = NO;
-    _collectionViewDataFlags.layoutIsPrepared = NO;
-    _validLayoutRect = CGRectNull;  // don't set CGRectZero in case of _contentSize=CGSizeZero
-}
-
-- (CGRect)collectionViewContentRect {
-    return (CGRect){.size=_contentSize};
-}
-
-- (void)validateLayoutInRect:(CGRect)rect {
-    [self validateItemCounts];
-    [self prepareToLoadData];
-
-    // TODO: check if we need to fetch data from layout
-    if (!CGRectEqualToRect(_validLayoutRect, rect)) {
-        _validLayoutRect = rect;
-        // we only want cell layoutAttributes & supplementaryView layoutAttributes
-        self.cachedLayoutAttributes = [[self.layout layoutAttributesForElementsInRect:rect] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(PSTCollectionViewLayoutAttributes *evaluatedObject, NSDictionary *bindings) {
-            return ([evaluatedObject isKindOfClass:PSTCollectionViewLayoutAttributes.class] &&
-                    ([evaluatedObject isCell] ||
-                            [evaluatedObject isSupplementaryView] ||
-                            [evaluatedObject isDecorationView]));
-        }]];
-    }
-}
-
-- (NSInteger)numberOfItems {
-    [self validateItemCounts];
-    return _numItems;
-}
-
-- (NSInteger)numberOfItemsBeforeSection:(NSInteger)section {
-    [self validateItemCounts];
-
-    NSAssert(section < _numSections, @"request for number of items in section %ld when there are only %ld sections in the collection view", (long)section, (long)_numSections);
-
-    NSInteger returnCount = 0;
-    for (int i = 0; i < section; i++) {
-        returnCount += _sectionItemCounts[i];
-    }
-
-    return returnCount;
-}
-
-- (NSInteger)numberOfItemsInSection:(NSInteger)section {
-    [self validateItemCounts];
-    if (section >= _numSections || section < 0) {
-        // In case of inconsistency returns the 'less harmful' amount of items. Throwing an exception here potentially
-        // causes exceptions when data is consistent. Deleting sections is one of the parts sensitive to this.
-        // All checks via assertions are done on CollectionView animation methods, specially 'endAnimations'.
-        return 0;
-        //@throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"Section %d out of range: 0...%d", section, _numSections] userInfo:nil];
-    }
-
-    NSInteger numberOfItemsInSection = 0;
-    if (_sectionItemCounts) {
-        numberOfItemsInSection = _sectionItemCounts[section];
-    }
-    return numberOfItemsInSection;
-}
-
-- (NSInteger)numberOfSections {
-    [self validateItemCounts];
-    return _numSections;
-}
-
-- (CGRect)rectForItemAtIndexPath:(NSIndexPath *)indexPath {
-    return CGRectZero;
-}
-
-- (NSIndexPath *)indexPathForItemAtGlobalIndex:(NSInteger)index {
-    [self validateItemCounts];
-
-    NSAssert(index < _numItems, @"request for index path for global index %ld when there are only %ld items in the collection view", (long)index, (long)_numItems);
-
-    NSInteger section = 0;
-    NSInteger countItems = 0;
-    for (section = 0; section < _numSections; section++) {
-        NSInteger countIncludingThisSection = countItems + _sectionItemCounts[section];
-        if (countIncludingThisSection > index) break;
-        countItems = countIncludingThisSection;
-    }
-
-    NSInteger item = index - countItems;
-
-    return [NSIndexPath indexPathForItem:item inSection:section];
-}
-
-- (NSUInteger)globalIndexForItemAtIndexPath:(NSIndexPath *)indexPath {
-    NSInteger offset = [self numberOfItemsBeforeSection:indexPath.section] + indexPath.item;
-    return (NSUInteger)offset;
-}
-
-- (BOOL)layoutIsPrepared {
-    return _collectionViewDataFlags.layoutIsPrepared;
-}
-
-- (void)setLayoutIsPrepared:(BOOL)layoutIsPrepared {
-    _collectionViewDataFlags.layoutIsPrepared = (unsigned int)layoutIsPrepared;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Fetch Layout Attributes
-
-- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
-    [self validateLayoutInRect:rect];
-    return self.cachedLayoutAttributes;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Private
-
-// ensure item count is valid and loaded
-- (void)validateItemCounts {
-    if (!_collectionViewDataFlags.itemCountsAreValid) {
-        [self updateItemCounts];
-    }
-}
-
-// query dataSource for new data
-- (void)updateItemCounts {
-    // query how many sections there will be
-    _numSections = 1;
-    if ([self.collectionView.dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)]) {
-        _numSections = [self.collectionView.dataSource numberOfSectionsInCollectionView:self.collectionView];
-    }
-    if (_numSections <= 0) { // early bail-out
-        _numItems = 0;
-        free(_sectionItemCounts);
-        _sectionItemCounts = 0;
-        _collectionViewDataFlags.itemCountsAreValid = YES;
-        return;
-    }
-    // allocate space
-    if (!_sectionItemCounts) {
-        _sectionItemCounts = malloc((size_t)_numSections * sizeof(NSInteger));
-    }else {
-        _sectionItemCounts = realloc(_sectionItemCounts, (size_t)_numSections * sizeof(NSInteger));
-    }
-
-    // query cells per section
-    _numItems = 0;
-    for (NSInteger i = 0; i < _numSections; i++) {
-        NSInteger cellCount = [self.collectionView.dataSource collectionView:self.collectionView numberOfItemsInSection:i];
-        _sectionItemCounts[i] = cellCount;
-        _numItems += cellCount;
-    }
-
-    _collectionViewDataFlags.itemCountsAreValid = YES;
-}
-
-- (void)prepareToLoadData {
-    if (!self.layoutIsPrepared) {
-        [self.layout prepareLayout];
-        _contentSize = self.layout.collectionViewContentSize;
-        self.layoutIsPrepared = YES;
-    }
-}
-
-@end

+ 0 - 115
Libraries external/PSTCollectionView/PSTCollectionViewFlowLayout.h

@@ -1,115 +0,0 @@
-//
-//  PSTCollectionViewFlowLayout.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewLayout.h"
-
-extern NSString *const PSTCollectionElementKindSectionHeader;
-extern NSString *const PSTCollectionElementKindSectionFooter;
-
-typedef NS_ENUM(NSInteger, PSTCollectionViewScrollDirection) {
-    PSTCollectionViewScrollDirectionVertical,
-    PSTCollectionViewScrollDirectionHorizontal
-};
-
-@protocol PSTCollectionViewDelegateFlowLayout <PSTCollectionViewDelegate>
-@optional
-
-- (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
-- (UIEdgeInsets)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
-- (CGFloat)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;
-- (CGFloat)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
-- (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
-- (CGSize)collectionView:(PSTCollectionView *)collectionView layout:(PSTCollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
-
-@end
-
-@class PSTGridLayoutInfo;
-
-@interface PSTCollectionViewFlowLayout : PSTCollectionViewLayout
-
-@property (nonatomic) CGFloat minimumLineSpacing;
-@property (nonatomic) CGFloat minimumInteritemSpacing;
-@property (nonatomic) CGSize itemSize; // for the cases the delegate method is not implemented
-@property (nonatomic) PSTCollectionViewScrollDirection scrollDirection; // default is PSTCollectionViewScrollDirectionVertical
-@property (nonatomic) CGSize headerReferenceSize;
-@property (nonatomic) CGSize footerReferenceSize;
-
-@property (nonatomic) UIEdgeInsets sectionInset;
-
-/*
- Row alignment options exits in the official UICollectionView, but hasn't been made public API.
-
- Here's a snippet to test this on UICollectionView:
-
- NSMutableDictionary *rowAlign = [[flowLayout valueForKey:@"_rowAlignmentsOptionsDictionary"] mutableCopy];
- rowAlign[@"UIFlowLayoutCommonRowHorizontalAlignmentKey"] = @(1);
- rowAlign[@"UIFlowLayoutLastRowHorizontalAlignmentKey"] = @(3);
- [flowLayout setValue:rowAlign forKey:@"_rowAlignmentsOptionsDictionary"];
- */
-@property (nonatomic, strong) NSDictionary *rowAlignmentOptions;
-
-@end
-
-// @steipete addition, private API in UICollectionViewFlowLayout
-extern NSString *const PSTFlowLayoutCommonRowHorizontalAlignmentKey;
-extern NSString *const PSTFlowLayoutLastRowHorizontalAlignmentKey;
-extern NSString *const PSTFlowLayoutRowVerticalAlignmentKey;
-
-typedef NS_ENUM(NSInteger, PSTFlowLayoutHorizontalAlignment) {
-    PSTFlowLayoutHorizontalAlignmentLeft,
-    PSTFlowLayoutHorizontalAlignmentCentered,
-    PSTFlowLayoutHorizontalAlignmentRight,
-    PSTFlowLayoutHorizontalAlignmentJustify // 3; default except for the last row
-};
-// TODO: settings for UIFlowLayoutRowVerticalAlignmentKey
-
-
-/*
-@interface PSTCollectionViewFlowLayout (Private)
-
-- (CGSize)synchronizeLayout;
-
-// For items being inserted or deleted, the collection view calls some different methods, which you should override to provide the appropriate layout information.
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForFooterInInsertedSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForHeaderInInsertedSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForInsertedItemAtIndexPath:(NSIndexPath *)indexPath;
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForFooterInDeletedSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForHeaderInDeletedSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDeletedItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (void)_updateItemsLayout;
-- (void)_getSizingInfos;
-- (void)_updateDelegateFlags;
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForFooterInSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForHeaderInSection:(NSInteger)section;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath usingData:(id)data;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForFooterInSection:(NSInteger)section usingData:(id)data;
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForHeaderInSection:(NSInteger)section usingData:(id)data;
-
-- (id)indexesForSectionFootersInRect:(CGRect)rect;
-- (id)indexesForSectionHeadersInRect:(CGRect)rect;
-- (id)indexPathsForItemsInRect:(CGRect)rect usingData:(id)arg2;
-- (id)indexesForSectionFootersInRect:(CGRect)rect usingData:(id)arg2;
-- (id)indexesForSectionHeadersInRect:(CGRect)arg1 usingData:(id)arg2;
-- (CGRect)_frameForItemAtSection:(int)arg1 andRow:(int)arg2 usingData:(id)arg3;
-- (CGRect)_frameForFooterInSection:(int)arg1 usingData:(id)arg2;
-- (CGRect)_frameForHeaderInSection:(int)arg1 usingData:(id)arg2;
-- (void)_invalidateLayout;
-- (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)arg1;
-- (PSTCollectionViewLayoutAttributes *)_layoutAttributesForItemsInRect:(CGRect)arg1;
-- (CGSize)collectionViewContentSize;
-- (void)finalizeCollectionViewUpdates;
-- (void)_invalidateButKeepDelegateInfo;
-- (void)_invalidateButKeepAllInfo;
-- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)arg1;
-- (id)layoutAttributesForElementsInRect:(CGRect)arg1;
-- (void)invalidateLayout;
-- (id)layoutAttributesForItemAtIndexPath:(id)arg1;
-
-@end
-*/

+ 0 - 420
Libraries external/PSTCollectionView/PSTCollectionViewFlowLayout.m

@@ -1,420 +0,0 @@
-//
-//  PSTCollectionViewFlowLayout.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewFlowLayout.h"
-#import "PSTCollectionView.h"
-#import "PSTGridLayoutItem.h"
-#import "PSTGridLayoutInfo.h"
-#import "PSTGridLayoutRow.h"
-#import "PSTGridLayoutSection.h"
-#import <objc/runtime.h>
-
-NSString *const PSTCollectionElementKindSectionHeader = @"UICollectionElementKindSectionHeader";
-NSString *const PSTCollectionElementKindSectionFooter = @"UICollectionElementKindSectionFooter";
-
-// this is not exposed in UICollectionViewFlowLayout
-NSString *const PSTFlowLayoutCommonRowHorizontalAlignmentKey = @"UIFlowLayoutCommonRowHorizontalAlignmentKey";
-NSString *const PSTFlowLayoutLastRowHorizontalAlignmentKey = @"UIFlowLayoutLastRowHorizontalAlignmentKey";
-NSString *const PSTFlowLayoutRowVerticalAlignmentKey = @"UIFlowLayoutRowVerticalAlignmentKey";
-
-@implementation PSTCollectionViewFlowLayout {
-    // class needs to have same iVar layout as UICollectionViewLayout
-    struct {
-        unsigned int delegateSizeForItem : 1;
-        unsigned int delegateReferenceSizeForHeader : 1;
-        unsigned int delegateReferenceSizeForFooter : 1;
-        unsigned int delegateInsetForSection : 1;
-        unsigned int delegateInteritemSpacingForSection : 1;
-        unsigned int delegateLineSpacingForSection : 1;
-        unsigned int delegateAlignmentOptions : 1;
-        unsigned int keepDelegateInfoWhileInvalidating : 1;
-        unsigned int keepAllDataWhileInvalidating : 1;
-        unsigned int layoutDataIsValid : 1;
-        unsigned int delegateInfoIsValid : 1;
-    }_gridLayoutFlags;
-    CGFloat _interitemSpacing;
-    CGFloat _lineSpacing;
-    CGSize _itemSize;
-    CGSize _headerReferenceSize;
-    CGSize _footerReferenceSize;
-    UIEdgeInsets _sectionInset;
-    PSTGridLayoutInfo *_data;
-    CGSize _currentLayoutSize;
-    NSMutableDictionary *_insertedItemsAttributesDict;
-    NSMutableDictionary *_insertedSectionHeadersAttributesDict;
-    NSMutableDictionary *_insertedSectionFootersAttributesDict;
-    NSMutableDictionary *_deletedItemsAttributesDict;
-    NSMutableDictionary *_deletedSectionHeadersAttributesDict;
-    NSMutableDictionary *_deletedSectionFootersAttributesDict;
-    PSTCollectionViewScrollDirection _scrollDirection;
-    NSDictionary *_rowAlignmentsOptionsDictionary;
-    CGRect _visibleBounds;
-    char filler[200]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-
-@synthesize rowAlignmentOptions = _rowAlignmentsOptionsDictionary;
-@synthesize minimumLineSpacing = _lineSpacing;
-@synthesize minimumInteritemSpacing = _interitemSpacing;
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (void)commonInit {
-    _itemSize = CGSizeMake(50.f, 50.f);
-    _lineSpacing = 10.f;
-    _interitemSpacing = 10.f;
-    _sectionInset = UIEdgeInsetsZero;
-    _scrollDirection = PSTCollectionViewScrollDirectionVertical;
-    _headerReferenceSize = CGSizeZero;
-    _footerReferenceSize = CGSizeZero;
-}
-
-- (id)init {
-    if ((self = [super init])) {
-        [self commonInit];
-
-        // set default values for row alignment.
-        _rowAlignmentsOptionsDictionary = @{
-                PSTFlowLayoutCommonRowHorizontalAlignmentKey : @(PSTFlowLayoutHorizontalAlignmentJustify),
-                PSTFlowLayoutLastRowHorizontalAlignmentKey : @(PSTFlowLayoutHorizontalAlignmentJustify),
-                // TODO: those values are some enum. find out what that is.
-                PSTFlowLayoutRowVerticalAlignmentKey : @(1),
-        };
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)decoder {
-    if ((self = [super initWithCoder:decoder])) {
-        [self commonInit];
-
-        // Some properties are not set if they're default (like minimumInteritemSpacing == 10)
-        if ([decoder containsValueForKey:@"UIItemSize"])
-            self.itemSize = [decoder decodeCGSizeForKey:@"UIItemSize"];
-        if ([decoder containsValueForKey:@"UIInteritemSpacing"])
-            self.minimumInteritemSpacing = [decoder decodeFloatForKey:@"UIInteritemSpacing"];
-        if ([decoder containsValueForKey:@"UILineSpacing"])
-            self.minimumLineSpacing = [decoder decodeFloatForKey:@"UILineSpacing"];
-        if ([decoder containsValueForKey:@"UIFooterReferenceSize"])
-            self.footerReferenceSize = [decoder decodeCGSizeForKey:@"UIFooterReferenceSize"];
-        if ([decoder containsValueForKey:@"UIHeaderReferenceSize"])
-            self.headerReferenceSize = [decoder decodeCGSizeForKey:@"UIHeaderReferenceSize"];
-        if ([decoder containsValueForKey:@"UISectionInset"])
-            self.sectionInset = [decoder decodeUIEdgeInsetsForKey:@"UISectionInset"];
-        if ([decoder containsValueForKey:@"UIScrollDirection"])
-            self.scrollDirection = [decoder decodeIntegerForKey:@"UIScrollDirection"];
-    }
-    return self;
-}
-
-- (void)encodeWithCoder:(NSCoder *)coder {
-    [super encodeWithCoder:coder];
-    [coder encodeCGSize:self.itemSize forKey:@"UIItemSize"];
-    [coder encodeFloat:(float)self.minimumInteritemSpacing forKey:@"UIInteritemSpacing"];
-    [coder encodeFloat:(float)self.minimumLineSpacing forKey:@"UILineSpacing"];
-    [coder encodeCGSize:self.footerReferenceSize forKey:@"UIFooterReferenceSize"];
-    [coder encodeCGSize:self.headerReferenceSize forKey:@"UIHeaderReferenceSize"];
-    [coder encodeUIEdgeInsets:self.sectionInset forKey:@"UISectionInset"];
-    [coder encodeInteger:self.scrollDirection forKey:@"UIScrollDirection"];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollectionViewLayout
-
-static char kPSTCachedItemRectsKey;
-
-- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
-    // Apple calls _layoutAttributesForItemsInRect
-    if (!_data) [self prepareLayout];
-
-    NSMutableArray *layoutAttributesArray = [NSMutableArray array];
-    for (PSTGridLayoutSection *section in _data.sections) {
-        if (CGRectIntersectsRect(section.frame, rect)) {
-
-            // if we have fixed size, calculate item frames only once.
-            // this also uses the default PSTFlowLayoutCommonRowHorizontalAlignmentKey alignment
-            // for the last row. (we want this effect!)
-            NSMutableDictionary *rectCache = objc_getAssociatedObject(self, &kPSTCachedItemRectsKey);
-            NSUInteger sectionIndex = [_data.sections indexOfObjectIdenticalTo:section];
-
-            CGRect normalizedHeaderFrame = section.headerFrame;
-            normalizedHeaderFrame.origin.x += section.frame.origin.x;
-            normalizedHeaderFrame.origin.y += section.frame.origin.y;
-            if (!CGRectIsEmpty(normalizedHeaderFrame) && CGRectIntersectsRect(normalizedHeaderFrame, rect)) {
-                PSTCollectionViewLayoutAttributes *layoutAttributes = [[self.class layoutAttributesClass] layoutAttributesForSupplementaryViewOfKind:PSTCollectionElementKindSectionHeader withIndexPath:[NSIndexPath indexPathForItem:0 inSection:(NSInteger)sectionIndex]];
-                layoutAttributes.frame = normalizedHeaderFrame;
-                [layoutAttributesArray addObject:layoutAttributes];
-            }
-
-            NSArray *itemRects = rectCache[@(sectionIndex)];
-            if (!itemRects && section.fixedItemSize && section.rows.count) {
-                itemRects = [(section.rows)[0] itemRects];
-                if (itemRects) rectCache[@(sectionIndex)] = itemRects;
-            }
-            
-            for (PSTGridLayoutRow *row in section.rows) {
-                CGRect normalizedRowFrame = row.rowFrame;
-                
-                normalizedRowFrame.origin.x += section.frame.origin.x;
-                normalizedRowFrame.origin.y += section.frame.origin.y;
-                
-                if (CGRectIntersectsRect(normalizedRowFrame, rect)) {
-                    // TODO be more fine-grained for items
-
-                    for (NSInteger itemIndex = 0; itemIndex < row.itemCount; itemIndex++) {
-                        PSTCollectionViewLayoutAttributes *layoutAttributes;
-                        NSUInteger sectionItemIndex;
-                        CGRect itemFrame;
-                        if (row.fixedItemSize) {
-                            itemFrame = [itemRects[(NSUInteger)itemIndex] CGRectValue];
-                            sectionItemIndex = (NSUInteger)(row.index * section.itemsByRowCount + itemIndex);
-                        }else {
-                            PSTGridLayoutItem *item = row.items[(NSUInteger)itemIndex];
-                            sectionItemIndex = [section.items indexOfObjectIdenticalTo:item];
-                            itemFrame = item.itemFrame;
-                        }
-
-                        CGRect normalisedItemFrame = CGRectMake(normalizedRowFrame.origin.x + itemFrame.origin.x, normalizedRowFrame.origin.y + itemFrame.origin.y, itemFrame.size.width, itemFrame.size.height);
-                        
-                        if (CGRectIntersectsRect(normalisedItemFrame, rect)) {
-                            layoutAttributes = [[self.class layoutAttributesClass] layoutAttributesForCellWithIndexPath:[NSIndexPath indexPathForItem:(NSInteger)sectionItemIndex inSection:(NSInteger)sectionIndex]];
-                            layoutAttributes.frame = normalisedItemFrame;
-                            [layoutAttributesArray addObject:layoutAttributes];
-                        }
-                    }
-                }
-            }
-
-            CGRect normalizedFooterFrame = section.footerFrame;
-            normalizedFooterFrame.origin.x += section.frame.origin.x;
-            normalizedFooterFrame.origin.y += section.frame.origin.y;
-            if (!CGRectIsEmpty(normalizedFooterFrame) && CGRectIntersectsRect(normalizedFooterFrame, rect)) {
-                PSTCollectionViewLayoutAttributes *layoutAttributes = [[self.class layoutAttributesClass] layoutAttributesForSupplementaryViewOfKind:PSTCollectionElementKindSectionFooter withIndexPath:[NSIndexPath indexPathForItem:0 inSection:(NSInteger)sectionIndex]];
-                layoutAttributes.frame = normalizedFooterFrame;
-                [layoutAttributesArray addObject:layoutAttributes];
-            }
-        }
-    }
-    return layoutAttributesArray;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
-    if (!_data) [self prepareLayout];
-
-    PSTGridLayoutSection *section = _data.sections[(NSUInteger)indexPath.section];
-    PSTGridLayoutRow *row = nil;
-    CGRect itemFrame = CGRectZero;
-
-    if (section.fixedItemSize && section.itemsByRowCount > 0 && indexPath.item / section.itemsByRowCount < (NSInteger)section.rows.count) {
-        row = section.rows[(NSUInteger)(indexPath.item / section.itemsByRowCount)];
-        NSUInteger itemIndex = (NSUInteger)(indexPath.item % section.itemsByRowCount);
-        NSArray *itemRects = [row itemRects];
-        itemFrame = [itemRects[itemIndex] CGRectValue];
-    }else if (indexPath.item < (NSInteger)section.items.count) {
-        PSTGridLayoutItem *item = section.items[(NSUInteger)indexPath.item];
-        row = item.rowObject;
-        itemFrame = item.itemFrame;
-    }
-
-    PSTCollectionViewLayoutAttributes *layoutAttributes = [[self.class layoutAttributesClass] layoutAttributesForCellWithIndexPath:indexPath];
-
-    // calculate item rect
-    CGRect normalizedRowFrame = row.rowFrame;
-    normalizedRowFrame.origin.x += section.frame.origin.x;
-    normalizedRowFrame.origin.y += section.frame.origin.y;
-    layoutAttributes.frame = CGRectMake(normalizedRowFrame.origin.x + itemFrame.origin.x, normalizedRowFrame.origin.y + itemFrame.origin.y, itemFrame.size.width, itemFrame.size.height);
-
-    return layoutAttributes;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
-    if (!_data) [self prepareLayout];
-
-    NSUInteger sectionIndex = (NSUInteger)indexPath.section;
-    PSTCollectionViewLayoutAttributes *layoutAttributes = nil;
-
-    if (sectionIndex < _data.sections.count) {
-        PSTGridLayoutSection *section = _data.sections[sectionIndex];
-
-        CGRect normalizedFrame = CGRectZero;
-        if ([kind isEqualToString:PSTCollectionElementKindSectionHeader]) {
-            normalizedFrame = section.headerFrame;
-        }
-        else if ([kind isEqualToString:PSTCollectionElementKindSectionFooter]) {
-            normalizedFrame = section.footerFrame;
-        }
-
-        if (!CGRectIsEmpty(normalizedFrame)) {
-            normalizedFrame.origin.x += section.frame.origin.x;
-            normalizedFrame.origin.y += section.frame.origin.y;
-
-            layoutAttributes = [[self.class layoutAttributesClass] layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:[NSIndexPath indexPathForItem:0 inSection:(NSInteger)sectionIndex]];
-            layoutAttributes.frame = normalizedFrame;
-        }
-    }
-    return layoutAttributes;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForDecorationViewWithReuseIdentifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath {
-    return nil;
-}
-
-- (CGSize)collectionViewContentSize {
-    if (!_data) [self prepareLayout];
-
-    return _data.contentSize;
-}
-
-- (void)setSectionInset:(UIEdgeInsets)sectionInset {
-    if (!UIEdgeInsetsEqualToEdgeInsets(sectionInset, _sectionInset)) {
-        _sectionInset = sectionInset;
-        [self invalidateLayout];
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Invalidating the Layout
-
-- (void)invalidateLayout {
-    [super invalidateLayout];
-    objc_setAssociatedObject(self, &kPSTCachedItemRectsKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-    _data = nil;
-}
-
-- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
-    // we need to recalculate on width changes
-    if ((_visibleBounds.size.width != newBounds.size.width && self.scrollDirection == PSTCollectionViewScrollDirectionVertical) || (_visibleBounds.size.height != newBounds.size.height && self.scrollDirection == PSTCollectionViewScrollDirectionHorizontal)) {
-        _visibleBounds = self.collectionView.bounds;
-        return YES;
-    }
-    return NO;
-}
-
-// return a point at which to rest after scrolling - for layouts that want snap-to-point scrolling behavior
-- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {
-    return proposedContentOffset;
-}
-
-- (void)prepareLayout {
-    // custom ivars
-    objc_setAssociatedObject(self, &kPSTCachedItemRectsKey, [NSMutableDictionary dictionary], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-
-    _data = [PSTGridLayoutInfo new]; // clear old layout data
-    _data.horizontal = self.scrollDirection == PSTCollectionViewScrollDirectionHorizontal;
-    _visibleBounds = self.collectionView.bounds;
-    CGSize collectionViewSize = _visibleBounds.size;
-    _data.dimension = _data.horizontal ? collectionViewSize.height : collectionViewSize.width;
-    _data.rowAlignmentOptions = _rowAlignmentsOptionsDictionary;
-    [self fetchItemsInfo];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Private
-
-- (void)fetchItemsInfo {
-    [self getSizingInfos];
-    [self updateItemsLayout];
-}
-
-// get size of all items (if delegate is implemented)
-- (void)getSizingInfos {
-    NSAssert(_data.sections.count == 0, @"Grid layout is already populated?");
-
-    id<PSTCollectionViewDelegateFlowLayout> flowDataSource = (id<PSTCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
-
-    BOOL implementsSizeDelegate = [flowDataSource respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)];
-    BOOL implementsHeaderReferenceDelegate = [flowDataSource respondsToSelector:@selector(collectionView:layout:referenceSizeForHeaderInSection:)];
-    BOOL implementsFooterReferenceDelegate = [flowDataSource respondsToSelector:@selector(collectionView:layout:referenceSizeForFooterInSection:)];
-
-    NSInteger numberOfSections = [self.collectionView numberOfSections];
-    for (NSInteger section = 0; section < numberOfSections; section++) {
-        PSTGridLayoutSection *layoutSection = [_data addSection];
-        layoutSection.verticalInterstice = _data.horizontal ? self.minimumInteritemSpacing : self.minimumLineSpacing;
-        layoutSection.horizontalInterstice = !_data.horizontal ? self.minimumInteritemSpacing : self.minimumLineSpacing;
-
-        if ([flowDataSource respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]) {
-            layoutSection.sectionMargins = [flowDataSource collectionView:self.collectionView layout:self insetForSectionAtIndex:section];
-        }else {
-            layoutSection.sectionMargins = self.sectionInset;
-        }
-
-        if ([flowDataSource respondsToSelector:@selector(collectionView:layout:minimumLineSpacingForSectionAtIndex:)]) {
-            CGFloat minimumLineSpacing = [flowDataSource collectionView:self.collectionView layout:self minimumLineSpacingForSectionAtIndex:section];
-            if (_data.horizontal) {
-                layoutSection.horizontalInterstice = minimumLineSpacing;
-            }else {
-                layoutSection.verticalInterstice = minimumLineSpacing;
-            }
-        }
-
-        if ([flowDataSource respondsToSelector:@selector(collectionView:layout:minimumInteritemSpacingForSectionAtIndex:)]) {
-            CGFloat minimumInterimSpacing = [flowDataSource collectionView:self.collectionView layout:self minimumInteritemSpacingForSectionAtIndex:section];
-            if (_data.horizontal) {
-                layoutSection.verticalInterstice = minimumInterimSpacing;
-            }else {
-                layoutSection.horizontalInterstice = minimumInterimSpacing;
-            }
-        }
-
-        CGSize headerReferenceSize;
-        if (implementsHeaderReferenceDelegate) {
-            headerReferenceSize = [flowDataSource collectionView:self.collectionView layout:self referenceSizeForHeaderInSection:section];
-        }else {
-            headerReferenceSize = self.headerReferenceSize;
-        }
-        layoutSection.headerDimension = _data.horizontal ? headerReferenceSize.width : headerReferenceSize.height;
-
-        CGSize footerReferenceSize;
-        if (implementsFooterReferenceDelegate) {
-            footerReferenceSize = [flowDataSource collectionView:self.collectionView layout:self referenceSizeForFooterInSection:section];
-        }else {
-            footerReferenceSize = self.footerReferenceSize;
-        }
-        layoutSection.footerDimension = _data.horizontal ? footerReferenceSize.width : footerReferenceSize.height;
-
-        NSInteger numberOfItems = [self.collectionView numberOfItemsInSection:section];
-
-        // if delegate implements size delegate, query it for all items
-        if (implementsSizeDelegate) {
-            for (NSInteger item = 0; item < numberOfItems; item++) {
-                NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:(NSInteger)section];
-                CGSize itemSize = implementsSizeDelegate ? [flowDataSource collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath] : self.itemSize;
-
-                PSTGridLayoutItem *layoutItem = [layoutSection addItem];
-                layoutItem.itemFrame = (CGRect){.size=itemSize};
-            }
-            // if not, go the fast path
-        }else {
-            layoutSection.fixedItemSize = YES;
-            layoutSection.itemSize = self.itemSize;
-            layoutSection.itemsCount = numberOfItems;
-        }
-    }
-}
-
-- (void)updateItemsLayout {
-    CGSize contentSize = CGSizeZero;
-    for (PSTGridLayoutSection *section in _data.sections) {
-        [section computeLayout];
-
-        // update section offset to make frame absolute (section only calculates relative)
-        CGRect sectionFrame = section.frame;
-        if (_data.horizontal) {
-            sectionFrame.origin.x += contentSize.width;
-            contentSize.width += section.frame.size.width + section.frame.origin.x;
-            contentSize.height = MAX(contentSize.height, sectionFrame.size.height + section.frame.origin.y + section.sectionMargins.top + section.sectionMargins.bottom);
-        }else {
-            sectionFrame.origin.y += contentSize.height;
-            contentSize.height += sectionFrame.size.height + section.frame.origin.y;
-            contentSize.width = MAX(contentSize.width, sectionFrame.size.width + section.frame.origin.x + section.sectionMargins.left + section.sectionMargins.right);
-        }
-        section.frame = sectionFrame;
-    }
-    _data.contentSize = contentSize;
-}
-
-@end

+ 0 - 28
Libraries external/PSTCollectionView/PSTCollectionViewItemKey.h

@@ -1,28 +0,0 @@
-//
-//  PSTCollectionViewItemKey.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewCommon.h"
-#import "PSTCollectionViewLayout.h"
-
-extern NSString *const PSTCollectionElementKindCell;
-extern NSString *const PSTCollectionElementKindDecorationView;
-@class PSTCollectionViewLayoutAttributes;
-
-NSString *PSTCollectionViewItemTypeToString(PSTCollectionViewItemType type); // debug helper
-
-// Used in NSDictionaries
-@interface PSTCollectionViewItemKey : NSObject <NSCopying>
-
-+ (id)collectionItemKeyForLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes;
-
-+ (id)collectionItemKeyForCellWithIndexPath:(NSIndexPath *)indexPath;
-
-@property (nonatomic, assign) PSTCollectionViewItemType type;
-@property (nonatomic, strong) NSIndexPath *indexPath;
-@property (nonatomic, strong) NSString *identifier;
-
-@end

+ 0 - 77
Libraries external/PSTCollectionView/PSTCollectionViewItemKey.m

@@ -1,77 +0,0 @@
-//
-//  PSTCollectionViewItemKey.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewItemKey.h"
-
-NSString *const PSTCollectionElementKindCell = @"UICollectionElementKindCell";
-
-@implementation PSTCollectionViewItemKey
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Static
-
-+ (id)collectionItemKeyForCellWithIndexPath:(NSIndexPath *)indexPath {
-    PSTCollectionViewItemKey *key = [self.class new];
-    key.indexPath = indexPath;
-    key.type = PSTCollectionViewItemTypeCell;
-    key.identifier = PSTCollectionElementKindCell;
-    return key;
-}
-
-+ (id)collectionItemKeyForLayoutAttributes:(PSTCollectionViewLayoutAttributes *)layoutAttributes {
-    PSTCollectionViewItemKey *key = [self.class new];
-    key.indexPath = layoutAttributes.indexPath;
-    PSTCollectionViewItemType const itemType = layoutAttributes.representedElementCategory;
-    key.type = itemType;
-    key.identifier = layoutAttributes.representedElementKind;
-    return key;
-}
-
-NSString *PSTCollectionViewItemTypeToString(PSTCollectionViewItemType type) {
-    switch (type) {
-        case PSTCollectionViewItemTypeCell: return @"Cell";
-        case PSTCollectionViewItemTypeDecorationView: return @"Decoration";
-        case PSTCollectionViewItemTypeSupplementaryView: return @"Supplementary";
-        default: return @"<INVALID>";
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p Type = %@ Identifier=%@ IndexPath = %@>", NSStringFromClass(self.class),
-                                      self, PSTCollectionViewItemTypeToString(self.type), _identifier, self.indexPath];
-}
-
-- (NSUInteger)hash {
-    return (([_indexPath hash] + _type) * 31) + [_identifier hash];
-}
-
-- (BOOL)isEqual:(id)other {
-    if ([other isKindOfClass:self.class]) {
-        PSTCollectionViewItemKey *otherKeyItem = (PSTCollectionViewItemKey *)other;
-        // identifier might be nil?
-        if (_type == otherKeyItem.type && [_indexPath isEqual:otherKeyItem.indexPath] && ([_identifier isEqualToString:otherKeyItem.identifier] || _identifier == otherKeyItem.identifier)) {
-            return YES;
-        }
-    }
-    return NO;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSCopying
-
-- (id)copyWithZone:(NSZone *)zone {
-    PSTCollectionViewItemKey *itemKey = [self.class new];
-    itemKey.indexPath = self.indexPath;
-    itemKey.type = self.type;
-    itemKey.identifier = self.identifier;
-    return itemKey;
-}
-
-@end

+ 0 - 18
Libraries external/PSTCollectionView/PSTCollectionViewLayout+Internals.h

@@ -1,18 +0,0 @@
-//
-//  PSTCollectionViewLayout+Internals.h
-//  FMPSTCollectionView
-//
-//  Created by Scott Talbot on 27/02/13.
-//  Copyright (c) 2013 Scott Talbot. All rights reserved.
-//
-
-#import "PSTCollectionViewLayout.h"
-
-
-@interface PSTCollectionViewLayout (Internals)
-
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewClassDict;
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewNibDict;
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewExternalObjectsTables;
-
-@end

+ 0 - 128
Libraries external/PSTCollectionView/PSTCollectionViewLayout.h

@@ -1,128 +0,0 @@
-//
-//  PSTCollectionViewLayout.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionViewCommon.h"
-#import <CoreGraphics/CoreGraphics.h>
-#import <QuartzCore/QuartzCore.h>
-
-typedef NS_ENUM(NSUInteger, PSTCollectionViewItemType) {
-    PSTCollectionViewItemTypeCell,
-    PSTCollectionViewItemTypeSupplementaryView,
-    PSTCollectionViewItemTypeDecorationView
-};
-
-// The PSTCollectionViewLayout class is provided as an abstract class for subclassing to define custom collection layouts.
-// Defining a custom layout is an advanced operation intended for applications with complex needs.
-@class PSTCollectionViewLayoutAttributes, PSTCollectionView;
-
-@interface PSTCollectionViewLayoutAttributes : NSObject <NSCopying>
-
-@property (nonatomic) CGRect frame;
-@property (nonatomic) CGPoint center;
-@property (nonatomic) CGSize size;
-@property (nonatomic) CATransform3D transform3D;
-@property (nonatomic) CGFloat alpha;
-@property (nonatomic) NSInteger zIndex; // default is 0
-@property (nonatomic, getter=isHidden) BOOL hidden; // As an optimization, PSTCollectionView might not create a view for items whose hidden attribute is YES
-@property (nonatomic, strong) NSIndexPath *indexPath;
-
-+ (instancetype)layoutAttributesForCellWithIndexPath:(NSIndexPath *)indexPath;
-
-+ (instancetype)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind withIndexPath:(NSIndexPath *)indexPath;
-
-+ (instancetype)layoutAttributesForDecorationViewOfKind:(NSString *)kind withIndexPath:(NSIndexPath *)indexPath;
-
-/*
- + (id)layoutAttributesForDecorationViewOfKind:(id)arg1 withIndexPath:(id)arg2;
- - (id)initialLayoutAttributesForInsertedDecorationElementOfKind:(id)arg1 atIndexPath:(id)arg2;
- - (BOOL)_isEquivalentTo:(id)arg1;
- */
-@end
-
-@interface PSTCollectionViewLayoutAttributes (Private)
-@property (nonatomic, readonly) NSString *representedElementKind;
-@property (nonatomic, readonly) PSTCollectionViewItemType representedElementCategory;
-
-- (BOOL)isDecorationView;
-
-- (BOOL)isSupplementaryView;
-
-- (BOOL)isCell;
-@end
-
-@interface PSTCollectionViewLayout : NSObject <NSCoding>
-
-// Methods in this class are meant to be overridden and will be called by its collection view to gather layout information.
-// To get the truth on the current state of the collection view, call methods on PSTCollectionView rather than these.
-@property (nonatomic, unsafe_unretained, readonly) PSTCollectionView *collectionView;
-
-// Call -invalidateLayout to indicate that the collection view needs to requery the layout information.
-// Subclasses must always call super if they override.
-- (void)invalidateLayout;
-
-/// @name Registering Decoration Views
-- (void)registerClass:(Class)viewClass forDecorationViewOfKind:(NSString *)kind;
-
-- (void)registerNib:(UINib *)nib forDecorationViewOfKind:(NSString *)kind;
-
-@end
-
-
-@interface PSTCollectionViewLayout (SubclassingHooks)
-
-+ (Class)layoutAttributesClass; // override this method to provide a custom class to be used when instantiating instances of PSTCollectionViewLayoutAttributes
-
-// The collection view calls -prepareLayout once at its first layout as the first message to the layout instance.
-// The collection view calls -prepareLayout again after layout is invalidated and before requerying the layout information.
-// Subclasses should always call super if they override.
-- (void)prepareLayout;
-
-// PSTCollectionView calls these four methods to determine the layout information.
-// Implement -layoutAttributesForElementsInRect: to return layout attributes for supplementary or decoration views, or to perform layout in an as-needed-on-screen fashion.
-// Additionally, all layout subclasses should implement -layoutAttributesForItemAtIndexPath: to return layout attributes instances on demand for specific index paths.
-// If the layout supports any supplementary or decoration view types, it should also implement the respective atIndexPath: methods for those types.
-- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect; // return an array layout attributes instances for all the views in the given rect
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
-
-- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds; // return YES to cause the collection view to requery the layout for geometry information
-- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity; // return a point at which to rest after scrolling - for layouts that want snap-to-point scrolling behavior
-
-- (CGSize)collectionViewContentSize; // the collection view calls this to update its content size any time it queries new layout information - at least one of the width and height fields must match the respective field of the collection view's bounds
-
-@end
-
-@interface PSTCollectionViewLayout (UpdateSupportHooks)
-
-// This method is called when there is an update with deletes/inserts to the collection view.
-// It will be called prior to calling the initial/final layout attribute methods below to give the layout an opportunity to do batch computations for the insertion and deletion layout attributes.
-// The updateItems parameter is an array of PSTCollectionViewUpdateItem instances for each element that is moving to a new index path.
-- (void)prepareForCollectionViewUpdates:(NSArray *)updateItems;
-
-// This method is called inside an animation block after all items have been laid out for a collection view update.
-// Subclasses can use this opportunity to layout their 'layout-owned' decoration views in response to the update.
-- (void)finalizeCollectionViewUpdates;
-
-// Collection view calls these methods to determine the starting layout for animating in newly inserted views, or the ending layout for animating out deleted views
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath;
-
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath;
-
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForInsertedSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath;
-
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDeletedSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath;
-
-@end
-
-@interface PSTCollectionViewLayout (Private)
-- (void)setCollectionViewBoundsSize:(CGSize)size;
-
-- (PSTCollectionReusableView *)decorationViewForCollectionView:(PSTCollectionView *)collectionView withReuseIdentifier:(NSString *)reuseIdentifier indexPath:(NSIndexPath *)indexPath;
-@end

+ 0 - 481
Libraries external/PSTCollectionView/PSTCollectionViewLayout.m

@@ -1,481 +0,0 @@
-//
-//  PSTCollectionViewLayout.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionView.h"
-#import "PSTCollectionViewItemKey.h"
-#import "PSTCollectionViewData.h"
-
-#import <objc/runtime.h>
-
-@interface PSTCollectionView ()
-- (id)currentUpdate;
-- (NSDictionary *)visibleViewsDict;
-- (PSTCollectionViewData *)collectionViewData;
-- (CGRect)visibleBoundRects; // visibleBounds is flagged as private API (wtf)
-@end
-
-@interface PSTCollectionReusableView ()
-- (void)setIndexPath:(NSIndexPath *)indexPath;
-@end
-
-@interface PSTCollectionViewUpdateItem ()
-- (BOOL)isSectionOperation;
-@end
-
-@interface PSTCollectionViewLayoutAttributes () {
-    struct {
-        unsigned int isCellKind:1;
-        unsigned int isDecorationView:1;
-        unsigned int isHidden:1;
-    }_layoutFlags;
-    char filler[20]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-@property (nonatomic) PSTCollectionViewItemType elementCategory;
-@property (nonatomic, copy) NSString *elementKind;
-@end
-
-@interface PSTCollectionViewUpdateItem ()
-- (NSIndexPath *)indexPath;
-@end
-
-@implementation PSTCollectionViewLayoutAttributes
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Static
-
-+ (instancetype)layoutAttributesForCellWithIndexPath:(NSIndexPath *)indexPath {
-    PSTCollectionViewLayoutAttributes *attributes = [self new];
-    attributes.elementKind = PSTCollectionElementKindCell;
-    attributes.elementCategory = PSTCollectionViewItemTypeCell;
-    attributes.indexPath = indexPath;
-    return attributes;
-}
-
-+ (instancetype)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind withIndexPath:(NSIndexPath *)indexPath {
-    PSTCollectionViewLayoutAttributes *attributes = [self new];
-    attributes.elementCategory = PSTCollectionViewItemTypeSupplementaryView;
-    attributes.elementKind = elementKind;
-    attributes.indexPath = indexPath;
-    return attributes;
-}
-
-+ (instancetype)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind withIndexPath:(NSIndexPath *)indexPath {
-    PSTCollectionViewLayoutAttributes *attributes = [self new];
-    attributes.elementCategory = PSTCollectionViewItemTypeDecorationView;
-    attributes.elementKind = elementKind;
-    attributes.indexPath = indexPath;
-    return attributes;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)init {
-    if ((self = [super init])) {
-        _alpha = 1.f;
-        _transform3D = CATransform3DIdentity;
-    }
-    return self;
-}
-
-- (NSUInteger)hash {
-    return ([_elementKind hash] * 31) + [_indexPath hash];
-}
-
-- (BOOL)isEqual:(id)other {
-    if ([other isKindOfClass:self.class]) {
-        PSTCollectionViewLayoutAttributes *otherLayoutAttributes = (PSTCollectionViewLayoutAttributes *)other;
-        if (_elementCategory == otherLayoutAttributes.elementCategory && [_elementKind isEqual:otherLayoutAttributes.elementKind] && [_indexPath isEqual:otherLayoutAttributes.indexPath]) {
-            return YES;
-        }
-    }
-    return NO;
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p frame:%@ indexPath:%@ elementKind:%@>", NSStringFromClass(self.class), self, NSStringFromCGRect(self.frame), self.indexPath, self.elementKind];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (PSTCollectionViewItemType)representedElementCategory {
-    return _elementCategory;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Private
-
-- (NSString *)representedElementKind {
-    return self.elementKind;
-}
-
-- (BOOL)isDecorationView {
-    return self.representedElementCategory == PSTCollectionViewItemTypeDecorationView;
-}
-
-- (BOOL)isSupplementaryView {
-    return self.representedElementCategory == PSTCollectionViewItemTypeSupplementaryView;
-}
-
-- (BOOL)isCell {
-    return self.representedElementCategory == PSTCollectionViewItemTypeCell;
-}
-
-- (void) updateFrame {
-    _frame = (CGRect){{_center.x - _size.width / 2, _center.y - _size.height / 2}, _size};
-}
-
-- (void)setSize:(CGSize)size {
-    _size = size;
-    [self updateFrame];
-}
-
-- (void)setCenter:(CGPoint)center {
-    _center = center;
-    [self updateFrame];
-}
-
-- (void)setFrame:(CGRect)frame {
-    _frame = frame;
-    _size = _frame.size;
-    _center = (CGPoint){CGRectGetMidX(_frame), CGRectGetMidY(_frame)};
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSCopying
-
-- (id)copyWithZone:(NSZone *)zone {
-    PSTCollectionViewLayoutAttributes *layoutAttributes = [self.class new];
-    layoutAttributes.indexPath = self.indexPath;
-    layoutAttributes.elementKind = self.elementKind;
-    layoutAttributes.elementCategory = self.elementCategory;
-    layoutAttributes.frame = self.frame;
-    layoutAttributes.center = self.center;
-    layoutAttributes.size = self.size;
-    layoutAttributes.transform3D = self.transform3D;
-    layoutAttributes.alpha = self.alpha;
-    layoutAttributes.zIndex = self.zIndex;
-    layoutAttributes.hidden = self.isHidden;
-    return layoutAttributes;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollection/UICollection interoperability
-
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
-    NSMethodSignature *signature = [super methodSignatureForSelector:selector];
-    if (!signature) {
-        NSString *selString = NSStringFromSelector(selector);
-        if ([selString hasPrefix:@"_"]) {
-            SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-            signature = [super methodSignatureForSelector:cleanedSelector];
-        }
-    }
-    return signature;
-}
-
-- (void)forwardInvocation:(NSInvocation *)invocation {
-    NSString *selString = NSStringFromSelector([invocation selector]);
-    if ([selString hasPrefix:@"_"]) {
-        SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-        if ([self respondsToSelector:cleanedSelector]) {
-            invocation.selector = cleanedSelector;
-            [invocation invokeWithTarget:self];
-        }
-    }else {
-        [super forwardInvocation:invocation];
-    }
-}
-
-@end
-
-
-@interface PSTCollectionViewLayout () {
-    __unsafe_unretained PSTCollectionView *_collectionView;
-    CGSize _collectionViewBoundsSize;
-    NSMutableDictionary *_initialAnimationLayoutAttributesDict;
-    NSMutableDictionary *_finalAnimationLayoutAttributesDict;
-    NSMutableIndexSet *_deletedSectionsSet;
-    NSMutableIndexSet *_insertedSectionsSet;
-    NSMutableDictionary *_decorationViewClassDict;
-    NSMutableDictionary *_decorationViewNibDict;
-    NSMutableDictionary *_decorationViewExternalObjectsTables;
-    char filler[200]; // [HACK] Our class needs to be larger than Apple's class for the superclass change to work.
-}
-@property (nonatomic, unsafe_unretained) PSTCollectionView *collectionView;
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewClassDict;
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewNibDict;
-@property (nonatomic, copy, readonly) NSDictionary *decorationViewExternalObjectsTables;
-@end
-
-@implementation PSTCollectionViewLayout
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)init {
-    if ((self = [super init])) {
-        _decorationViewClassDict = [NSMutableDictionary new];
-        _decorationViewNibDict = [NSMutableDictionary new];
-        _decorationViewExternalObjectsTables = [NSMutableDictionary new];
-        _initialAnimationLayoutAttributesDict = [NSMutableDictionary new];
-        _finalAnimationLayoutAttributesDict = [NSMutableDictionary new];
-        _insertedSectionsSet = [NSMutableIndexSet new];
-        _deletedSectionsSet = [NSMutableIndexSet new];
-    }
-    return self;
-}
-
-- (void)awakeFromNib {
-    [super awakeFromNib];
-}
-
-- (void)setCollectionView:(PSTCollectionView *)collectionView {
-    if (collectionView != _collectionView) {
-        _collectionView = collectionView;
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Invalidating the Layout
-
-- (void)invalidateLayout {
-    [[_collectionView collectionViewData] invalidate];
-    [_collectionView setNeedsLayout];
-}
-
-- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
-    // not sure about his..
-    if ((self.collectionView.bounds.size.width != newBounds.size.width) || (self.collectionView.bounds.size.height != newBounds.size.height)) {
-        return YES;
-    }
-    return NO;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Providing Layout Attributes
-
-+ (Class)layoutAttributesClass {
-    return PSTCollectionViewLayoutAttributes.class;
-}
-
-- (void)prepareLayout {
-}
-
-- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
-    return nil;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
-    return nil;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
-    return nil;
-}
-
-- (PSTCollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
-    return nil;
-}
-
-// return a point at which to rest after scrolling - for layouts that want snap-to-point scrolling behavior
-- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {
-    return proposedContentOffset;
-}
-
-- (CGSize)collectionViewContentSize {
-    return CGSizeZero;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Responding to Collection View Updates
-
-- (void)prepareForCollectionViewUpdates:(NSArray *)updateItems {
-    NSDictionary *update = [_collectionView currentUpdate];
-
-    for (PSTCollectionReusableView *view in [[_collectionView visibleViewsDict] objectEnumerator]) {
-        PSTCollectionViewLayoutAttributes *attr = [view.layoutAttributes copy];
-        if (attr) {
-            if (attr.isCell) {
-                NSUInteger index = [update[@"oldModel"] globalIndexForItemAtIndexPath:[attr indexPath]];
-                if (index != NSNotFound) {
-                    [attr setIndexPath:[attr indexPath]];
-                }
-            }
-            _initialAnimationLayoutAttributesDict[[PSTCollectionViewItemKey collectionItemKeyForLayoutAttributes:attr]] = attr;
-        }
-    }
-
-    PSTCollectionViewData *collectionViewData = [_collectionView collectionViewData];
-
-    CGRect bounds = [_collectionView visibleBoundRects];
-
-    for (PSTCollectionViewLayoutAttributes *attr in [collectionViewData layoutAttributesForElementsInRect:bounds]) {
-        if (attr.isCell) {
-            NSInteger index = (NSInteger)[collectionViewData globalIndexForItemAtIndexPath:attr.indexPath];
-
-            index = [update[@"newToOldIndexMap"][(NSUInteger)index] integerValue];
-            if (index != NSNotFound) {
-                PSTCollectionViewLayoutAttributes *finalAttrs = [attr copy];
-                [finalAttrs setIndexPath:[update[@"oldModel"] indexPathForItemAtGlobalIndex:index]];
-                [finalAttrs setAlpha:0];
-                _finalAnimationLayoutAttributesDict[[PSTCollectionViewItemKey collectionItemKeyForLayoutAttributes:finalAttrs]] = finalAttrs;
-            }
-        }
-    }
-
-    for (PSTCollectionViewUpdateItem *updateItem in updateItems) {
-        PSTCollectionUpdateAction action = updateItem.updateAction;
-
-        if ([updateItem isSectionOperation]) {
-            if (action == PSTCollectionUpdateActionReload) {
-                [_deletedSectionsSet addIndex:(NSUInteger)[[updateItem indexPathBeforeUpdate] section]];
-                [_insertedSectionsSet addIndex:(NSUInteger)[updateItem indexPathAfterUpdate].section];
-            }
-            else {
-                NSMutableIndexSet *indexSet = action == PSTCollectionUpdateActionInsert ? _insertedSectionsSet : _deletedSectionsSet;
-                [indexSet addIndex:(NSUInteger)[updateItem indexPath].section];
-            }
-        }
-        else {
-            if (action == PSTCollectionUpdateActionDelete) {
-                PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:
-                        [updateItem indexPathBeforeUpdate]];
-
-                PSTCollectionViewLayoutAttributes *attrs = [_finalAnimationLayoutAttributesDict[key] copy];
-
-                if (attrs) {
-                    [attrs setAlpha:0];
-                    _finalAnimationLayoutAttributesDict[key] = attrs;
-                }
-            }
-            else if (action == PSTCollectionUpdateActionReload || action == PSTCollectionUpdateActionInsert) {
-                PSTCollectionViewItemKey *key = [PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:
-                        [updateItem indexPathAfterUpdate]];
-                PSTCollectionViewLayoutAttributes *attrs = [_initialAnimationLayoutAttributesDict[key] copy];
-
-                if (attrs) {
-                    [attrs setAlpha:0];
-                    _initialAnimationLayoutAttributesDict[key] = attrs;
-                }
-            }
-        }
-    }
-}
-
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
-    PSTCollectionViewLayoutAttributes *attrs = _initialAnimationLayoutAttributesDict[[PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:itemIndexPath]];
-
-    if ([_insertedSectionsSet containsIndex:(NSUInteger)[itemIndexPath section]]) {
-        attrs = [attrs copy];
-        [attrs setAlpha:0];
-    }
-    return attrs;
-}
-
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {
-    PSTCollectionViewLayoutAttributes *attrs = _finalAnimationLayoutAttributesDict[[PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:itemIndexPath]];
-
-    if ([_deletedSectionsSet containsIndex:(NSUInteger)[itemIndexPath section]]) {
-        attrs = [attrs copy];
-        [attrs setAlpha:0];
-    }
-    return attrs;
-
-}
-
-- (PSTCollectionViewLayoutAttributes *)initialLayoutAttributesForInsertedSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath {
-    PSTCollectionViewLayoutAttributes *attrs = _initialAnimationLayoutAttributesDict[[PSTCollectionViewItemKey collectionItemKeyForCellWithIndexPath:elementIndexPath]];
-
-    if ([_insertedSectionsSet containsIndex:(NSUInteger)[elementIndexPath section]]) {
-        attrs = [attrs copy];
-        [attrs setAlpha:0];
-    }
-    return attrs;
-
-}
-
-- (PSTCollectionViewLayoutAttributes *)finalLayoutAttributesForDeletedSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath {
-    return nil;
-}
-
-- (void)finalizeCollectionViewUpdates {
-    [_initialAnimationLayoutAttributesDict removeAllObjects];
-    [_finalAnimationLayoutAttributesDict removeAllObjects];
-    [_deletedSectionsSet removeAllIndexes];
-    [_insertedSectionsSet removeAllIndexes];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Registering Decoration Views
-
-- (void)registerClass:(Class)viewClass forDecorationViewOfKind:(NSString *)kind {
-    _decorationViewClassDict[kind] = viewClass;
-}
-
-- (void)registerNib:(UINib *)nib forDecorationViewOfKind:(NSString *)kind {
-    _decorationViewNibDict[kind] = nib;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Private
-
-- (void)setCollectionViewBoundsSize:(CGSize)size {
-    _collectionViewBoundsSize = size;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSCoding
-
-- (id)initWithCoder:(NSCoder *)coder {
-    if ((self = [self init])) {
-    }
-    return self;
-}
-
-- (void)encodeWithCoder:(NSCoder *)coder {}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - PSTCollection/UICollection interoperability
-
-#ifdef kPSUIInteroperabilityEnabled
-#import <objc/runtime.h>
-#import <objc/message.h>
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
-    NSMethodSignature *sig = [super methodSignatureForSelector:selector];
-    if(!sig) {
-        NSString *selString = NSStringFromSelector(selector);
-        if ([selString hasPrefix:@"_"]) {
-            SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-            sig = [super methodSignatureForSelector:cleanedSelector];
-        }
-    }
-    return sig;
-}
-
-- (void)forwardInvocation:(NSInvocation *)inv {
-    NSString *selString = NSStringFromSelector([inv selector]);
-    if ([selString hasPrefix:@"_"]) {
-        SEL cleanedSelector = NSSelectorFromString([selString substringFromIndex:1]);
-        if ([self respondsToSelector:cleanedSelector]) {
-            // dynamically add method for faster resolving
-            Method newMethod = class_getInstanceMethod(self.class, [inv selector]);
-            IMP underscoreIMP = imp_implementationWithBlock(^(id _self) {
-                return objc_msgSend(_self, cleanedSelector);
-            });
-            class_addMethod(self.class, [inv selector], underscoreIMP, method_getTypeEncoding(newMethod));
-            // invoke now
-            inv.selector = cleanedSelector;
-            [inv invokeWithTarget:self];
-        }
-    }else {
-        [super forwardInvocation:inv];
-    }
-}
-#endif
-
-@end

+ 0 - 41
Libraries external/PSTCollectionView/PSTCollectionViewUpdateItem.h

@@ -1,41 +0,0 @@
-//
-//  PSTCollectionViewUpdateItem.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//  Contributed by Sergey Gavrilyuk.
-//
-
-#import <Foundation/Foundation.h>
-
-typedef NS_ENUM(NSInteger, PSTCollectionUpdateAction) {
-    PSTCollectionUpdateActionInsert,
-    PSTCollectionUpdateActionDelete,
-    PSTCollectionUpdateActionReload,
-    PSTCollectionUpdateActionMove,
-    PSTCollectionUpdateActionNone
-};
-
-@interface PSTCollectionViewUpdateItem : NSObject
-
-@property (nonatomic, readonly, strong) NSIndexPath *indexPathBeforeUpdate; // nil for PSTCollectionUpdateActionInsert
-@property (nonatomic, readonly, strong) NSIndexPath *indexPathAfterUpdate;  // nil for PSTCollectionUpdateActionDelete
-@property (nonatomic, readonly, assign) PSTCollectionUpdateAction updateAction;
-
-
-- (id)initWithInitialIndexPath:(NSIndexPath *)arg1
-        finalIndexPath:(NSIndexPath *)arg2
-        updateAction:(PSTCollectionUpdateAction)arg3;
-
-- (id)initWithAction:(PSTCollectionUpdateAction)arg1
-        forIndexPath:(NSIndexPath *)indexPath;
-
-- (id)initWithOldIndexPath:(NSIndexPath *)arg1 newIndexPath:(NSIndexPath *)arg2;
-
-- (PSTCollectionUpdateAction)updateAction;
-
-- (NSComparisonResult)compareIndexPaths:(PSTCollectionViewUpdateItem *)otherItem;
-
-- (NSComparisonResult)inverseCompareIndexPaths:(PSTCollectionViewUpdateItem *)otherItem;
-
-@end

+ 0 - 117
Libraries external/PSTCollectionView/PSTCollectionViewUpdateItem.m

@@ -1,117 +0,0 @@
-//
-//  PSTCollectionViewUpdateItem.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//  Contributed by Sergey Gavrilyuk.
-//
-
-#import "PSTCollectionViewUpdateItem.h"
-#import "NSIndexPath+PSTCollectionViewAdditions.h"
-
-@interface PSTCollectionViewUpdateItem () {
-    NSIndexPath *_initialIndexPath;
-    NSIndexPath *_finalIndexPath;
-    PSTCollectionUpdateAction _updateAction;
-    id _gap;
-}
-@end
-
-@implementation PSTCollectionViewUpdateItem
-
-@synthesize updateAction = _updateAction;
-@synthesize indexPathBeforeUpdate = _initialIndexPath;
-@synthesize indexPathAfterUpdate = _finalIndexPath;
-
-- (id)initWithInitialIndexPath:(NSIndexPath *)initialIndexPath finalIndexPath:(NSIndexPath *)finalIndexPath updateAction:(PSTCollectionUpdateAction)updateAction {
-    if ((self = [super init])) {
-        _initialIndexPath = initialIndexPath;
-        _finalIndexPath = finalIndexPath;
-        _updateAction = updateAction;
-    }
-    return self;
-}
-
-- (id)initWithAction:(PSTCollectionUpdateAction)updateAction forIndexPath:(NSIndexPath *)indexPath {
-    if (updateAction == PSTCollectionUpdateActionInsert)
-        return [self initWithInitialIndexPath:nil finalIndexPath:indexPath updateAction:updateAction];
-    else if (updateAction == PSTCollectionUpdateActionDelete)
-        return [self initWithInitialIndexPath:indexPath finalIndexPath:nil updateAction:updateAction];
-    else if (updateAction == PSTCollectionUpdateActionReload)
-        return [self initWithInitialIndexPath:indexPath finalIndexPath:indexPath updateAction:updateAction];
-
-    return nil;
-}
-
-- (id)initWithOldIndexPath:(NSIndexPath *)oldIndexPath newIndexPath:(NSIndexPath *)newIndexPath {
-    return [self initWithInitialIndexPath:oldIndexPath finalIndexPath:newIndexPath updateAction:PSTCollectionUpdateActionMove];
-}
-
-- (NSString *)description {
-    NSString *action = nil;
-    switch (_updateAction) {
-        case PSTCollectionUpdateActionInsert: action = @"insert"; break;
-        case PSTCollectionUpdateActionDelete: action = @"delete"; break;
-        case PSTCollectionUpdateActionMove:   action = @"move";   break;
-        case PSTCollectionUpdateActionReload: action = @"reload"; break;
-        default: break;
-    }
-
-    return [NSString stringWithFormat:@"Index path before update (%@) index path after update (%@) action (%@).",  _initialIndexPath, _finalIndexPath, action];
-}
-
-- (void)setNewIndexPath:(NSIndexPath *)indexPath {
-    _finalIndexPath = indexPath;
-}
-
-- (void)setGap:(id)gap {
-    _gap = gap;
-}
-
-- (BOOL)isSectionOperation {
-    return (_initialIndexPath.item == NSNotFound || _finalIndexPath.item == NSNotFound);
-}
-
-- (NSIndexPath *)newIndexPath {
-    return _finalIndexPath;
-}
-
-- (id)gap {
-    return _gap;
-}
-
-- (PSTCollectionUpdateAction)action {
-    return _updateAction;
-}
-
-- (id)indexPath {
-    //TODO: check this
-    return _initialIndexPath;
-}
-
-- (NSComparisonResult)compareIndexPaths:(PSTCollectionViewUpdateItem *)otherItem {
-    NSComparisonResult result = NSOrderedSame;
-    NSIndexPath *selfIndexPath = nil;
-    NSIndexPath *otherIndexPath = nil;
-
-    switch (_updateAction) {
-        case PSTCollectionUpdateActionInsert:
-            selfIndexPath = _finalIndexPath;
-            otherIndexPath = [otherItem newIndexPath];
-            break;
-        case PSTCollectionUpdateActionDelete:
-            selfIndexPath = _initialIndexPath;
-            otherIndexPath = [otherItem indexPath];
-        default: break;
-    }
-
-    if (self.isSectionOperation) result = [@(selfIndexPath.section) compare:@(otherIndexPath.section)];
-    else result = [selfIndexPath compare:otherIndexPath];
-    return result;
-}
-
-- (NSComparisonResult)inverseCompareIndexPaths:(PSTCollectionViewUpdateItem *)otherItem {
-    return (NSComparisonResult)([self compareIndexPaths:otherItem] * -1);
-}
-
-@end

+ 0 - 43
Libraries external/PSTCollectionView/PSTGridLayoutInfo.h

@@ -1,43 +0,0 @@
-//
-//  PSTGridLayoutInfo.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@class PSTGridLayoutSection;
-
-/*
- Every PSTCollectionViewLayout has a PSTGridLayoutInfo attached.
- Is used extensively in PSTCollectionViewFlowLayout.
- */
-@interface PSTGridLayoutInfo : NSObject
-
-@property (nonatomic, strong, readonly) NSArray *sections;
-@property (nonatomic, strong) NSDictionary *rowAlignmentOptions;
-@property (nonatomic, assign) BOOL usesFloatingHeaderFooter;
-
-// Vertical/horizontal dimension (depending on horizontal)
-// Used to create row objects
-@property (nonatomic, assign) CGFloat dimension;
-
-@property (nonatomic, assign) BOOL horizontal;
-@property (nonatomic, assign) BOOL leftToRight;
-@property (nonatomic, assign) CGSize contentSize;
-
-// Frame for specific PSTGridLayoutItem.
-- (CGRect)frameForItemAtIndexPath:(NSIndexPath *)indexPath;
-
-// Add new section. Invalidates layout.
-- (PSTGridLayoutSection *)addSection;
-
-// forces the layout to recompute on next access
-// TODO; what's the parameter for?
-- (void)invalidate:(BOOL)arg;
-
-// Make a copy of the current state.
-- (PSTGridLayoutInfo *)snapshot;
-
-@end

+ 0 - 76
Libraries external/PSTCollectionView/PSTGridLayoutInfo.m

@@ -1,76 +0,0 @@
-//
-//  PSTGridLayoutInfo.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTGridLayoutInfo.h"
-#import "PSTGridLayoutSection.h"
-#import "PSTGridLayoutItem.h"
-
-@interface PSTGridLayoutInfo () {
-    NSMutableArray *_sections;
-    CGRect _visibleBounds;
-    CGSize _layoutSize;
-    BOOL _isValid;
-}
-@property (nonatomic, strong) NSMutableArray *sections;
-@end
-
-@implementation PSTGridLayoutInfo
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)init {
-    if ((self = [super init])) {
-        _sections = [NSMutableArray new];
-    }
-    return self;
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p dimension:%.1f horizontal:%d contentSize:%@ sections:%@>", NSStringFromClass(self.class), self, self.dimension, self.horizontal, NSStringFromCGSize(self.contentSize), self.sections];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (PSTGridLayoutInfo *)snapshot {
-    PSTGridLayoutInfo *layoutInfo = [self.class new];
-    layoutInfo.sections = (NSMutableArray *)self.sections;
-    layoutInfo.rowAlignmentOptions = self.rowAlignmentOptions;
-    layoutInfo.usesFloatingHeaderFooter = self.usesFloatingHeaderFooter;
-    layoutInfo.dimension = self.dimension;
-    layoutInfo.horizontal = self.horizontal;
-    layoutInfo.leftToRight = self.leftToRight;
-    layoutInfo.contentSize = self.contentSize;
-    return layoutInfo;
-}
-
-- (CGRect)frameForItemAtIndexPath:(NSIndexPath *)indexPath {
-    PSTGridLayoutSection *section = self.sections[(NSUInteger)indexPath.section];
-    CGRect itemFrame;
-    if (section.fixedItemSize) {
-        itemFrame = (CGRect){.size=section.itemSize};
-    }else {
-        itemFrame = [section.items[(NSUInteger)indexPath.item] itemFrame];
-    }
-    return itemFrame;
-}
-
-- (id)addSection {
-    PSTGridLayoutSection *section = [PSTGridLayoutSection new];
-    section.rowAlignmentOptions = self.rowAlignmentOptions;
-    section.layoutInfo = self;
-    [_sections addObject:section];
-    [self invalidate:NO];
-    return section;
-}
-
-- (void)invalidate:(BOOL)arg {
-    _isValid = NO;
-}
-
-@end

+ 0 - 19
Libraries external/PSTCollectionView/PSTGridLayoutItem.h

@@ -1,19 +0,0 @@
-//
-//  PSTGridLayoutItem.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@class PSTGridLayoutSection, PSTGridLayoutRow;
-
-// Represents a single grid item; only created for non-uniform-sized grids.
-@interface PSTGridLayoutItem : NSObject
-
-@property (nonatomic, unsafe_unretained) PSTGridLayoutSection *section;
-@property (nonatomic, unsafe_unretained) PSTGridLayoutRow *rowObject;
-@property (nonatomic, assign) CGRect itemFrame;
-
-@end

+ 0 - 19
Libraries external/PSTCollectionView/PSTGridLayoutItem.m

@@ -1,19 +0,0 @@
-//
-//  PSTGridLayoutItem.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTGridLayoutItem.h"
-
-@implementation PSTGridLayoutItem
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p itemFrame:%@>", NSStringFromClass(self.class), self, NSStringFromCGRect(self.itemFrame)];
-}
-
-@end

+ 0 - 43
Libraries external/PSTCollectionView/PSTGridLayoutRow.h

@@ -1,43 +0,0 @@
-//
-//  PSTGridLayoutRow.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@class PSTGridLayoutSection, PSTGridLayoutItem;
-
-@interface PSTGridLayoutRow : NSObject
-
-@property (nonatomic, unsafe_unretained) PSTGridLayoutSection *section;
-@property (nonatomic, strong, readonly) NSArray *items;
-@property (nonatomic, assign) CGSize rowSize;
-@property (nonatomic, assign) CGRect rowFrame;
-@property (nonatomic, assign) NSInteger index;
-@property (nonatomic, assign) BOOL complete;
-@property (nonatomic, assign) BOOL fixedItemSize;
-
-// @steipete addition for row-fastPath
-@property (nonatomic, assign) NSInteger itemCount;
-
-//- (PSTGridLayoutRow *)copyFromSection:(PSTGridLayoutSection *)section; // ???
-
-// Add new item to items array.
-- (void)addItem:(PSTGridLayoutItem *)item;
-
-// Layout current row (if invalid)
-- (void)layoutRow;
-
-// @steipete: Helper to save code in PSTCollectionViewFlowLayout.
-// Returns the item rects when fixedItemSize is enabled.
-- (NSArray *)itemRects;
-
-//  Set current row frame invalid.
-- (void)invalidate;
-
-// Copy a snapshot of the current row data
-- (PSTGridLayoutRow *)snapshot;
-
-@end

+ 0 - 193
Libraries external/PSTCollectionView/PSTGridLayoutRow.m

@@ -1,193 +0,0 @@
-//
-//  PSTGridLayoutRow.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTCollectionView.h"
-#import "PSTGridLayoutRow.h"
-#import "PSTGridLayoutSection.h"
-#import "PSTGridLayoutItem.h"
-#import "PSTGridLayoutInfo.h"
-
-@interface PSTGridLayoutRow () {
-    NSMutableArray *_items;
-    BOOL _isValid;
-    int _verticalAlignement;
-    int _horizontalAlignement;
-}
-@property (nonatomic, strong) NSArray *items;
-@end
-
-@implementation PSTGridLayoutRow
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)init {
-    if ((self = [super init])) {
-        _items = [NSMutableArray new];
-    }
-    return self;
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p frame:%@ index:%ld items:%@>", NSStringFromClass(self.class), self, NSStringFromCGRect(self.rowFrame), (long)self.index, self.items];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)invalidate {
-    _isValid = NO;
-    _rowSize = CGSizeZero;
-    _rowFrame = CGRectZero;
-}
-
-- (NSArray *)itemRects {
-    return [self layoutRowAndGenerateRectArray:YES];
-}
-
-- (void)layoutRow {
-    [self layoutRowAndGenerateRectArray:NO];
-}
-
-- (NSArray *)layoutRowAndGenerateRectArray:(BOOL)generateRectArray {
-    NSMutableArray *rects = generateRectArray ? [NSMutableArray array] : nil;
-    if (!_isValid || generateRectArray) {
-        // properties for aligning
-        BOOL isHorizontal = self.section.layoutInfo.horizontal;
-        BOOL isLastRow = self.section.indexOfImcompleteRow == self.index;
-        PSTFlowLayoutHorizontalAlignment horizontalAlignment = [self.section.rowAlignmentOptions[isLastRow ? PSTFlowLayoutLastRowHorizontalAlignmentKey : PSTFlowLayoutCommonRowHorizontalAlignmentKey] integerValue];
-
-        // calculate space that's left over if we would align it from left to right.
-        CGFloat leftOverSpace = self.section.layoutInfo.dimension;
-        if (isHorizontal) {
-            leftOverSpace -= self.section.sectionMargins.top + self.section.sectionMargins.bottom;
-        }else {
-            leftOverSpace -= self.section.sectionMargins.left + self.section.sectionMargins.right;
-        }
-
-        // calculate the space that we have left after counting all items.
-        // UICollectionView is smart and lays out items like they would have been placed on a full row
-        // So we need to calculate the "usedItemCount" with using the last item as a reference size.
-        // This allows us to correctly justify-place the items in the grid.
-        NSInteger usedItemCount = 0;
-        NSInteger itemIndex = 0;
-        CGFloat spacing = isHorizontal ? self.section.verticalInterstice : self.section.horizontalInterstice;
-        // the last row should justify as if it is filled with more (invisible) items so that the whole
-        // UICollectionView feels more like a grid than a random line of blocks
-        while (itemIndex < self.itemCount || isLastRow) {
-            CGFloat nextItemSize;
-            // first we need to find the size (width/height) of the next item to fit
-            if (!self.fixedItemSize) {
-                PSTGridLayoutItem *item = self.items[(NSUInteger)MIN(itemIndex, self.itemCount - 1)];
-                nextItemSize = isHorizontal ? item.itemFrame.size.height : item.itemFrame.size.width;
-            }else {
-                nextItemSize = isHorizontal ? self.section.itemSize.height : self.section.itemSize.width;
-            }
-
-            // the first item does not add a separator spacing,
-            // every one afterwards in the same row will need this spacing constant
-            if (itemIndex > 0) {
-                nextItemSize += spacing;
-            }
-
-            // check to see if we can at least fit an item (+separator if necessary)
-            if (leftOverSpace < nextItemSize) {
-                break;
-            }
-
-            // we need to maintain the leftover space after the maximum amount of items have
-            // occupied, so we know how to adjust equal spacing among all the items in a row
-            leftOverSpace -= nextItemSize;
-
-            itemIndex++;
-            usedItemCount = itemIndex;
-        }
-
-        // push everything to the right if right-aligning and divide in half for centered
-        // currently there is no public API supporting this behavior
-        CGPoint itemOffset = CGPointZero;
-        if (horizontalAlignment == PSTFlowLayoutHorizontalAlignmentRight) {
-            itemOffset.x += leftOverSpace;
-        }else if (horizontalAlignment == PSTFlowLayoutHorizontalAlignmentCentered ||
-                (horizontalAlignment == PSTFlowLayoutHorizontalAlignmentJustify && usedItemCount == 1)) {
-            // Special case one item row to split leftover space in half
-            itemOffset.x += leftOverSpace / 2;
-        }
-
-        // calculate the justified spacing among all items in a row if we are using
-        // the default PSTFlowLayoutHorizontalAlignmentJustify layout
-        CGFloat interSpacing = usedItemCount <= 1 ? 0 : leftOverSpace / (CGFloat)(usedItemCount - 1);
-
-        // calculate row frame as union of all items
-        CGRect frame = CGRectZero;
-        CGRect itemFrame = (CGRect){.size=self.section.itemSize};
-        for (itemIndex = 0; itemIndex < self.itemCount; itemIndex++) {
-            PSTGridLayoutItem *item = nil;
-            if (!self.fixedItemSize) {
-                item = self.items[(NSUInteger)itemIndex];
-                itemFrame = [item itemFrame];
-            }
-            // depending on horizontal/vertical for an item size (height/width),
-            // we add the minimum separator then an equally distributed spacing
-            // (since our default mode is justify) calculated from the total leftover
-            // space divided by the number of intervals
-            if (isHorizontal) {
-                itemFrame.origin.y = itemOffset.y;
-                itemOffset.y += itemFrame.size.height + self.section.verticalInterstice;
-                if (horizontalAlignment == PSTFlowLayoutHorizontalAlignmentJustify) {
-                    itemOffset.y += interSpacing;
-                }
-            }else {
-                itemFrame.origin.x = itemOffset.x;
-                itemOffset.x += itemFrame.size.width + self.section.horizontalInterstice;
-                if (horizontalAlignment == PSTFlowLayoutHorizontalAlignmentJustify) {
-                    itemOffset.x += interSpacing;
-                }
-            }
-            item.itemFrame = itemFrame; // might call nil; don't care
-            [rects addObject:[NSValue valueWithCGRect:itemFrame]];
-            frame = CGRectUnion(frame, itemFrame);
-        }
-        _rowSize = frame.size;
-        //        _rowFrame = frame; // set externally
-        _isValid = YES;
-    }
-    return rects;
-}
-
-- (void)addItem:(PSTGridLayoutItem *)item {
-    [_items addObject:item];
-    item.rowObject = self;
-    [self invalidate];
-}
-
-- (PSTGridLayoutRow *)snapshot {
-    PSTGridLayoutRow *snapshotRow = [self.class new];
-    snapshotRow.section = self.section;
-    snapshotRow.items = self.items;
-    snapshotRow.rowSize = self.rowSize;
-    snapshotRow.rowFrame = self.rowFrame;
-    snapshotRow.index = self.index;
-    snapshotRow.complete = self.complete;
-    snapshotRow.fixedItemSize = self.fixedItemSize;
-    snapshotRow.itemCount = self.itemCount;
-    return snapshotRow;
-}
-
-- (PSTGridLayoutRow *)copyFromSection:(PSTGridLayoutSection *)section {
-    return nil; // ???
-}
-
-- (NSInteger)itemCount {
-    if (self.fixedItemSize) {
-        return _itemCount;
-    }else {
-        return (NSInteger)self.items.count;
-    }
-}
-
-@end

+ 0 - 64
Libraries external/PSTCollectionView/PSTGridLayoutSection.h

@@ -1,64 +0,0 @@
-//
-//  PSTGridLayoutSection.h
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@class PSTGridLayoutInfo, PSTGridLayoutRow, PSTGridLayoutItem;
-
-@interface PSTGridLayoutSection : NSObject
-
-@property (nonatomic, strong, readonly) NSArray *items;
-@property (nonatomic, strong, readonly) NSArray *rows;
-
-// fast path for equal-size items
-@property (nonatomic, assign) BOOL fixedItemSize;
-@property (nonatomic, assign) CGSize itemSize;
-// depending on fixedItemSize, this either is a _ivar or queries items.
-@property (nonatomic, assign) NSInteger itemsCount;
-
-@property (nonatomic, assign) CGFloat verticalInterstice;
-@property (nonatomic, assign) CGFloat horizontalInterstice;
-@property (nonatomic, assign) UIEdgeInsets sectionMargins;
-
-@property (nonatomic, assign) CGRect frame;
-@property (nonatomic, assign) CGRect headerFrame;
-@property (nonatomic, assign) CGRect footerFrame;
-@property (nonatomic, assign) CGFloat headerDimension;
-@property (nonatomic, assign) CGFloat footerDimension;
-@property (nonatomic, unsafe_unretained) PSTGridLayoutInfo *layoutInfo;
-@property (nonatomic, strong) NSDictionary *rowAlignmentOptions;
-
-@property (nonatomic, assign, readonly) CGFloat otherMargin;
-@property (nonatomic, assign, readonly) CGFloat beginMargin;
-@property (nonatomic, assign, readonly) CGFloat endMargin;
-@property (nonatomic, assign, readonly) CGFloat actualGap;
-@property (nonatomic, assign, readonly) CGFloat lastRowBeginMargin;
-@property (nonatomic, assign, readonly) CGFloat lastRowEndMargin;
-@property (nonatomic, assign, readonly) CGFloat lastRowActualGap;
-@property (nonatomic, assign, readonly) BOOL lastRowIncomplete;
-@property (nonatomic, assign, readonly) NSInteger itemsByRowCount;
-@property (nonatomic, assign, readonly) NSInteger indexOfImcompleteRow; // typo as of iOS6B3
-
-//- (PSTGridLayoutSection *)copyFromLayoutInfo:(PSTGridLayoutInfo *)layoutInfo;
-
-// Faster variant of invalidate/compute
-- (void)recomputeFromIndex:(NSInteger)index;
-
-// Invalidate layout. Destroys rows.
-- (void)invalidate;
-
-// Compute layout. Creates rows.
-- (void)computeLayout;
-
-- (PSTGridLayoutItem *)addItem;
-
-- (PSTGridLayoutRow *)addRow;
-
-// Copy snapshot of current object
-- (PSTGridLayoutSection *)snapshot;
-
-@end

+ 0 - 210
Libraries external/PSTCollectionView/PSTGridLayoutSection.m

@@ -1,210 +0,0 @@
-//
-//  PSTGridLayoutSection.m
-//  PSPDFKit
-//
-//  Copyright (c) 2012-2013 Peter Steinberger. All rights reserved.
-//
-
-#import "PSTGridLayoutSection.h"
-#import "PSTGridLayoutItem.h"
-#import "PSTGridLayoutRow.h"
-#import "PSTGridLayoutInfo.h"
-
-@interface PSTGridLayoutSection () {
-    NSMutableArray *_items;
-    NSMutableArray *_rows;
-    BOOL _isValid;
-}
-@property (nonatomic, strong) NSArray *items;
-@property (nonatomic, strong) NSArray *rows;
-@property (nonatomic, assign) CGFloat otherMargin;
-@property (nonatomic, assign) CGFloat beginMargin;
-@property (nonatomic, assign) CGFloat endMargin;
-@property (nonatomic, assign) CGFloat actualGap;
-@property (nonatomic, assign) CGFloat lastRowBeginMargin;
-@property (nonatomic, assign) CGFloat lastRowEndMargin;
-@property (nonatomic, assign) CGFloat lastRowActualGap;
-@property (nonatomic, assign) BOOL lastRowIncomplete;
-@property (nonatomic, assign) NSInteger itemsByRowCount;
-@property (nonatomic, assign) NSInteger indexOfImcompleteRow;
-@end
-
-@implementation PSTGridLayoutSection
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - NSObject
-
-- (id)init {
-    if ((self = [super init])) {
-        _items = [NSMutableArray new];
-        _rows = [NSMutableArray new];
-    }
-    return self;
-}
-
-- (NSString *)description {
-    return [NSString stringWithFormat:@"<%@: %p itemCount:%ld frame:%@ rows:%@>", NSStringFromClass(self.class), self, (long)self.itemsCount, NSStringFromCGRect(self.frame), self.rows];
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark - Public
-
-- (void)invalidate {
-    _isValid = NO;
-    self.rows = [NSMutableArray array];
-}
-
-- (void)computeLayout {
-    if (!_isValid) {
-        NSAssert(self.rows.count == 0, @"No rows shall be at this point.");
-
-        // iterate over all items, turning them into rows.
-        CGSize sectionSize = CGSizeZero;
-        NSInteger rowIndex = 0;
-        NSInteger itemIndex = 0;
-        NSInteger itemsByRowCount = 0;
-        CGFloat dimensionLeft = 0;
-        PSTGridLayoutRow *row = nil;
-        // get dimension and compensate for section margin
-        CGFloat headerFooterDimension = self.layoutInfo.dimension;
-        CGFloat dimension = headerFooterDimension;
-
-        if (self.layoutInfo.horizontal) {
-            dimension -= self.sectionMargins.top + self.sectionMargins.bottom;
-            self.headerFrame = CGRectMake(sectionSize.width, 0, self.headerDimension, headerFooterDimension);
-            sectionSize.width += self.headerDimension + self.sectionMargins.left;
-        }else {
-            dimension -= self.sectionMargins.left + self.sectionMargins.right;
-            self.headerFrame = CGRectMake(0, sectionSize.height, headerFooterDimension, self.headerDimension);
-            sectionSize.height += self.headerDimension + self.sectionMargins.top;
-        }
-
-        CGFloat spacing = self.layoutInfo.horizontal ? self.verticalInterstice : self.horizontalInterstice;
-
-        do {
-            BOOL finishCycle = itemIndex >= self.itemsCount;
-            // TODO: fast path could even remove row creation and just calculate on the fly
-            PSTGridLayoutItem *item = nil;
-            if (!finishCycle) item = self.fixedItemSize ? nil : self.items[(NSUInteger)itemIndex];
-
-            CGSize itemSize = self.fixedItemSize ? self.itemSize : item.itemFrame.size;
-            CGFloat itemDimension = self.layoutInfo.horizontal ? itemSize.height : itemSize.width;
-            // first item of each row does not add spacing
-            if (itemsByRowCount > 0) itemDimension += spacing;
-            if (dimensionLeft < itemDimension || finishCycle) {
-                // finish current row
-                if (row) {
-                    // compensate last row
-                    self.itemsByRowCount = fmax(itemsByRowCount, self.itemsByRowCount);
-                    row.itemCount = itemsByRowCount;
-
-                    // if current row is done but there are still items left, increase the incomplete row counter
-                    if (!finishCycle) self.indexOfImcompleteRow = rowIndex;
-
-                    [row layoutRow];
-
-                    if (self.layoutInfo.horizontal) {
-                        row.rowFrame = CGRectMake(sectionSize.width, self.sectionMargins.top, row.rowSize.width, row.rowSize.height);
-                        sectionSize.height = MAX(row.rowSize.height, sectionSize.height);
-                        sectionSize.width += row.rowSize.width + (finishCycle ? 0 : self.horizontalInterstice);
-                    }else {
-                        row.rowFrame = CGRectMake(self.sectionMargins.left, sectionSize.height, row.rowSize.width, row.rowSize.height);
-                        sectionSize.height += row.rowSize.height + (finishCycle ? 0 : self.verticalInterstice);
-                        sectionSize.width = MAX(row.rowSize.width, sectionSize.width);
-                    }
-                }
-                // add new rows until the section is fully laid out
-                if (!finishCycle) {
-                    // create new row
-                    row.complete = YES; // finish up current row
-                    row = [self addRow];
-                    row.fixedItemSize = self.fixedItemSize;
-                    row.index = rowIndex;
-                    self.indexOfImcompleteRow = rowIndex;
-                    rowIndex++;
-                    // convert an item from previous row to current, remove spacing for first item
-                    if (itemsByRowCount > 0) itemDimension -= spacing;
-                    dimensionLeft = dimension - itemDimension;
-                    itemsByRowCount = 0;
-                }
-            }else {
-                dimensionLeft -= itemDimension;
-            }
-
-            // add item on slow path
-            if (item) [row addItem:item];
-
-            itemIndex++;
-            itemsByRowCount++;
-        } while (itemIndex <= self.itemsCount); // cycle once more to finish last row
-
-        if (self.layoutInfo.horizontal) {
-            sectionSize.width += self.sectionMargins.right;
-            self.footerFrame = CGRectMake(sectionSize.width, 0, self.footerDimension, headerFooterDimension);
-            sectionSize.width += self.footerDimension;
-        }else {
-            sectionSize.height += self.sectionMargins.bottom;
-            self.footerFrame = CGRectMake(0, sectionSize.height, headerFooterDimension, self.footerDimension);
-            sectionSize.height += self.footerDimension;
-        }
-
-        _frame = CGRectMake(0, 0, sectionSize.width, sectionSize.height);
-        _isValid = YES;
-    }
-}
-
-- (void)recomputeFromIndex:(NSInteger)index {
-    // TODO: use index.
-    [self invalidate];
-    [self computeLayout];
-}
-
-- (PSTGridLayoutItem *)addItem {
-    PSTGridLayoutItem *item = [PSTGridLayoutItem new];
-    item.section = self;
-    [_items addObject:item];
-    return item;
-}
-
-- (PSTGridLayoutRow *)addRow {
-    PSTGridLayoutRow *row = [PSTGridLayoutRow new];
-    row.section = self;
-    [_rows addObject:row];
-    return row;
-}
-
-- (PSTGridLayoutSection *)snapshot {
-    PSTGridLayoutSection *snapshotSection = [PSTGridLayoutSection new];
-    snapshotSection.items = [self.items copy];
-    snapshotSection.rows = [self.items copy];
-    snapshotSection.verticalInterstice = self.verticalInterstice;
-    snapshotSection.horizontalInterstice = self.horizontalInterstice;
-    snapshotSection.sectionMargins = self.sectionMargins;
-    snapshotSection.frame = self.frame;
-    snapshotSection.headerFrame = self.headerFrame;
-    snapshotSection.footerFrame = self.footerFrame;
-    snapshotSection.headerDimension = self.headerDimension;
-    snapshotSection.footerDimension = self.footerDimension;
-    snapshotSection.layoutInfo = self.layoutInfo;
-    snapshotSection.rowAlignmentOptions = self.rowAlignmentOptions;
-    snapshotSection.fixedItemSize = self.fixedItemSize;
-    snapshotSection.itemSize = self.itemSize;
-    snapshotSection.itemsCount = self.itemsCount;
-    snapshotSection.otherMargin = self.otherMargin;
-    snapshotSection.beginMargin = self.beginMargin;
-    snapshotSection.endMargin = self.endMargin;
-    snapshotSection.actualGap = self.actualGap;
-    snapshotSection.lastRowBeginMargin = self.lastRowBeginMargin;
-    snapshotSection.lastRowEndMargin = self.lastRowEndMargin;
-    snapshotSection.lastRowActualGap = self.lastRowActualGap;
-    snapshotSection.lastRowIncomplete = self.lastRowIncomplete;
-    snapshotSection.itemsByRowCount = self.itemsByRowCount;
-    snapshotSection.indexOfImcompleteRow = self.indexOfImcompleteRow;
-    return snapshotSection;
-}
-
-- (NSInteger)itemsCount {
-    return self.fixedItemSize ? _itemsCount : (NSInteger)self.items.count;
-}
-
-@end