mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 17:28:22 +00:00
Add isLast/FirstSection API to IGListSectionController
Summary: Product needs show that section controllers need some sort of awarenes when they are the first/last section in a list (e.g. for cell borders). Adding this simple API, non-breaking. Reviewed By: jessesquires Differential Revision: D4016023 fbshipit-source-id: c75f9298fc73875a1cabad191fe2db6cb9ee4376
This commit is contained in:
parent
4863974f9d
commit
394760081c
5 changed files with 45 additions and 1 deletions
|
|
@ -5,7 +5,7 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
|
|||
## Master
|
||||
|
||||
- Fixed `-[IGListAdapter reloadDataWithCompletion:]` not returning early when `collectionView` or `dataSource` is nil and `completion` is nil. [Ben Asher](https://github.com/benasher44) [#51](https://github.com/Instagram/IGListKit/pull/51)
|
||||
|
||||
- Added `-isFirstSection` and `-isLastSection` APIs to `IGListSectionController`
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
|
|
|
|||
|
|
@ -386,6 +386,9 @@
|
|||
// for IGListSectionController subclasses after calling [super init]
|
||||
IGListSectionControllerPushThread(self.viewController, self);
|
||||
|
||||
id firstObject = objects.firstObject;
|
||||
id lastObject = objects.lastObject;
|
||||
|
||||
for (id object in objects) {
|
||||
// infra checks to see if a controller exists
|
||||
IGListSectionController <IGListSectionType> *sectionController = [map sectionControllerForObject:object];
|
||||
|
|
@ -403,6 +406,8 @@
|
|||
// in case the section controller was created outside of -listAdapter:sectionControllerForObject:
|
||||
sectionController.collectionContext = self;
|
||||
sectionController.viewController = self.viewController;
|
||||
sectionController.isFirstSection = (object == firstObject);
|
||||
sectionController.isLastSection = (object == lastObject);
|
||||
|
||||
// check if the item has changed instances or is new
|
||||
const NSUInteger oldSection = [map sectionForObject:object];
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@
|
|||
*/
|
||||
@property (nonatomic, weak, nullable, readonly) id <IGListCollectionContext> collectionContext;
|
||||
|
||||
/**
|
||||
Returns YES if the section controller is the first section in the list.
|
||||
*/
|
||||
@property (nonatomic, assign, readonly) BOOL isFirstSection;
|
||||
|
||||
/**
|
||||
Returns YES if the section controller is the last section in the list.
|
||||
*/
|
||||
@property (nonatomic, assign, readonly) BOOL isLastSection;
|
||||
|
||||
/**
|
||||
The margins used to lay out content in the section controller.
|
||||
|
||||
|
|
|
|||
|
|
@ -19,4 +19,8 @@ FOUNDATION_EXTERN void IGListSectionControllerPopThread(void);
|
|||
|
||||
@property (nonatomic, weak, readwrite) UIViewController *viewController;
|
||||
|
||||
@property (nonatomic, assign, readwrite) BOOL isFirstSection;
|
||||
|
||||
@property (nonatomic, assign, readwrite) BOOL isLastSection;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -452,4 +452,29 @@
|
|||
XCTAssertNil(weakSectionController);
|
||||
}
|
||||
|
||||
- (void)test_whenAdapterUpdatedTwice_withThreeSections_thatSectionsUpdatedFirstLast {
|
||||
self.dataSource.objects = @[@0, @1, @2];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
|
||||
XCTAssertTrue([[self.adapter sectionControllerForObject:@0] isFirstSection]);
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@1] isFirstSection]);
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@2] isFirstSection]);
|
||||
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@0] isLastSection]);
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@1] isLastSection]);
|
||||
XCTAssertTrue([[self.adapter sectionControllerForObject:@2] isLastSection]);
|
||||
|
||||
// update and shift objects to test that first/last flags are also updated
|
||||
self.dataSource.objects = @[@2, @0, @1];
|
||||
[self.adapter performUpdatesAnimated:NO completion:nil];
|
||||
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@0] isFirstSection]);
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@1] isFirstSection]);
|
||||
XCTAssertTrue([[self.adapter sectionControllerForObject:@2] isFirstSection]);
|
||||
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@0] isLastSection]);
|
||||
XCTAssertTrue([[self.adapter sectionControllerForObject:@1] isLastSection]);
|
||||
XCTAssertFalse([[self.adapter sectionControllerForObject:@2] isLastSection]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Reference in a new issue