forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoFeedListKitViewController.m
More file actions
106 lines (91 loc) · 3.42 KB
/
Copy pathPhotoFeedListKitViewController.m
File metadata and controls
106 lines (91 loc) · 3.42 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// PhotoFeedListKitViewController.m
// Sample
//
// Created by Adlai Holler on 12/29/16.
// Copyright © 2016 Facebook. All rights reserved.
//
#import "PhotoFeedListKitViewController.h"
#import <IGListKit/IGListKit.h>
#import "PhotoFeedModel.h"
#import "PhotoFeedSectionController.h"
#import "RefreshingSectionControllerType.h"
@interface PhotoFeedListKitViewController () <IGListAdapterDataSource, ASCollectionDelegate>
@property (nonatomic, strong) IGListAdapter *listAdapter;
@property (nonatomic, strong) PhotoFeedModel *photoFeed;
@property (nonatomic, strong, readonly) ASCollectionNode *collectionNode;
@property (nonatomic, strong, readonly) UIActivityIndicatorView *spinner;
@property (nonatomic, strong, readonly) UIRefreshControl *refreshCtrl;
@end
@implementation PhotoFeedListKitViewController
@synthesize spinner = _spinner;
- (instancetype)init
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
ASCollectionNode *node = [[ASCollectionNode alloc] initWithCollectionViewLayout:layout];
if (self = [super initWithNode:node]) {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenWidthImageSize = CGSizeMake(screenRect.size.width * screenScale, screenRect.size.width * screenScale);
_photoFeed = [[PhotoFeedModel alloc] initWithPhotoFeedModelType:PhotoFeedModelTypePopular imageSize:screenWidthImageSize];
IGListAdapterUpdater *updater = [[IGListAdapterUpdater alloc] init];
_listAdapter = [[IGListAdapter alloc] initWithUpdater:updater viewController:self workingRangeSize:0];
_listAdapter.dataSource = self;
[_listAdapter setASDKCollectionNode:self.collectionNode];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionNode.view.alwaysBounceVertical = YES;
_refreshCtrl = [[UIRefreshControl alloc] init];
[_refreshCtrl addTarget:self action:@selector(refreshFeed) forControlEvents:UIControlEventValueChanged];
[self.collectionNode.view addSubview:_refreshCtrl];
_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
}
- (ASCollectionNode *)collectionNode
{
return self.node;
}
- (void)resetAllData
{
// nop, not used currently
}
- (void)refreshFeed
{
// Ask the first section controller to do the refreshing.
id<RefreshingSectionControllerType> secCtrl = [self.listAdapter sectionControllerForObject:self.photoFeed];
if ([(NSObject*)secCtrl conformsToProtocol:@protocol(RefreshingSectionControllerType)]) {
[secCtrl refreshContentWithCompletion:^{
[self.refreshCtrl endRefreshing];
}];
}
}
- (UIActivityIndicatorView *)spinner
{
if (_spinner == nil) {
_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_spinner startAnimating];
}
return _spinner;
}
#pragma mark - IGListAdapterDataSource
- (NSArray<id <IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter
{
return @[ self.photoFeed ];
}
- (UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter
{
return self.spinner;
}
- (IGListSectionController *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object
{
if ([object isKindOfClass:[PhotoFeedModel class]]) {
return [[PhotoFeedSectionController alloc] init];
} else {
ASDisplayNodeFailAssert(@"Only supports objects of class PhotoFeedModel.");
return nil;
}
}
@end