mirror of
https://github.com/Instagram/IGListKit
synced 2026-04-25 07:27:30 +00:00
Summary: Removing the `IGListSectionType` protocol and adding default implementations into `IGListSectionController`. - `numberOfItems` returns 1 - `cellForItemAtIndex:` asserts (have to return a cell) - `didUpdateToObject:` no-ops - `didSelectItemAtIndex:` no-ops Fixes #168 Reviewed By: jessesquires Differential Revision: D4909585 fbshipit-source-id: 8816702504e3fc0683868914ff4dd20e4af7c166
72 lines
2.2 KiB
Objective-C
72 lines
2.2 KiB
Objective-C
/**
|
|
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
|
|
|
The examples provided by Facebook are for non-commercial testing and evaluation
|
|
purposes only. Facebook reserves all rights not expressly granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#import "PostSectionController.h"
|
|
|
|
#import "Post.h"
|
|
#import "PhotoCell.h"
|
|
#import "InteractiveCell.h"
|
|
#import "CommentCell.h"
|
|
#import "UserInfoCell.h"
|
|
|
|
static NSInteger cellsBeforeComments = 3;
|
|
|
|
@implementation PostSectionController {
|
|
Post *_post;
|
|
}
|
|
|
|
#pragma mark - IGListSectionController Overrides
|
|
|
|
- (NSInteger)numberOfItems {
|
|
return cellsBeforeComments + _post.comments.count;
|
|
}
|
|
|
|
- (CGSize)sizeForItemAtIndex:(NSInteger)index {
|
|
const CGFloat width = self.collectionContext.containerSize.width;
|
|
CGFloat height;
|
|
if (index == 0 || index == 2) {
|
|
height = 41.0;
|
|
} else if (index == 1) {
|
|
height = width; // square
|
|
} else {
|
|
height = 25.0;
|
|
}
|
|
return CGSizeMake(width, height);
|
|
}
|
|
|
|
- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
|
|
Class cellClass;
|
|
if (index == 0) {
|
|
cellClass = [UserInfoCell class];
|
|
} else if (index == 1) {
|
|
cellClass = [PhotoCell class];
|
|
} else if (index == 2) {
|
|
cellClass = [InteractiveCell class];
|
|
} else {
|
|
cellClass = [CommentCell class];
|
|
}
|
|
id cell = [self.collectionContext dequeueReusableCellOfClass:cellClass forSectionController:self atIndex:index];
|
|
if ([cell isKindOfClass:[CommentCell class]]) {
|
|
[(CommentCell *)cell setComment:_post.comments[index - cellsBeforeComments]];
|
|
} else if ([cell isKindOfClass:[UserInfoCell class]]) {
|
|
[(UserInfoCell *)cell setName:_post.username];
|
|
}
|
|
return cell;
|
|
}
|
|
|
|
- (void)didUpdateToObject:(id)object {
|
|
_post = object;
|
|
}
|
|
|
|
@end
|