mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-13 20:38:56 +00:00
Summary: This pull request removes the `sectionForSectionController:` method from the `IGListCollectionContext` protocol so that the protocol is exclusively for presentation methods. This should not add new functionality, but rather makes the index directly accessible on the section controllers themselves. This change makes sense because at no time will there be an update to the list that the list adapter is unaware of and so it will always be able to set and update any indexes for a section controller that has changed. Issue fixed: #609 - [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 https://github.com/Instagram/IGListKit/pull/671 Reviewed By: jessesquires Differential Revision: D4942159 Pulled By: amonshiz fbshipit-source-id: d648cfdd381cbf1d9ee7ff549ae27d2972a84622
87 lines
2.9 KiB
Objective-C
87 lines
2.9 KiB
Objective-C
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import "IGListSectionControllerInternal.h"
|
|
|
|
#import <IGListKit/IGListMacros.h>
|
|
#import <IGListKit/IGListAssert.h>
|
|
|
|
static NSString * const kIGListSectionControllerThreadKey = @"kIGListSectionControllerThreadKey";
|
|
|
|
@interface IGListSectionControllerThreadContext : NSObject
|
|
@property (nonatomic, weak) UIViewController *viewController;
|
|
@property (nonatomic, weak) id<IGListCollectionContext> collectionContext;
|
|
@end
|
|
@implementation IGListSectionControllerThreadContext
|
|
@end
|
|
|
|
static NSMutableArray<IGListSectionControllerThreadContext *> *threadContextStack(void) {
|
|
IGAssertMainThread();
|
|
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
|
NSMutableArray *stack = threadDictionary[kIGListSectionControllerThreadKey];
|
|
if (stack == nil) {
|
|
stack = [NSMutableArray new];
|
|
threadDictionary[kIGListSectionControllerThreadKey] = stack;
|
|
}
|
|
return stack;
|
|
}
|
|
|
|
void IGListSectionControllerPushThread(UIViewController *viewController, id<IGListCollectionContext> collectionContext) {
|
|
IGListSectionControllerThreadContext *context = [IGListSectionControllerThreadContext new];
|
|
context.viewController = viewController;
|
|
context.collectionContext = collectionContext;
|
|
|
|
[threadContextStack() addObject:context];
|
|
}
|
|
|
|
void IGListSectionControllerPopThread(void) {
|
|
NSMutableArray *stack = threadContextStack();
|
|
IGAssert(stack.count > 0, @"IGListSectionController thread stack is empty");
|
|
[stack removeLastObject];
|
|
}
|
|
|
|
@implementation IGListSectionController
|
|
|
|
- (instancetype)init {
|
|
if (self = [super init]) {
|
|
IGListSectionControllerThreadContext *context = [threadContextStack() lastObject];
|
|
_viewController = context.viewController;
|
|
_collectionContext = context.collectionContext;
|
|
|
|
if (_collectionContext == nil) {
|
|
IGLKLog(@"Warning: Creating %@ outside of -[IGListAdapterDataSource listAdapter:sectionControllerForObject:]. Collection context and view controller will be set later.",
|
|
NSStringFromClass([self class]));
|
|
}
|
|
|
|
_minimumInteritemSpacing = 0.0;
|
|
_minimumLineSpacing = 0.0;
|
|
_inset = UIEdgeInsetsZero;
|
|
_sectionIndex = NSNotFound;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSInteger)numberOfItems {
|
|
return 1;
|
|
}
|
|
|
|
- (CGSize)sizeForItemAtIndex:(NSInteger)index {
|
|
return CGSizeZero;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
|
|
IGFailAssert(@"Section controller %@ must override %s:", self, __PRETTY_FUNCTION__);
|
|
return nil;
|
|
}
|
|
|
|
- (void)didUpdateToObject:(id)object {}
|
|
|
|
- (void)didSelectItemAtIndex:(NSInteger)index {}
|
|
|
|
@end
|