-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from grigaci/features/collectionViewAdditions
Collection view additions
- Loading branch information
Showing
151 changed files
with
7,246 additions
and
4,263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ DerivedData | |
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
*.gcda | ||
*.gcno | ||
*.DS_Store | ||
|
||
# CocoaPods | ||
# | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// BIBatchHelpers.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Mihai Chifor on 8/31/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIScrollDetails.h" | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
/*! | ||
@abstract Determine if batch fetching should begin based on the state of the parameters. | ||
@param scrollDirection The current scrolling direction of the scroll view. | ||
@param bounds The bounds of the scrollview. | ||
@param contentSize The content size of the scrollview. | ||
@param targetOffset The offset that the scrollview will scroll to. | ||
@param leadingScreens How many screens in the remaining distance will trigger batch fetching. | ||
@return Whether or not the current state should proceed with batch fetching. | ||
@discussion This method is broken into a category for unit testing purposes and should be used with the BITableView and BICollectionView batch fetching API. | ||
*/ | ||
extern BOOL BIDisplayShouldFetchBatch(BIScrollDirection scrollDirection, | ||
CGRect bounds, | ||
CGSize contentSize, | ||
CGPoint targetOffset, | ||
CGFloat leadingScreens); | ||
|
||
extern const CGFloat kBIDefaultInfiniteScrollingLeadingScreens; | ||
extern const CGFloat kBITableFooterViewAnimationDuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// BIBatchHelpers.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Mihai Chifor on 8/31/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIBatchHelpers.h" | ||
|
||
BOOL BIDisplayShouldFetchBatch(BIScrollDirection scrollDirection, | ||
CGRect bounds, | ||
CGSize contentSize, | ||
CGPoint targetOffset, | ||
CGFloat leadingScreens) { | ||
|
||
// only Up and Left scrolls are currently supported (tail loading) | ||
if (scrollDirection != BIScrollDirectionLeft && scrollDirection != BIScrollDirectionUp) { | ||
return NO; | ||
} | ||
|
||
// no fetching for null states | ||
if (leadingScreens <= 0.0 || | ||
CGRectEqualToRect(bounds, CGRectZero)) { | ||
return NO; | ||
} | ||
|
||
CGFloat viewLength, offset, contentLength; | ||
|
||
if (scrollDirection == BIScrollDirectionUp) { | ||
viewLength = bounds.size.height; | ||
offset = targetOffset.y; | ||
contentLength = contentSize.height; | ||
} else { // horizontal | ||
viewLength = bounds.size.width; | ||
offset = targetOffset.x; | ||
contentLength = contentSize.width; | ||
} | ||
|
||
// target offset will always be 0 if the content size is smaller than the viewport | ||
BOOL hasSmallContent = offset == 0.0 && contentLength < viewLength; | ||
|
||
CGFloat triggerDistance = viewLength * leadingScreens; | ||
CGFloat remainingDistance = contentLength - viewLength - offset; | ||
|
||
return hasSmallContent || remainingDistance <= triggerDistance; | ||
} | ||
|
||
const CGFloat kBIDefaultInfiniteScrollingLeadingScreens = .5f; | ||
const CGFloat kBITableFooterViewAnimationDuration = .25f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// BIBatchRequest.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
FOUNDATION_EXPORT const NSInteger kDefaultBatchRequestSize; | ||
|
||
@class BIBatchResponse; | ||
|
||
typedef void(^BIBatchRequestCompletionBlock)(BIBatchResponse * __nonnull response); | ||
|
||
/*! | ||
@brief Helper values for batch insert position. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, BIBatchInsertPosition) { | ||
/*! | ||
* @brief insert new elements at the beggining. | ||
*/ | ||
BIBatchInsertPositionTop = 0, | ||
/*! | ||
* @brief insert new elements at the end. | ||
*/ | ||
BIBatchInsertPositionBottom = UINT_MAX | ||
}; | ||
|
||
/*! | ||
* @brief Defines a set of data request values. | ||
* Mostly used in table and collection views for inserting sets of data. | ||
*/ | ||
@interface BIBatchRequest : NSObject | ||
|
||
/*! | ||
* @brief Designated initializer for a table view batch. | ||
* @param sectionIndex The index of the section where to fetch data. | ||
* @param batchSize The size of the batch to fetch. | ||
* @param completionBlock Code block to be called when fetching is done or in case of error. | ||
*/ | ||
- (nonnull instancetype)initWithSection:(NSUInteger)sectionIndex | ||
batchSize:(NSUInteger)batchSize | ||
completionBlock:(nullable BIBatchRequestCompletionBlock)completionBlock NS_DESIGNATED_INITIALIZER; | ||
|
||
/*! | ||
* @brief Convenience kDefaultTableViewBatchSize for a table view batch. | ||
* @discussion Fetches kCardDefaultBatchSize elements in section index 0. | ||
* @param completionBlock Code block to be called when fetching is done or in case of error. | ||
*/ | ||
- (nonnull instancetype)initWithCompletionBlock:(nullable BIBatchRequestCompletionBlock)completionBlock; | ||
|
||
/*! | ||
* @brief Size of the batch that is fetching. | ||
*/ | ||
@property (nonatomic, assign, readonly) NSUInteger batchSize; | ||
|
||
/*! | ||
* @brief Section index for which data is fetching. | ||
*/ | ||
@property (nonatomic, assign, readonly) NSUInteger sectionIndex; | ||
|
||
/*! | ||
* @brief Code block to be called when fetching is done or in case of error. | ||
*/ | ||
@property (nonatomic, copy, nullable, readonly) BIBatchRequestCompletionBlock completionBlock; | ||
|
||
/*! | ||
* @brief Specify an index from where to start inserting the new elements that will be fetched. | ||
* Defaults to BIBatchInsertPositionBottom; | ||
*/ | ||
@property (nonatomic, assign) NSUInteger insertPosition; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// BIBatchRequest.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIBatchRequest.h" | ||
|
||
const NSInteger kDefaultBatchRequestSize = 3; | ||
|
||
@interface BIBatchRequest () | ||
|
||
@property (nonatomic, assign, readwrite) NSUInteger batchSize; | ||
@property (nonatomic, assign, readwrite) NSUInteger sectionIndex; | ||
@property (nonatomic, copy, nullable, readwrite) BIBatchRequestCompletionBlock completionBlock; | ||
|
||
@end | ||
|
||
|
||
@implementation BIBatchRequest | ||
|
||
#pragma mark - Init methods | ||
|
||
- (instancetype)initWithSection:(NSUInteger)sectionIndex | ||
batchSize:(NSUInteger)batchSize | ||
completionBlock:(BIBatchRequestCompletionBlock)completionBlock { | ||
self = [super init]; | ||
if (self) { | ||
self.sectionIndex = sectionIndex; | ||
self.batchSize = batchSize; | ||
self.completionBlock = completionBlock; | ||
self.insertPosition = BIBatchInsertPositionBottom; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithCompletionBlock:(BIBatchRequestCompletionBlock)completionBlock { | ||
return [self initWithSection:0 | ||
batchSize:kDefaultBatchRequestSize | ||
completionBlock:completionBlock]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// BIBatchResponse.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class BIBatchRequest; | ||
|
||
@interface BIBatchResponse : NSObject | ||
|
||
+ (nonnull instancetype)batchResponseForRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths; | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths; | ||
|
||
- (nonnull instancetype)init NS_UNAVAILABLE; | ||
+ (nonnull instancetype)new NS_UNAVAILABLE; | ||
|
||
@property (nonatomic, strong, nullable, readonly) NSError *error; | ||
@property (nonatomic, copy, nullable, readonly) NSArray *indexPaths; | ||
@property (nonatomic, strong, nullable, readonly) BIBatchRequest *batchRequest; | ||
|
||
@end | ||
|
||
@interface BIBatchResponse (UITableView) | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
tableView:(nonnull UITableView *)tableView | ||
countNewItems:(NSUInteger)countNewItems; | ||
|
||
@end | ||
|
||
@interface BIBatchResponse (UICollectionView) | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
collectionView:(nonnull UICollectionView *)collectionView | ||
countNewItems:(NSUInteger)countNewItems; | ||
|
||
@end |
Oops, something went wrong.