2019-12-19 17:32:49 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-02-21 00:11:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import "ObjcDemoViewController.h"
|
2017-03-31 21:45:28 +00:00
|
|
|
|
2017-02-21 00:11:56 +00:00
|
|
|
#import <IGListKit/IGListKit.h>
|
|
|
|
|
|
2017-04-07 18:20:37 +00:00
|
|
|
#import "Post.h"
|
|
|
|
|
#import "PostSectionController.h"
|
2017-02-21 00:11:56 +00:00
|
|
|
|
|
|
|
|
@interface ObjcDemoViewController () <IGListAdapterDataSource>
|
2017-03-31 21:45:28 +00:00
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
2017-02-21 00:11:56 +00:00
|
|
|
@property (nonatomic, strong) IGListAdapter *adapter;
|
2019-12-19 17:32:49 +00:00
|
|
|
@property (nonatomic, copy) NSArray<Post *> *data;
|
2017-03-31 21:45:28 +00:00
|
|
|
|
2017-02-21 00:11:56 +00:00
|
|
|
@end
|
|
|
|
|
|
2017-03-31 21:45:28 +00:00
|
|
|
|
2017-02-21 00:11:56 +00:00
|
|
|
@implementation ObjcDemoViewController
|
|
|
|
|
|
2017-04-07 18:20:37 +00:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
2017-03-31 21:45:28 +00:00
|
|
|
|
2017-04-07 18:20:37 +00:00
|
|
|
self.data = @[
|
|
|
|
|
[[Post alloc] initWithUsername:@"userA" comments:@[
|
|
|
|
|
@"Luminous triangle",
|
|
|
|
|
@"Awesome",
|
|
|
|
|
@"Super clean",
|
|
|
|
|
@"Stunning shot",
|
|
|
|
|
]],
|
|
|
|
|
[[Post alloc] initWithUsername:@"userB" comments:@[
|
|
|
|
|
@"The simplicity here is superb",
|
|
|
|
|
@"thanks!",
|
|
|
|
|
@"That's always so kind of you!",
|
|
|
|
|
@"I think you might like this",
|
|
|
|
|
]],
|
|
|
|
|
[[Post alloc] initWithUsername:@"userC" comments:@[
|
|
|
|
|
@"So good",
|
|
|
|
|
]],
|
|
|
|
|
[[Post alloc] initWithUsername:@"userD" comments:@[
|
|
|
|
|
@"hope she might like it.",
|
|
|
|
|
@"I love it."
|
|
|
|
|
]],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
|
|
|
|
|
collectionViewLayout:[UICollectionViewFlowLayout new]];
|
2017-03-31 21:45:28 +00:00
|
|
|
[self.view addSubview:self.collectionView];
|
|
|
|
|
self.adapter = [[IGListAdapter alloc] initWithUpdater:[[IGListAdapterUpdater alloc] init]
|
2017-04-21 21:24:14 +00:00
|
|
|
viewController:self];
|
2017-03-31 21:45:28 +00:00
|
|
|
|
|
|
|
|
self.adapter.collectionView = self.collectionView;
|
|
|
|
|
self.adapter.dataSource = self;
|
2017-02-21 00:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
self.collectionView.frame = self.view.bounds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - IGListAdapterDataSource
|
|
|
|
|
|
|
|
|
|
- (NSArray<id<IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter {
|
|
|
|
|
return self.data;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-19 15:17:56 +00:00
|
|
|
- (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object {
|
2017-04-07 18:20:37 +00:00
|
|
|
return [PostSectionController new];
|
2017-02-21 00:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-31 21:45:28 +00:00
|
|
|
- (UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter {
|
|
|
|
|
return nil;
|
2017-03-07 00:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 00:11:56 +00:00
|
|
|
@end
|