Skip to content

Commit

Permalink
Make -[IGListAdapter updater] Public, Read-Only
Browse files Browse the repository at this point in the history
Summary:
Hey IGListKit folks! Would you be willing to expose this, so that other objects that are given a list adapter can inspect its updater configuration?

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes #379

Reviewed By: jessesquires

Differential Revision: D4379016

Pulled By: rnystrom

fbshipit-source-id: 4056457181fea31f71b1e928b60aec46160cc585
  • Loading branch information
Adlai Holler authored and Facebook Github Bot committed Jan 4, 2017
1 parent 71ce990 commit 5fa588e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This release closes the [2.1.0 milestone](https://github.com/Instagram/IGListKit

- Added `allowsBackgroundReloading` flag (default `YES`) to `IGListAdapterUpdater` so users can configure this behavior as needed. [Adlai-Holler](https://github.com/Adlai-Holler) [(#375)](https://github.com/Instagram/IGListKit/pull/375)

- `-[IGListAdapter updater]` is now public (read-only). [Adlai-Holler](https://github.com/Adlai-Holler) [(#379)](https://github.com/Instagram/IGListKit/pull/379)

### Fixes

- Avoid `UICollectionView` crashes when queueing a reload and insert/delete on the same item as well as reloading an item in a section that is animating. [Ryan Nystrom](https://github.com/rnystrom) [(#325)](https://github.com/Instagram/IGListKit/pull/325)
Expand Down
9 changes: 7 additions & 2 deletions Source/IGListAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ IGLK_SUBCLASSING_RESTRICTED
*/
@property (nonatomic, nullable, weak) id <UIScrollViewDelegate> scrollViewDelegate;

/**
The updater that this list adapter was created with.
*/
@property (nonatomic, strong, readonly) id <IGListUpdatingDelegate> updater;

/**
A bitmask of experiments to conduct on the adapter.
*/
Expand All @@ -81,7 +86,7 @@ IGLK_SUBCLASSING_RESTRICTED
/**
Initializes a new `IGListAdapter` object.
@param updatingDelegate An object that manages updates to the collection view.
@param updater An object that manages updates to the collection view.
@param viewController The view controller that will house the adapter.
@param workingRangeSize The number of objects before and after the viewport to consider within the working range.
Expand All @@ -94,7 +99,7 @@ IGLK_SUBCLASSING_RESTRICTED
To opt out of using the working range, you can provide a value of `0`.
*/
- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updatingDelegate
- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updater
viewController:(nullable UIViewController *)viewController
workingRangeSize:(NSInteger)workingRangeSize NS_DESIGNATED_INITIALIZER;

Expand Down
24 changes: 12 additions & 12 deletions Source/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ - (void)dealloc {

#pragma mark - Init

- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updatingDelegate
- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updater
viewController:(UIViewController *)viewController
workingRangeSize:(NSInteger)workingRangeSize {
IGAssertMainThread();
IGParameterAssert(updatingDelegate);
IGParameterAssert(updater);

if (self = [super init]) {
NSPointerFunctions *keyFunctions = [updatingDelegate objectLookupPointerFunctions];
NSPointerFunctions *keyFunctions = [updater objectLookupPointerFunctions];
NSPointerFunctions *valueFunctions = [NSPointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsStrongMemory];
NSMapTable *table = [[NSMapTable alloc] initWithKeyPointerFunctions:keyFunctions valuePointerFunctions:valueFunctions capacity:0];
_sectionMap = [[IGListSectionMap alloc] initWithMapTable:table];
Expand All @@ -52,7 +52,7 @@ - (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updatingDelegate
_cellSectionControllerMap = [NSMapTable mapTableWithKeyOptions:NSMapTableObjectPointerPersonality | NSMapTableStrongMemory
valueOptions:NSMapTableStrongMemory];

_updatingDelegate = updatingDelegate;
_updater = updater;
_viewController = viewController;
}
return self;
Expand Down Expand Up @@ -259,7 +259,7 @@ - (void)performUpdatesAnimated:(BOOL)animated completion:(IGListUpdaterCompletio
NSArray *newItems = [[dataSource objectsForListAdapter:self] copy];

__weak __typeof__(self) weakSelf = self;
[self.updatingDelegate performUpdateWithCollectionView:collectionView
[self.updater performUpdateWithCollectionView:collectionView
fromObjects:fromObjects
toObjects:newItems
animated:animated
Expand Down Expand Up @@ -294,7 +294,7 @@ - (void)reloadDataWithCompletion:(nullable IGListUpdaterCompletion)completion {
NSArray *newItems = [[dataSource objectsForListAdapter:self] copy];

__weak __typeof__(self) weakSelf = self;
[self.updatingDelegate reloadDataWithCollectionView:collectionView reloadUpdateBlock:^{
[self.updater reloadDataWithCollectionView:collectionView reloadUpdateBlock:^{
// purge all section controllers from the item map so that they are regenerated
[weakSelf.sectionMap reset];
[weakSelf updateObjects:newItems dataSource:dataSource];
Expand Down Expand Up @@ -329,7 +329,7 @@ - (void)reloadObjects:(NSArray *)objects {
UICollectionView *collectionView = self.collectionView;
IGAssert(collectionView != nil, @"Tried to reload the adapter without a collection view");

[self.updatingDelegate reloadCollectionView:collectionView sections:sections];
[self.updater reloadCollectionView:collectionView sections:sections];
}


Expand Down Expand Up @@ -917,7 +917,7 @@ - (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)
[self insertInSectionController:sectionController atIndexes:indexes];
} else {
NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:YES];
[self.updatingDelegate reloadItemsInCollectionView:collectionView indexPaths:indexPaths];
[self.updater reloadItemsInCollectionView:collectionView indexPaths:indexPaths];
}
}

Expand All @@ -933,7 +933,7 @@ - (void)insertInSectionController:(IGListSectionController<IGListSectionType> *)
}

NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:NO];
[self.updatingDelegate insertItemsIntoCollectionView:collectionView indexPaths:indexPaths];
[self.updater insertItemsIntoCollectionView:collectionView indexPaths:indexPaths];
}

- (void)deleteInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes {
Expand All @@ -948,7 +948,7 @@ - (void)deleteInSectionController:(IGListSectionController<IGListSectionType> *)
}

NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:YES];
[self.updatingDelegate deleteItemsFromCollectionView:collectionView indexPaths:indexPaths];
[self.updater deleteItemsFromCollectionView:collectionView indexPaths:indexPaths];
}

- (void)reloadSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
Expand All @@ -964,7 +964,7 @@ - (void)reloadSectionController:(IGListSectionController <IGListSectionType> *)s
}

NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section];
[self.updatingDelegate reloadCollectionView:collectionView sections:sections];
[self.updater reloadCollectionView:collectionView sections:sections];
}

- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion {
Expand All @@ -974,7 +974,7 @@ - (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completi
IGAssert(collectionView != nil, @"Performing batch updates without a collection view.");

__weak __typeof__(self) weakSelf = self;
[self.updatingDelegate performUpdateWithCollectionView:collectionView animated:animated itemUpdates:^{
[self.updater performUpdateWithCollectionView:collectionView animated:animated itemUpdates:^{
weakSelf.isInUpdateBlock = YES;
updates();
weakSelf.isInUpdateBlock = NO;
Expand Down
2 changes: 1 addition & 1 deletion Source/Internal/IGListAdapterInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ IGListCollectionContext
__weak UICollectionView *_collectionView;
}

@property (nonatomic, strong) id <IGListUpdatingDelegate> updatingDelegate;
@property (nonatomic, strong) id <IGListUpdatingDelegate> updater;

@property (nonatomic, strong, readonly) IGListSectionMap *sectionMap;
@property (nonatomic, strong, readonly) IGListDisplayHandler *displayHandler;
Expand Down
8 changes: 4 additions & 4 deletions Tests/IGListAdapterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ - (void)test_whenSectionControllerReloading_withEmptyIndexes_thatNoUpdatesHappen

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListUpdatingDelegate)];
[[mockDelegate reject] reloadItemsInCollectionView:[OCMArg any] indexPaths:[OCMArg any]];
self.adapter.updatingDelegate = mockDelegate;
self.adapter.updater = mockDelegate;

id sectionController = [self.adapter sectionControllerForObject:@1];
[self.adapter reloadInSectionController:sectionController atIndexes:[NSIndexSet new]];
Expand All @@ -718,7 +718,7 @@ - (void)test_whenSectionControllerDeleting_withEmptyIndexes_thatNoUpdatesHappen

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListUpdatingDelegate)];
[[mockDelegate reject] deleteItemsFromCollectionView:[OCMArg any] indexPaths:[OCMArg any]];
self.adapter.updatingDelegate = mockDelegate;
self.adapter.updater = mockDelegate;

id sectionController = [self.adapter sectionControllerForObject:@1];
[self.adapter deleteInSectionController:sectionController atIndexes:[NSIndexSet new]];
Expand All @@ -732,7 +732,7 @@ - (void)test_whenSectionControllerInserting_withEmptyIndexes_thatNoUpdatesHappen

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListUpdatingDelegate)];
[[mockDelegate reject] insertItemsIntoCollectionView:[OCMArg any] indexPaths:[OCMArg any]];
self.adapter.updatingDelegate = mockDelegate;
self.adapter.updater = mockDelegate;

id sectionController = [self.adapter sectionControllerForObject:@1];
[self.adapter insertInSectionController:sectionController atIndexes:[NSIndexSet new]];
Expand All @@ -746,7 +746,7 @@ - (void)test_whenReloading_withSectionControllerNotFound_thatNoUpdatesHappen {

id mockDelegate = [OCMockObject mockForProtocol:@protocol(IGListUpdatingDelegate)];
[[mockDelegate reject] reloadCollectionView:[OCMArg any] sections:[OCMArg any]];
self.adapter.updatingDelegate = mockDelegate;
self.adapter.updater = mockDelegate;

id sectionController = [IGListSectionController new];
[self.adapter reloadSectionController:sectionController];
Expand Down

0 comments on commit 5fa588e

Please sign in to comment.