-
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 #42 from grigaci/fix-collection-view-reload
Remove no content view from collectionview on reloadData.
- Loading branch information
Showing
6 changed files
with
146 additions
and
1 deletion.
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
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
16 changes: 16 additions & 0 deletions
16
BIObjCHelpersTests/Mocks/Views/CollectionView/BIMockCollectionViewDatasource.h
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,16 @@ | ||
// | ||
// BIMockCollectionViewDatasource.h | ||
// BIObjCHelpersTests | ||
// | ||
// Created by Bogdan Iusco on 12/02/2018. | ||
// Copyright © 2018 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface BIMockCollectionViewDatasource : NSObject<UICollectionViewDataSource> | ||
|
||
@property (nonatomic, copy, nullable, readwrite) NSInteger(^numberOfItemsInSectionCallback)(NSInteger); | ||
@property (nonatomic, copy, nullable, readwrite) UICollectionViewCell *__nonnull(^cellForItemAtIndexPathCallback)(NSIndexPath *__nonnull); | ||
|
||
@end |
30 changes: 30 additions & 0 deletions
30
BIObjCHelpersTests/Mocks/Views/CollectionView/BIMockCollectionViewDatasource.m
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 @@ | ||
// | ||
// BIMockCollectionViewDatasource.m | ||
// BIObjCHelpersTests | ||
// | ||
// Created by Bogdan Iusco on 12/02/2018. | ||
// Copyright © 2018 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIMockCollectionViewDatasource.h" | ||
|
||
@implementation BIMockCollectionViewDatasource | ||
|
||
#pragma mark - UICollectionViewDataSource methods | ||
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { | ||
if (self.numberOfItemsInSectionCallback) { | ||
return self.numberOfItemsInSectionCallback(section); | ||
} | ||
return 0; | ||
} | ||
|
||
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: | ||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { | ||
if (self.cellForItemAtIndexPathCallback) { | ||
return self.cellForItemAtIndexPathCallback(indexPath); | ||
} | ||
return [[UICollectionViewCell alloc] init]; | ||
} | ||
|
||
@end |
66 changes: 66 additions & 0 deletions
66
BIObjCHelpersTests/Tests/Views/CollectionView/BICollectionViewTestCase.m
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,66 @@ | ||
// | ||
// BICollectionViewTestCase.m | ||
// BIObjCHelpersTests | ||
// | ||
// Created by Bogdan Iusco on 12/02/2018. | ||
// Copyright © 2018 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BICollectionView.h" | ||
#import "BIScrollAdditionalViewBase.h" | ||
#import "UIScrollView+BIBatching.h" | ||
#import "BIMockCollectionViewDatasource.h" | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
@interface BICollectionViewTestCase : XCTestCase | ||
|
||
@property (nonatomic, strong, nullable) BICollectionView *collectionView; | ||
@property (nonatomic, strong, nullable) UICollectionViewLayout *layout; | ||
@property (nonatomic, strong, nullable) BIMockCollectionViewDatasource *datasource; | ||
|
||
@end | ||
|
||
@implementation BICollectionViewTestCase | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
CGRect frame = CGRectMake(0, 0, 100, 100); | ||
self.layout = [[UICollectionViewFlowLayout alloc] init]; | ||
self.collectionView = [[BICollectionView alloc] initWithFrame:frame collectionViewLayout:self.layout]; | ||
self.datasource = [[BIMockCollectionViewDatasource alloc] init]; | ||
self.datasource.numberOfItemsInSectionCallback = ^NSInteger(NSInteger section) { | ||
return 1; | ||
}; | ||
self.collectionView.dataSource = self.datasource; | ||
} | ||
|
||
#pragma mark - Test reloadData | ||
|
||
- (void)test_reloadData_no_content { | ||
BIScrollAdditionalViewBase *noContentView = [[BIScrollAdditionalViewBase alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | ||
self.collectionView.createAdditionalNoContentViewCallback = ^BIScrollAdditionalViewBase * _Nullable{ | ||
return noContentView; | ||
}; | ||
[self.collectionView addAdditionalNoContentView]; | ||
XCTAssertNotNil(noContentView.superview); | ||
|
||
[self.collectionView reloadData]; | ||
|
||
XCTAssertNil(noContentView.superview); | ||
} | ||
|
||
- (void)test_reloadData_loading { | ||
BIScrollAdditionalViewBase *loadingView = [[BIScrollAdditionalViewBase alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | ||
self.collectionView.createAdditionalLoadingContentViewCallback = ^BIScrollAdditionalViewBase * _Nullable{ | ||
return loadingView; | ||
}; | ||
[self.collectionView addAdditionalLoadingContentView]; | ||
XCTAssertNotNil(loadingView.superview); | ||
|
||
[self.collectionView reloadData]; | ||
|
||
XCTAssertNil(loadingView.superview); | ||
} | ||
|
||
@end |