Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 38aac9d

Browse files
author
Adlai Holler
authored
IGListKit Support II: Electric Boogaloo (#2942)
* Reimplement IGListKit support in a cleaner way * Rename and fix some stuff * Fix supplementaries more * Update docs * Update test * Cleanup minor things * Tweak it * Indentation * Remove irrelevant changes * Break out cell into its own file * Fix indentation * Address feedback
1 parent 34338ca commit 38aac9d

70 files changed

Lines changed: 2444 additions & 180 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ before_install:
1717
install: echo "<3"
1818
env:
1919
- MODE=tests
20+
- MODE=tests_listkit
2021
- MODE=examples-pt1
2122
- MODE=examples-pt2
2223
- MODE=examples-pt3

ASDKListKit/ASDKListKit.xcodeproj/project.pbxproj

Lines changed: 394 additions & 0 deletions
Large diffs are not rendered by default.

ASDKListKit/ASDKListKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASDKListKit/ASDKListKit.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// ASListKitTestAdapterDataSource.h
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import <IGListKit/IGListKit.h>
10+
11+
@interface ASListKitTestAdapterDataSource : NSObject <IGListAdapterDataSource>
12+
13+
// array of numbers which is then passed to -[IGListTestSection setItems:]
14+
@property (nonatomic, strong) NSArray <NSNumber *> *objects;
15+
16+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// ASListKitTestAdapterDataSource.m
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import "ASListKitTestAdapterDataSource.h"
10+
#import "ASListTestSection.h"
11+
12+
@implementation ASListKitTestAdapterDataSource
13+
14+
- (NSArray *)objectsForListAdapter:(IGListAdapter *)listAdapter
15+
{
16+
return self.objects;
17+
}
18+
19+
- (IGListSectionController <IGListSectionType> *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object
20+
{
21+
ASListTestSection *section = [[ASListTestSection alloc] init];
22+
return section;
23+
}
24+
25+
- (nullable UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter
26+
{
27+
return nil;
28+
}
29+
30+
@end
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// ASListKitTests.m
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
11+
#import "ASListKitTestAdapterDataSource.h"
12+
#import "ASXCTExtensions.h"
13+
#import <JGMethodSwizzler/JGMethodSwizzler.h>
14+
15+
@interface ASListKitTests : XCTestCase
16+
17+
@property (nonatomic, strong) ASCollectionNode *collectionNode;
18+
@property (nonatomic, strong) UICollectionView *collectionView;
19+
@property (nonatomic, strong) IGListAdapter *adapter;
20+
@property (nonatomic, strong) ASListKitTestAdapterDataSource *dataSource;
21+
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
22+
@property (nonatomic, strong) UIWindow *window;
23+
@property (nonatomic) NSInteger reloadDataCount;
24+
25+
@end
26+
27+
@implementation ASListKitTests
28+
29+
- (void)setUp
30+
{
31+
[super setUp];
32+
33+
[ASCollectionView swizzleInstanceMethod:@selector(reloadData) withReplacement:JGMethodReplacementProviderBlock {
34+
return JGMethodReplacement(void, ASCollectionView *) {
35+
JGOriginalImplementation(void);
36+
_reloadDataCount++;
37+
};
38+
}];
39+
40+
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
41+
42+
self.layout = [[UICollectionViewFlowLayout alloc] init];
43+
self.collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:self.layout];
44+
self.collectionNode.frame = self.window.bounds;
45+
self.collectionView = self.collectionNode.view;
46+
47+
[self.window addSubnode:self.collectionNode];
48+
49+
IGListAdapterUpdater *updater = [[IGListAdapterUpdater alloc] init];
50+
51+
self.dataSource = [[ASListKitTestAdapterDataSource alloc] init];
52+
self.adapter = [[IGListAdapter alloc] initWithUpdater:updater
53+
viewController:nil
54+
workingRangeSize:0];
55+
self.adapter.dataSource = self.dataSource;
56+
[self.adapter setASDKCollectionNode:self.collectionNode];
57+
XCTAssertNotNil(self.adapter.collectionView, @"Adapter was not bound to collection view. You may have a stale copy of AsyncDisplayKit that was built without IG_LIST_KIT. Clean Builder Folder IMO.");
58+
}
59+
60+
- (void)tearDown
61+
{
62+
[super tearDown];
63+
XCTAssert([ASCollectionView deswizzleAllMethods]);
64+
self.reloadDataCount = 0;
65+
self.window = nil;
66+
self.collectionNode = nil;
67+
self.collectionView = nil;
68+
self.adapter = nil;
69+
self.dataSource = nil;
70+
self.layout = nil;
71+
}
72+
73+
- (void)test_whenAdapterUpdated_withObjectsOverflow_thatVisibleObjectsIsSubsetOfAllObjects
74+
{
75+
// each section controller returns n items sized 100x10
76+
self.dataSource.objects = @[@1, @2, @3, @4, @5, @6];
77+
XCTestExpectation *e = [self expectationWithDescription:@"Data update completed"];
78+
79+
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) {
80+
[e fulfill];
81+
}];
82+
83+
[self waitForExpectationsWithTimeout:1 handler:nil];
84+
self.collectionNode.view.contentOffset = CGPointMake(0, 30);
85+
[self.collectionNode.view layoutIfNeeded];
86+
87+
88+
NSArray *visibleObjects = [[self.adapter visibleObjects] sortedArrayUsingSelector:@selector(compare:)];
89+
NSArray *expectedObjects = @[@3, @4, @5];
90+
XCTAssertEqualObjects(visibleObjects, expectedObjects);
91+
}
92+
93+
- (void)test_whenCollectionViewIsNotInAWindow_updaterDoesNotJustCallReloadData
94+
{
95+
[self.collectionView removeFromSuperview];
96+
97+
[self.collectionView layoutIfNeeded];
98+
self.dataSource.objects = @[@1, @2, @3, @4, @5, @6];
99+
XCTestExpectation *e = [self expectationWithDescription:@"Data update completed"];
100+
101+
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) {
102+
[e fulfill];
103+
}];
104+
[self waitForExpectationsWithTimeout:1 handler:nil];
105+
[self.collectionView layoutIfNeeded];
106+
107+
XCTAssertEqual(self.reloadDataCount, 2);
108+
}
109+
110+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ASListTestCellNode.h
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import <AsyncDisplayKit/AsyncDisplayKit.h>
10+
11+
@interface ASListTestCellNode : ASCellNode
12+
13+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ASListTestCellNode.m
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import "ASListTestCellNode.h"
10+
11+
@implementation ASListTestCellNode
12+
13+
@end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// ASListTestObject.h
3+
// AsyncDisplayKit
4+
//
5+
// Created by Adlai Holler on 12/25/16.
6+
// Copyright © 2016 Facebook. All rights reserved.
7+
//
8+
9+
#import <IGListKit/IGListKit.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface ASListTestObject : NSObject <IGListDiffable, NSCopying>
14+
15+
- (instancetype)initWithKey:(id <NSCopying>)key value:(id)value;
16+
17+
@property (nonatomic, strong, readonly) id key;
18+
@property (nonatomic, strong) id value;
19+
20+
@end
21+
22+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)