Skip to content

Commit

Permalink
Merge pull request #7 from grigaci/features/collectionViewAdditions
Browse files Browse the repository at this point in the history
Collection view additions
  • Loading branch information
grigaci committed Oct 19, 2015
2 parents 5779306 + fb8f576 commit c80d90f
Show file tree
Hide file tree
Showing 151 changed files with 7,246 additions and 4,263 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
*.gcda
*.gcno
*.DS_Store

# CocoaPods
#
Expand Down
202 changes: 147 additions & 55 deletions BIObjCHelpers.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
ReferencedContainer = "container:BIObjCHelpers.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "FB_REFERENCE_IMAGE_DIR"
value = "$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
BlueprintName = "BIObjCHelpersTests"
ReferencedContainer = "container:BIObjCHelpers.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "BIActivityIndicatorContainerViewTestCase">
</Test>
<Test
Identifier = "BITableViewCellTestCase">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<MacroExpansion>
Expand Down Expand Up @@ -67,6 +75,13 @@
ReferencedContainer = "container:BIObjCHelpers.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "FB_REFERENCE_IMAGE_DIR"
value = "$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT const NSInteger kDefaultTableViewBatchSize;
FOUNDATION_EXPORT const NSInteger kDefaultBatchSize;

typedef void(^BITableViewBatchCompletionBlock)(NSError * __nullable error, NSArray * __nullable newIndexPaths);
typedef void(^BIBatchCompletionBlock)(NSError * __nullable error, NSArray * __nullable newIndexPaths);

@interface BITableViewBatch : NSObject
@interface BIBatch : NSObject// __deprecated_msg("Use BIBatchRequest")

/*!
* @brief Designated initializer for a table view batch.
Expand All @@ -22,14 +22,14 @@ typedef void(^BITableViewBatchCompletionBlock)(NSError * __nullable error, NSArr
*/
- (nonnull instancetype)initWithSection:(NSUInteger)sectionIndex
batchSize:(NSUInteger)batchSize
completionBlock:(nullable BITableViewBatchCompletionBlock)completionBlock NS_DESIGNATED_INITIALIZER;
completionBlock:(nullable BIBatchCompletionBlock)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 BITableViewBatchCompletionBlock)completionBlock;
- (nonnull instancetype)initWithCompletionBlock:(nullable BIBatchCompletionBlock)completionBlock;

/*!
* @brief Size of the batch that is fetching.
Expand All @@ -44,6 +44,6 @@ typedef void(^BITableViewBatchCompletionBlock)(NSError * __nullable error, NSArr
/*!
* @brief Code block to be called when fetching is done or in case of error.
*/
@property (nonatomic, copy, nullable, readonly) BITableViewBatchCompletionBlock completionBlock;
@property (nonatomic, copy, nullable, readonly) BIBatchCompletionBlock completionBlock;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
// Copyright (c) 2015 Bogdan Iusco. All rights reserved.
//

#import "BITableViewBatch.h"
#import "BIBatch.h"

const NSInteger kDefaultTableViewBatchSize = 3;
const NSInteger kDefaultBatchSize = 3;

@interface BITableViewBatch ()
@interface BIBatch ()

@property (nonatomic, assign, readwrite) NSUInteger batchSize;
@property (nonatomic, assign, readwrite) NSUInteger sectionIndex;
@property (nonatomic, copy, nullable, readwrite) BITableViewBatchCompletionBlock completionBlock;
@property (nonatomic, copy, nullable, readwrite) BIBatchCompletionBlock completionBlock;

@end


@implementation BITableViewBatch
@implementation BIBatch

#pragma mark - Init methods

- (instancetype)initWithSection:(NSUInteger)sectionIndex
batchSize:(NSUInteger)batchSize
completionBlock:(BITableViewBatchCompletionBlock)completionBlock {
completionBlock:(BIBatchCompletionBlock)completionBlock {
self = [super init];
if (self) {
self.sectionIndex = sectionIndex;
Expand All @@ -35,9 +35,9 @@ - (instancetype)initWithSection:(NSUInteger)sectionIndex
return self;
}

- (instancetype)initWithCompletionBlock:(BITableViewBatchCompletionBlock)completionBlock {
- (instancetype)initWithCompletionBlock:(BIBatchCompletionBlock)completionBlock {
return [self initWithSection:0
batchSize:kDefaultTableViewBatchSize
batchSize:kDefaultBatchSize
completionBlock:completionBlock];
}

Expand Down
30 changes: 30 additions & 0 deletions BIObjCHelpers/Batch/BIBatchHelpers.h
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;
50 changes: 50 additions & 0 deletions BIObjCHelpers/Batch/BIBatchHelpers.m
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;
75 changes: 75 additions & 0 deletions BIObjCHelpers/Batch/BIBatchRequest.h
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
45 changes: 45 additions & 0 deletions BIObjCHelpers/Batch/BIBatchRequest.m
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
46 changes: 46 additions & 0 deletions BIObjCHelpers/Batch/BIBatchResponse.h
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
Loading

0 comments on commit c80d90f

Please sign in to comment.