Skip to content

Commit

Permalink
Merge pull request #42 from grigaci/fix-collection-view-reload
Browse files Browse the repository at this point in the history
Remove no content view from collectionview on reloadData.
  • Loading branch information
grigaci committed Feb 12, 2018
2 parents 796eb0d + fc09afb commit 512dde3
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BIObjCHelpers.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BIObjCHelpers"
s.version = "0.4.2"
s.version = "0.4.3"
s.summary = "My collection of Objective-C helpers"
s.description = <<-DESC
Simple collection of classes commonly used in Objective-C projects.
Expand Down
26 changes: 26 additions & 0 deletions BIObjCHelpers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
43FA5D671CD2327200FA754E /* BILaunchStartersFactoryTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 943700831BCD4E250063D2CC /* BILaunchStartersFactoryTestCase.m */; };
43FA5D681CD2327600FA754E /* BIMockStarter.m in Sources */ = {isa = PBXBuildFile; fileRef = 43BE6CF61B568ECB001F0A00 /* BIMockStarter.m */; };
43FA5D691CD2381E00FA754E /* DefaultData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 43BE6CD31B568CC7001F0A00 /* DefaultData.plist */; };
8B6246B02031AAAE005989DB /* BICollectionViewTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B6246AF2031AAAE005989DB /* BICollectionViewTestCase.m */; };
8B6246B42031AD22005989DB /* BIMockCollectionViewDatasource.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B6246B32031AD22005989DB /* BIMockCollectionViewDatasource.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -241,6 +243,9 @@
43F541CC1CD0F276002EB6C6 /* BIObjCHelpersTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BIObjCHelpersTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
43FA5D4A1CD2310300FA754E /* BIObjCHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BIObjCHelpers.h; sourceTree = "<group>"; };
43FA5D4B1CD2310300FA754E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8B6246AF2031AAAE005989DB /* BICollectionViewTestCase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = BICollectionViewTestCase.m; path = Views/CollectionView/BICollectionViewTestCase.m; sourceTree = "<group>"; };
8B6246B22031AD22005989DB /* BIMockCollectionViewDatasource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = BIMockCollectionViewDatasource.h; path = Mocks/Views/CollectionView/BIMockCollectionViewDatasource.h; sourceTree = "<group>"; };
8B6246B32031AD22005989DB /* BIMockCollectionViewDatasource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = BIMockCollectionViewDatasource.m; path = Mocks/Views/CollectionView/BIMockCollectionViewDatasource.m; sourceTree = "<group>"; };
914D2CB41B57BB41009A9B4D /* BIBatchHelpersTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIBatchHelpersTestCase.m; sourceTree = "<group>"; };
91614A811B94790400D00EB2 /* _BIScrollViewProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = _BIScrollViewProxy.h; path = Utils/Proxy/_BIScrollViewProxy.h; sourceTree = "<group>"; };
91614A821B94790400D00EB2 /* _BIScrollViewProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = _BIScrollViewProxy.m; path = Utils/Proxy/_BIScrollViewProxy.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -854,6 +859,7 @@
43D3BFF81D12FCA4000C840C /* Views */ = {
isa = PBXGroup;
children = (
8B6246B12031AD01005989DB /* CollectionView */,
43D3BFF91D12FCA7000C840C /* TableView */,
);
name = Views;
Expand Down Expand Up @@ -897,6 +903,7 @@
43DA59491B6217A900ECAAC0 /* Views */ = {
isa = PBXGroup;
children = (
8B6246AE2031AA8E005989DB /* CollectionView */,
43DA594A1B6217B200ECAAC0 /* TableView */,
);
name = Views;
Expand All @@ -920,6 +927,23 @@
path = BIObjCHelpers/SupportingFiles;
sourceTree = SOURCE_ROOT;
};
8B6246AE2031AA8E005989DB /* CollectionView */ = {
isa = PBXGroup;
children = (
8B6246AF2031AAAE005989DB /* BICollectionViewTestCase.m */,
);
name = CollectionView;
sourceTree = "<group>";
};
8B6246B12031AD01005989DB /* CollectionView */ = {
isa = PBXGroup;
children = (
8B6246B22031AD22005989DB /* BIMockCollectionViewDatasource.h */,
8B6246B32031AD22005989DB /* BIMockCollectionViewDatasource.m */,
);
name = CollectionView;
sourceTree = "<group>";
};
914D2CAF1B5792CD009A9B4D /* Views */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1209,6 +1233,7 @@
43D3BFF71D12E592000C840C /* MockUINib.m in Sources */,
43FA5D611CD2325B00FA754E /* BIMockDatasourceFeedTableView.m in Sources */,
43FA5D651CD2326A00FA754E /* BIOperationQueueTestCase.m in Sources */,
8B6246B42031AD22005989DB /* BIMockCollectionViewDatasource.m in Sources */,
43A5B5571CFD733300F79359 /* BIOperationBaseTestCase.m in Sources */,
43FA5D541CD2321E00FA754E /* BITableViewTestCase.m in Sources */,
43FA5D661CD2326F00FA754E /* BIStartersFactoryTestCase.m in Sources */,
Expand All @@ -1220,6 +1245,7 @@
43FA5D671CD2327200FA754E /* BILaunchStartersFactoryTestCase.m in Sources */,
43FA5D501CD2320700FA754E /* NSString+RandomTest.m in Sources */,
43FA5D511CD2320A00FA754E /* BITestCaseCoreData.m in Sources */,
8B6246B02031AAAE005989DB /* BICollectionViewTestCase.m in Sources */,
43FA5D5F1CD2325400FA754E /* BIDatasourceFeedTableViewTestCase.m in Sources */,
43FA5D631CD2326400FA754E /* BILifecycleTestCase.m in Sources */,
43D3BFEB1D12DF5D000C840C /* MockBIHandlerTableView.m in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions BIObjCHelpers/Views/CollectionView/BICollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ - (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths {
}
}

- (void)reloadData {
[super reloadData];
if ([self BI_totalNumberOfRows] != 0 && self.visibleAdditionalView) {
[self removeVisibleAdditionalView];
}
}

#pragma mark - Public methods

- (void)triggerPullToRefresh {
Expand Down
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
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
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

0 comments on commit 512dde3

Please sign in to comment.