forked from Instagram/IGListKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IGListSectionController.m
69 lines (56 loc) · 2.47 KB
/
IGListSectionController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 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;
}
return self;
}
@end