Add support for IGListKit > 2.1, without IGListCollectionView (#3239)

This commit is contained in:
Adlai Holler 2017-04-03 12:52:36 -07:00 committed by GitHub
parent 42eb955d8f
commit e1f7b86756
4 changed files with 18 additions and 10 deletions

View File

@ -3,7 +3,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0' platform :ios, '8.0'
target 'ASDKListKitTests' do target 'ASDKListKitTests' do
pod 'AsyncDisplayKit/IGListKit', :path => '..' pod 'AsyncDisplayKit/IGListKit', :path => '..'
pod 'IGListKit', :git => 'https://github.com/Instagram/IGListKit', :commit => '5eca718' pod 'IGListKit', :git => 'https://github.com/Instagram/IGListKit', :commit => 'e9e09d7'
pod 'JGMethodSwizzler', :git => 'https://github.com/JonasGessner/JGMethodSwizzler', :branch => 'master' pod 'JGMethodSwizzler', :git => 'https://github.com/JonasGessner/JGMethodSwizzler', :branch => 'master'
end end

View File

@ -21,4 +21,10 @@
#ifndef IG_LIST_KIT #ifndef IG_LIST_KIT
#define IG_LIST_KIT __has_include(<IGListKit/IGListKit.h>) #define IG_LIST_KIT __has_include(<IGListKit/IGListKit.h>)
/**
* For IGListKit versions < 3.0, you have to use IGListCollectionView.
* For 3.0 and later, that class is removed and you use UICollectionView.
*/
#define IG_LIST_COLLECTION_VIEW __has_include(<IGListKit/IGListCollectionView.h>)
#endif #endif

View File

@ -36,9 +36,12 @@
collectionNode.delegate = dataSource; collectionNode.delegate = dataSource;
__weak IGListAdapter *weakSelf = self; __weak IGListAdapter *weakSelf = self;
[collectionNode onDidLoad:^(__kindof ASCollectionNode * _Nonnull collectionNode) { [collectionNode onDidLoad:^(__kindof ASCollectionNode * _Nonnull collectionNode) {
// We manually set the superclass of ASCollectionView to IGListCollectionView at runtime. #if IG_LIST_COLLECTION_VIEW
// Issue tracked at https://github.com/Instagram/IGListKit/issues/409 // We manually set the superclass of ASCollectionView to IGListCollectionView at runtime if needed.
weakSelf.collectionView = (IGListCollectionView *)collectionNode.view; weakSelf.collectionView = (IGListCollectionView *)collectionNode.view;
#else
weakSelf.collectionView = collectionNode.view;
#endif
}]; }];
} }

View File

@ -42,7 +42,7 @@ typedef struct {
* and then we use it and clear it in beginBatchFetchWithContext: (on default queue). * and then we use it and clear it in beginBatchFetchWithContext: (on default queue).
* *
* It is safe to use it without a lock in this limited way, since those two methods will * It is safe to use it without a lock in this limited way, since those two methods will
* never execute in parallel.6 * never execute in parallel.
*/ */
@property (nonatomic, weak) ASIGSectionController *sectionControllerForBatchFetching; @property (nonatomic, weak) ASIGSectionController *sectionControllerForBatchFetching;
@end @end
@ -52,7 +52,9 @@ typedef struct {
- (instancetype)initWithListAdapter:(IGListAdapter *)listAdapter - (instancetype)initWithListAdapter:(IGListAdapter *)listAdapter
{ {
if (self = [super init]) { if (self = [super init]) {
#if IG_LIST_COLLECTION_VIEW
[ASIGListAdapterBasedDataSource setASCollectionViewSuperclass]; [ASIGListAdapterBasedDataSource setASCollectionViewSuperclass];
#endif
[ASIGListAdapterBasedDataSource configureUpdater:listAdapter.updater]; [ASIGListAdapterBasedDataSource configureUpdater:listAdapter.updater];
ASDisplayNodeAssert([listAdapter conformsToProtocol:@protocol(UICollectionViewDataSource)], @"Expected IGListAdapter to conform to UICollectionViewDataSource."); ASDisplayNodeAssert([listAdapter conformsToProtocol:@protocol(UICollectionViewDataSource)], @"Expected IGListAdapter to conform to UICollectionViewDataSource.");
@ -244,12 +246,8 @@ typedef struct {
return ctrl; return ctrl;
} }
/** /// If needed, set ASCollectionView's superclass to IGListCollectionView (IGListKit < 3.0).
* Set ASCollectionView's superclass to IGListCollectionView. #if IG_LIST_COLLECTION_VIEW
* Scary! If IGListKit removed the subclassing restriction, we could
* use #if in the @interface to choose the superclass based on
* whether we have IGListKit available.
*/
+ (void)setASCollectionViewSuperclass + (void)setASCollectionViewSuperclass
{ {
#pragma clang diagnostic push #pragma clang diagnostic push
@ -260,6 +258,7 @@ typedef struct {
}); });
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }
#endif
/// Ensure updater won't call reloadData on us. /// Ensure updater won't call reloadData on us.
+ (void)configureUpdater:(id<IGListUpdatingDelegate>)updater + (void)configureUpdater:(id<IGListUpdatingDelegate>)updater