This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
IGListKit Support II: Electric Boogaloo #2942
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d196c46
Reimplement IGListKit support in a cleaner way
Adlai-Holler 6010dc0
Rename and fix some stuff
5a77bbc
Fix supplementaries more
5049ff9
Update docs
5f91ff9
Update test
f9778d8
Cleanup minor things
ce11c37
Tweak it
Adlai-Holler 5812b12
Indentation
Adlai-Holler 9dc2995
Remove irrelevant changes
Adlai-Holler 727c01e
Break out cell into its own file
a2444bd
Fix indentation
bcef25d
Address feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
ASDKListKit/ASDKListKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
ASDKListKit/ASDKListKit.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
ASDKListKit/ASDKListKitTests/ASListKitTestAdapterDataSource.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// ASListKitTestAdapterDataSource.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <IGListKit/IGListKit.h> | ||
|
||
@interface ASListKitTestAdapterDataSource : NSObject <IGListAdapterDataSource> | ||
|
||
// array of numbers which is then passed to -[IGListTestSection setItems:] | ||
@property (nonatomic, strong) NSArray <NSNumber *> *objects; | ||
|
||
@end |
27 changes: 27 additions & 0 deletions
27
ASDKListKit/ASDKListKitTests/ASListKitTestAdapterDataSource.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ASListKitTestAdapterDataSource.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASListKitTestAdapterDataSource.h" | ||
#import "ASListTestSection.h" | ||
|
||
@implementation ASListKitTestAdapterDataSource | ||
|
||
- (NSArray *)objectsForListAdapter:(IGListAdapter *)listAdapter { | ||
return self.objects; | ||
} | ||
|
||
- (IGListSectionController <IGListSectionType> *)listAdapter:(IGListAdapter *)listAdapter sectionControllerForObject:(id)object { | ||
ASListTestSection *section = [[ASListTestSection alloc] init]; | ||
return section; | ||
} | ||
|
||
- (nullable UIView *)emptyViewForListAdapter:(IGListAdapter *)listAdapter { | ||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// ASListKitTests.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
#import "ASListKitTestAdapterDataSource.h" | ||
#import "ASXCTExtensions.h" | ||
#import <JGMethodSwizzler/JGMethodSwizzler.h> | ||
|
||
@interface ASListKitTests : XCTestCase | ||
|
||
@property (nonatomic, strong) ASCollectionNode *collectionNode; | ||
@property (nonatomic, strong) UICollectionView *collectionView; | ||
@property (nonatomic, strong) IGListAdapter *adapter; | ||
@property (nonatomic, strong) ASListKitTestAdapterDataSource *dataSource; | ||
@property (nonatomic, strong) UICollectionViewFlowLayout *layout; | ||
@property (nonatomic, strong) UIWindow *window; | ||
@property (nonatomic) NSInteger reloadDataCount; | ||
|
||
@end | ||
|
||
@implementation ASListKitTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
[ASCollectionView swizzleInstanceMethod:@selector(reloadData) withReplacement:JGMethodReplacementProviderBlock { | ||
return JGMethodReplacement(void, ASCollectionView *) { | ||
JGOriginalImplementation(void); | ||
_reloadDataCount++; | ||
}; | ||
}]; | ||
|
||
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | ||
|
||
self.layout = [[UICollectionViewFlowLayout alloc] init]; | ||
self.collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:self.layout]; | ||
self.collectionNode.frame = self.window.bounds; | ||
self.collectionView = self.collectionNode.view; | ||
|
||
[self.window addSubnode:self.collectionNode]; | ||
|
||
IGListAdapterUpdater *updater = [[IGListAdapterUpdater alloc] init]; | ||
|
||
self.dataSource = [[ASListKitTestAdapterDataSource alloc] init]; | ||
self.adapter = [[IGListAdapter alloc] initWithUpdater:updater | ||
viewController:nil | ||
workingRangeSize:0]; | ||
self.adapter.dataSource = self.dataSource; | ||
[self.adapter becomeDataSourceAndDelegateForCollectionNode:self.collectionNode]; | ||
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."); | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
XCTAssert([ASCollectionView deswizzleAllMethods]); | ||
self.reloadDataCount = 0; | ||
self.window = nil; | ||
self.collectionNode = nil; | ||
self.collectionView = nil; | ||
self.adapter = nil; | ||
self.dataSource = nil; | ||
self.layout = nil; | ||
} | ||
|
||
- (void)test_whenAdapterUpdated_withObjectsOverflow_thatVisibleObjectsIsSubsetOfAllObjects { | ||
// each section controller returns n items sized 100x10 | ||
self.dataSource.objects = @[@1, @2, @3, @4, @5, @6]; | ||
XCTestExpectation *e = [self expectationWithDescription:@"Data update completed"]; | ||
|
||
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) { | ||
[e fulfill]; | ||
}]; | ||
|
||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
self.collectionNode.view.contentOffset = CGPointMake(0, 30); | ||
[self.collectionNode.view layoutIfNeeded]; | ||
|
||
|
||
NSArray *visibleObjects = [[self.adapter visibleObjects] sortedArrayUsingSelector:@selector(compare:)]; | ||
NSArray *expectedObjects = @[@3, @4, @5]; | ||
XCTAssertEqualObjects(visibleObjects, expectedObjects); | ||
} | ||
|
||
- (void)test_whenCollectionViewIsNotInAWindow_updaterDoesNotJustCallReloadData | ||
{ | ||
[self.collectionView removeFromSuperview]; | ||
|
||
[self.collectionView layoutIfNeeded]; | ||
self.dataSource.objects = @[@1, @2, @3, @4, @5, @6]; | ||
XCTestExpectation *e = [self expectationWithDescription:@"Data update completed"]; | ||
|
||
[self.adapter performUpdatesAnimated:NO completion:^(BOOL finished) { | ||
[e fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
[self.collectionView layoutIfNeeded]; | ||
|
||
XCTAssertEqual(self.reloadDataCount, 2); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ASListTestCellNode.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface ASListTestCellNode : ASCellNode | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ASListTestCellNode.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASListTestCellNode.h" | ||
|
||
@implementation ASListTestCellNode | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// ASListTestObject.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <IGListKit/IGListKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ASListTestObject : NSObject <IGListDiffable, NSCopying> | ||
|
||
- (instancetype)initWithKey:(id <NSCopying>)key value:(id)value; | ||
|
||
@property (nonatomic, strong, readonly) id key; | ||
@property (nonatomic, strong) id value; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// ASListTestObject.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASListTestObject.h" | ||
|
||
@implementation ASListTestObject | ||
|
||
- (instancetype)initWithKey:(id)key value:(id)value { | ||
if (self = [super init]) { | ||
_key = [key copy]; | ||
_value = value; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)copyWithZone:(NSZone *)zone { | ||
return [[ASListTestObject alloc] initWithKey:self.key value:self.value]; | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Extra return here. Is there a standard on protocol names? Would it make sense for the pragma mark to say or protocol ? |
||
#pragma mark - IGListDiffable | ||
|
||
- (id<NSObject>)diffIdentifier { | ||
return self.key; | ||
} | ||
|
||
- (BOOL)isEqualToDiffableObject:(id)object { | ||
if (object == self) { | ||
return YES; | ||
} | ||
if ([object isKindOfClass:[ASListTestObject class]]) { | ||
id k1 = self.key; | ||
id k2 = [object key]; | ||
id v1 = self.value; | ||
id v2 = [(ASListTestObject *)object value]; | ||
return (v1 == v2 || [v1 isEqual:v2]) && (k1 == k2 || [k1 isEqual:k2]); | ||
} | ||
return NO; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// ASListTestSection.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <IGListKit/IGListKit.h> | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface ASListTestSection : IGListSectionController <IGListSectionType, ASSectionController> | ||
|
||
@property (nonatomic) NSInteger itemCount; | ||
|
||
@property (nonatomic) NSInteger selectedItemIndex; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// ASListTestSection.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASListTestSection.h" | ||
#import "ASListTestCellNode.h" | ||
|
||
@implementation ASListTestSection | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
_selectedItemIndex = NSNotFound; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSInteger)numberOfItems { | ||
return self.itemCount; | ||
} | ||
|
||
- (CGSize)sizeForItemAtIndex:(NSInteger)index { | ||
ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); | ||
return CGSizeMake(100, 10); | ||
} | ||
|
||
ASIGSectionControllerCellForIndexImplementation | ||
|
||
- (void)didUpdateToObject:(id)object { | ||
if ([object isKindOfClass:[NSNumber class]]) { | ||
self.itemCount = [object integerValue]; | ||
} | ||
} | ||
|
||
- (void)didSelectItemAtIndex:(NSInteger)index { | ||
self.selectedItemIndex = index; | ||
} | ||
|
||
- (ASCellNodeBlock)nodeBlockForItemAtIndex:(NSInteger)index | ||
{ | ||
return ^{ | ||
ASListTestCellNode *node = [[ASListTestCellNode alloc] init]; | ||
node.style.preferredSize = CGSizeMake(100, 10); | ||
return node; | ||
}; | ||
} | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
ASDKListKit/ASDKListKitTests/ASListTestSupplementaryNode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ASListTestSupplementaryNode.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface ASListTestSupplementaryNode : ASCellNode | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
ASDKListKit/ASDKListKitTests/ASListTestSupplementaryNode.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ASListTestSupplementaryNode.m | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import "ASListTestSupplementaryNode.h" | ||
|
||
@implementation ASListTestSupplementaryNode | ||
|
||
@end |
20 changes: 20 additions & 0 deletions
20
ASDKListKit/ASDKListKitTests/ASListTestSupplementarySource.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// ASListTestSupplementarySource.h | ||
// AsyncDisplayKit | ||
// | ||
// Created by Adlai Holler on 12/25/16. | ||
// Copyright © 2016 Facebook. All rights reserved. | ||
// | ||
|
||
#import <IGListKit/IGListKit.h> | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface ASListTestSupplementarySource : NSObject <IGListSupplementaryViewSource, ASSupplementaryNodeSource> | ||
|
||
@property (nonatomic, strong, readwrite) NSArray<NSString *> *supportedElementKinds; | ||
|
||
@property (nonatomic, weak) id<IGListCollectionContext> collectionContext; | ||
|
||
@property (nonatomic, weak) IGListSectionController<IGListSectionType> *sectionController; | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The default-inserted methods use the brace-at-end-of-name style, so we should bump it down.