Skip to content

Commit

Permalink
Working ranges in stacked section controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Nystrom committed Dec 22, 2016
1 parent 2957ee5 commit 7d02eea
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (instancetype)initWithSectionControllers:(NSArray <IGListSectionController<IGL

self.displayDelegate = self;
self.scrollDelegate = self;
self.workingRangeDelegate = self;

[self reloadData];
}
Expand Down Expand Up @@ -332,4 +333,18 @@ - (void)listAdapter:(IGListAdapter *)listAdapter didEndDraggingSectionController
}
}

#pragma mark - IGListWorkingRangeDelegate

- (void)listAdapter:(IGListAdapter *)listAdapter sectionControllerWillEnterWorkingRange:(IGListSectionController<IGListSectionType> *)sectionController {
for (IGListSectionController<IGListSectionType> *childSectionController in self.sectionControllers) {
[[childSectionController workingRangeDelegate] listAdapter:listAdapter sectionControllerWillEnterWorkingRange:childSectionController];
}
}

- (void)listAdapter:(IGListAdapter *)listAdapter sectionControllerDidExitWorkingRange:(IGListSectionController<IGListSectionType> *)sectionController {
for (IGListSectionController<IGListSectionType> *childSectionController in self.sectionControllers) {
[[childSectionController workingRangeDelegate] listAdapter:listAdapter sectionControllerDidExitWorkingRange:childSectionController];
}
}

@end
3 changes: 2 additions & 1 deletion Source/Internal/IGListStackedSectionControllerInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<
IGListCollectionContext,
IGListDisplayDelegate,
IGListScrollDelegate
IGListScrollDelegate,
IGListWorkingRangeDelegate
>

@property (nonatomic, strong, readonly) NSOrderedSet<__kindof IGListSectionController<IGListSectionType> *> *sectionControllers;
Expand Down
53 changes: 52 additions & 1 deletion Tests/IGListStackSectionControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (void)setUp {
self.collectionView.frame = kStackTestFrame;

self.dataSource = [[IGTestStackedDataSource alloc] init];
self.adapter = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil workingRangeSize:0];
self.adapter = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil workingRangeSize:1];
}

- (void)tearDown {
Expand Down Expand Up @@ -702,4 +702,55 @@ - (void)test_whenDeselectingChildSectionControllerIndex_thatCorrectCellDeselecte
XCTAssertFalse([[self.collectionView cellForItemAtIndexPath:path] isSelected]);
}

- (void)test_whenRemovingSection_withWorkingRange_thatChildSectionControllersReceiveEvents {
[self setupWithObjects:@[
[[IGTestObject alloc] initWithKey:@0 value:@[@1, @2, @3]],
[[IGTestObject alloc] initWithKey:@1 value:@[@1, @1]]
]];

IGListStackedSectionController *stack = [self.adapter sectionControllerForObject:self.dataSource.objects.firstObject];
IGListTestSection *section = stack.sectionControllers.firstObject;

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListWorkingRangeDelegate)];
[[mockDelegate expect] listAdapter:self.adapter sectionControllerDidExitWorkingRange:section];

section.workingRangeDelegate = mockDelegate;

self.dataSource.objects = @[
[[IGTestObject alloc] initWithKey:@1 value:@[@1, @1]],
];

XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];

[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
[mockDelegate verify];
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:15 handler:nil];
}

- (void)test_whenScrolling_withWorkingRange_thatChildSectionControllersReceiveEvents {
[self setupWithObjects:@[
[[IGTestObject alloc] initWithKey:@0 value:@[@1, @2, @3]],
[[IGTestObject alloc] initWithKey:@1 value:@[@1, @2, @3]],
[[IGTestObject alloc] initWithKey:@2 value:@[@1, @2, @3]],
[[IGTestObject alloc] initWithKey:@3 value:@[@1, @2, @3]],
[[IGTestObject alloc] initWithKey:@4 value:@[@1, @1]]
]];

IGListStackedSectionController *stack = [self.adapter sectionControllerForObject:self.dataSource.objects.lastObject];
IGListTestSection *section = stack.sectionControllers.firstObject;

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListWorkingRangeDelegate)];
[[mockDelegate expect] listAdapter:self.adapter sectionControllerWillEnterWorkingRange:section];

section.workingRangeDelegate = mockDelegate;

[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:4] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
[self.collectionView layoutIfNeeded];

[mockDelegate verify];
}

@end

0 comments on commit 7d02eea

Please sign in to comment.