Skip to content

Commit

Permalink
Rename sectionIndex API to just section
Browse files Browse the repository at this point in the history
Summary:
Quick rename before releasing 3.0 to get this API in parity w/ `isFirstSection` and `isLastSection`. My b I should have caught this in review.

Closes #720

Reviewed By: jessesquires, amonshiz

Differential Revision: D5031184

fbshipit-source-id: 1cd7b00c8b32084fecd861e78808eea0d0056337
  • Loading branch information
Ryan Nystrom authored and facebook-github-bot committed May 11, 2017
1 parent 7304fe8 commit 0a41691
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ final class DisplaySectionController: ListSectionController, ListDisplayDelegate

override func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
cell.text = "Section \(self.sectionIndex), cell \(index)"
cell.text = "Section \(self.section), cell \(index)"
return cell
}

// MARK: ListDisplayDelegate

func listAdapter(_ listAdapter: ListAdapter, willDisplay sectionController: ListSectionController) {
print("Will display section \(self.sectionIndex)")
print("Will display section \(self.section)")
}

func listAdapter(_ listAdapter: ListAdapter, willDisplay sectionController: ListSectionController, cell: UICollectionViewCell, at index: Int) {
print("Did will display cell \(index) in section \(self.sectionIndex)")
print("Did will display cell \(index) in section \(self.section)")
}

func listAdapter(_ listAdapter: ListAdapter, didEndDisplaying sectionController: ListSectionController) {
print("Did end displaying section \(self.sectionIndex)")
print("Did end displaying section \(self.section)")
}

func listAdapter(_ listAdapter: ListAdapter, didEndDisplaying sectionController: ListSectionController, cell: UICollectionViewCell, at index: Int) {
print("Did end displaying cell \(index) in section \(self.sectionIndex)")
print("Did end displaying cell \(index) in section \(self.section)")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ListeningSectionController: ListSectionController, IncrementListener
}

func configureCell(cell: LabelCell) {
cell.text = "Section: \(self.sectionIndex), value: \(value)"
cell.text = "Section: \(self.section), value: \(value)"
}

// MARK: ListSectionController Overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class WorkingRangeSectionController: ListSectionController, ListWorkingRan
let url = URL(string: urlString)
else { return }

print("Downloading image \(urlString) for section \(self.sectionIndex)")
print("Downloading image \(urlString) for section \(self.section)")

task = URLSession.shared.dataTask(with: url) { data, response, err in
guard let data = data, let image = UIImage(data: data) else {
Expand Down
7 changes: 5 additions & 2 deletions Source/IGListSectionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ NS_SWIFT_NAME(ListSectionController)
@property (nonatomic, weak, nullable, readonly) id <IGListCollectionContext> collectionContext;

/**
Returns the index within the list for this section controller.
Returns the section within the list for this section controller.
@note This value also relates to the section within a `UICollectionView` that this section controller's cells belong.
It also relates to the `-[NSIndexPath section]` value for individual cells within the collection view.
*/
@property (nonatomic, assign, readonly) NSInteger sectionIndex;
@property (nonatomic, assign, readonly) NSInteger section;

/**
Returns `YES` if the section controller is the first section in the list, `NO` otherwise.
Expand Down
2 changes: 1 addition & 1 deletion Source/IGListSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (instancetype)init {
_minimumInteritemSpacing = 0.0;
_minimumLineSpacing = 0.0;
_inset = UIEdgeInsetsZero;
_sectionIndex = NSNotFound;
_section = NSNotFound;
}
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {

- (void)didUpdateToObject:(id)object {
for (IGListSectionController *sectionController in self.sectionControllers) {
sectionController.sectionIndex = self.sectionIndex;
sectionController.section = self.section;
[sectionController didUpdateToObject:object];
}
[self reloadData];
Expand Down
2 changes: 1 addition & 1 deletion Source/Internal/IGListSectionControllerInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FOUNDATION_EXTERN void IGListSectionControllerPopThread(void);

@property (nonatomic, weak, readwrite) UIViewController *viewController;

@property (nonatomic, assign, readwrite) NSInteger sectionIndex;
@property (nonatomic, assign, readwrite) NSInteger section;

@property (nonatomic, assign, readwrite) BOOL isFirstSection;

Expand Down
4 changes: 2 additions & 2 deletions Source/Internal/IGListSectionMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)updateWithObjects:(NSArray *)objects sectionControllers:(NSArray *)secti

sectionController.isFirstSection = (object == firstObject);
sectionController.isLastSection = (object == lastObject);
sectionController.sectionIndex = (NSInteger)idx;
sectionController.section = (NSInteger)idx;
}];
}

Expand Down Expand Up @@ -109,7 +109,7 @@ - (NSInteger)sectionForObject:(id)object {

- (void)reset {
[self enumerateUsingBlock:^(id _Nonnull object, IGListSectionController * _Nonnull sectionController, NSInteger section, BOOL * _Nonnull stop) {
sectionController.sectionIndex = NSNotFound;
sectionController.section = NSNotFound;
sectionController.isFirstSection = NO;
sectionController.isLastSection = NO;
}];
Expand Down
2 changes: 1 addition & 1 deletion Tests/IGListAdapterE2ETests.m
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ - (void)test_whenQueryingCollectionContext_withNewItemInstances_thatSectionMatch
__weak __typeof__(sectionController) weakSectionController = sectionController;
sectionController.itemUpdateBlock = ^{
executedUpdateBlock = YES;
XCTAssertEqual(weakSectionController.sectionIndex, 1);
XCTAssertEqual(weakSectionController.section, 1);
};

[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished3) {
Expand Down
45 changes: 22 additions & 23 deletions Tests/IGListAdapterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1098,26 +1098,26 @@ - (void)test_whenInsertingAtBeginning_thatAllSectionControllerIndexesUpdateCorre
[self.adapter performUpdatesAnimated:NO completion:nil];

IGListSectionController *controller1a = [self.adapter sectionControllerForObject:one];
XCTAssertEqual(controller1a.sectionIndex, 0);
XCTAssertEqual(controller1a.section, 0);
XCTAssertTrue(controller1a.isFirstSection);

XCTAssertEqual([self.adapter sectionControllerForObject:two].sectionIndex, 1);
XCTAssertEqual([self.adapter sectionControllerForObject:three].sectionIndex, 2);
XCTAssertEqual([self.adapter sectionControllerForObject:two].section, 1);
XCTAssertEqual([self.adapter sectionControllerForObject:three].section, 2);
XCTAssertTrue([self.adapter sectionControllerForObject:three].isLastSection);

self.dataSource.objects = @[zero, one, two, three];
[self.adapter performUpdatesAnimated:NO completion:nil];

IGListSectionController *controller0 = [self.adapter sectionControllerForObject:zero];
XCTAssertEqual(controller0.sectionIndex, 0);
XCTAssertEqual(controller0.section, 0);
XCTAssertTrue(controller0.isFirstSection);

IGListSectionController *controller1b = [self.adapter sectionControllerForObject:one];
XCTAssertEqual(controller1b.sectionIndex, 1);
XCTAssertEqual(controller1b.section, 1);
XCTAssertFalse(controller1b.isFirstSection);

XCTAssertEqual([self.adapter sectionControllerForObject:two].sectionIndex, 2);
XCTAssertEqual([self.adapter sectionControllerForObject:three].sectionIndex, 3);
XCTAssertEqual([self.adapter sectionControllerForObject:two].section, 2);
XCTAssertEqual([self.adapter sectionControllerForObject:three].section, 3);
XCTAssertTrue([self.adapter sectionControllerForObject:three].isLastSection);
}

Expand All @@ -1130,27 +1130,27 @@ - (void)test_whenRemovingFromHead_thatAllSectionControllerIndexesUpdateCorrectly
[self.adapter performUpdatesAnimated:NO completion:nil];

IGListSectionController *zeroController = [self.adapter sectionControllerForSection:0];
XCTAssertEqual(zeroController.sectionIndex, 0);
XCTAssertEqual(zeroController.section, 0);
XCTAssertTrue(zeroController.isFirstSection);

IGListSectionController *oneController = [self.adapter sectionControllerForSection:1];
XCTAssertEqual(oneController.sectionIndex, 1);
XCTAssertEqual(oneController.section, 1);
XCTAssertFalse(oneController.isFirstSection);

IGListSectionController *threeController = [self.adapter sectionControllerForSection:3];
XCTAssertEqual(threeController.sectionIndex, 3);
XCTAssertEqual(threeController.section, 3);
XCTAssertTrue(threeController.isLastSection);

self.dataSource.objects = @[one, two, three];
[self.adapter performUpdatesAnimated:NO completion:nil];

XCTAssertEqual(zeroController.sectionIndex, NSNotFound);
XCTAssertEqual(zeroController.section, NSNotFound);
XCTAssertFalse(zeroController.isFirstSection);

XCTAssertEqual(oneController.sectionIndex, 0);
XCTAssertEqual(oneController.section, 0);
XCTAssertTrue(oneController.isFirstSection);

XCTAssertEqual(threeController.sectionIndex, 2);
XCTAssertEqual(threeController.section, 2);
XCTAssertTrue(threeController.isLastSection);
}

Expand All @@ -1163,31 +1163,31 @@ - (void)test_whenRemovingFromMiddle_thatAllSectionControllerIndexesUpdateCorrect
[self.adapter performUpdatesAnimated:NO completion:nil];

IGListSectionController *zeroController = [self.adapter sectionControllerForSection:0];
XCTAssertEqual(zeroController.sectionIndex, 0);
XCTAssertEqual(zeroController.section, 0);
XCTAssertTrue(zeroController.isFirstSection);

IGListSectionController *oneController = [self.adapter sectionControllerForSection:1];
XCTAssertEqual(oneController.sectionIndex, 1);
XCTAssertEqual(oneController.section, 1);
XCTAssertFalse(oneController.isFirstSection);

IGListSectionController *threeController = [self.adapter sectionControllerForSection:3];
XCTAssertEqual(threeController.sectionIndex, 3);
XCTAssertEqual(threeController.section, 3);
XCTAssertTrue(threeController.isLastSection);

self.dataSource.objects = @[zero, two, three];
[self.adapter performUpdatesAnimated:NO completion:nil];

XCTAssertEqual(zeroController.sectionIndex, 0);
XCTAssertEqual(zeroController.section, 0);
XCTAssertTrue(zeroController.isFirstSection);

XCTAssertEqual(oneController.sectionIndex, NSNotFound);
XCTAssertEqual(oneController.section, NSNotFound);
XCTAssertFalse(oneController.isFirstSection);

XCTAssertEqual(threeController.sectionIndex, 2);
XCTAssertEqual(threeController.section, 2);
XCTAssertTrue(threeController.isLastSection);
}

- (void)test_withStrongRefToSectionController_thatAdapterSectionIndexIsZero_thatSectionControllerIndexDoesNotChange {
- (void)test_withStrongRefToSectionController_thatAdaptersectionIsZero_thatSectionControllerIndexDoesNotChange {
IGListSectionController *sc = nil;

// hold a weak reference to simulate what would happen to the collectionContext object on a section controller
Expand All @@ -1207,11 +1207,10 @@ - (void)test_withStrongRefToSectionController_thatAdapterSectionIndexIsZero_that
[adapter performUpdatesAnimated:NO completion:nil];

sc = [adapter sectionControllerForSection:1];
XCTAssertEqual(sc.sectionIndex, 1);
XCTAssertEqual(sc.section, 1);
}

XCTAssertEqual(sc.sectionIndex, NSNotFound);
// This will be 0 because wAdapter should be nil and so nil messaging will return 0
XCTAssertEqual(sc.section, NSNotFound);
XCTAssertEqual([wAdapter sectionForSectionController:sc], 0);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/IGListSectionMapTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ - (void)test_whenUpdatingItems_thatSectionControllerIndexesAreUpdated {
NSArray *objects = @[@0, @1, @2];

IGListTestSection *one = [IGListTestSection new];
XCTAssertEqual(one.sectionIndex, NSNotFound);
XCTAssertEqual(one.section, NSNotFound);

NSArray *sectionControllers = @[[IGListTestSection new], one, [IGListTestSection new]];
IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]];
[map updateWithObjects:objects sectionControllers:sectionControllers];

XCTAssertEqual(one.sectionIndex, 1);
XCTAssertEqual(one.section, 1);
XCTAssertFalse(one.isFirstSection);
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/IGListStackSectionControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ - (void)test_whenQueryingSectionControllerSection_thatSectionMatchesStackSection
IGListTestSection *section21 = stack2.sectionControllers[0];
IGListTestSection *section22 = stack2.sectionControllers[1];

XCTAssertEqual(stack1.sectionIndex, 0);
XCTAssertEqual(stack2.sectionIndex, 1);
XCTAssertEqual(section11.sectionIndex, 0);
XCTAssertEqual(section12.sectionIndex, 0);
XCTAssertEqual(section21.sectionIndex, 1);
XCTAssertEqual(section22.sectionIndex, 1);
XCTAssertEqual(stack1.section, 0);
XCTAssertEqual(stack2.section, 1);
XCTAssertEqual(section11.section, 0);
XCTAssertEqual(section12.section, 0);
XCTAssertEqual(section21.section, 1);
XCTAssertEqual(section22.section, 1);
}

- (void)test_whenReloadingItems_thatCollectionViewReloadsRelativeIndexPaths {
Expand Down

0 comments on commit 0a41691

Please sign in to comment.