[Umbrella] ASCollectionView -> ASCollectionNode Migration, Separate Index Spaces (#2372)

* Separate dataSource & UIKit index spaces

Beef up our supplementary node support

Make the API way better

Go nuts

Add a unit test for UICollectionView's handling of reloadData inside batch updates

Wrap indexPathForNode: in a cache

Convert index paths in delegate methods

Go back on table view

Put collection view back

Switch up the API

Move most ASCollectionView API to ASCollectionNode

Move most table logic over to ASTableNode

Do the things

More conversion work

Keep on keepin' on

Get table view delegate API done

More porting

Simplify

Clear the delegate

More cleanup

Move more stuff around

Remove pointless file

Re-add some API

Put back more API

Use the right flag

* Some cleanup

* Remove incorrect comment

* Tweak the API

* Put back a couple methods

* update example projects (note: ASCollectionView deprecation warnings expected)

* change reloadDataWithCompletion:nil --> reloadData

* Clean up rebase

* Make deprecated numberOfItemsInSection methods optional

* Use the right flag

* Address nits

* update ASDKTube, ASDKgram & ASViewController examples
This commit is contained in:
Adlai Holler
2016-10-14 17:21:16 -07:00
committed by GitHub
parent fb768683bc
commit c2ea7cfeac
50 changed files with 3448 additions and 1122 deletions

View File

@@ -29,9 +29,9 @@ static const NSInteger kBatchSize = 20;
static const CGFloat kHorizontalSectionPadding = 10.0f;
static const CGFloat kVerticalSectionPadding = 20.0f;
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>
{
ASCollectionView *_collectionView;
ASCollectionNode *_collectionNode;
NSMutableArray *_data;
}
@@ -45,7 +45,7 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
- (instancetype)init
{
self = [super init];
self = [super initWithNode:_collectionNode];
if (self) {
@@ -53,24 +53,23 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.asyncDataSource = self;
_collectionView.asyncDelegate = self;
_collectionView.backgroundColor = [UIColor grayColor];
_collectionView.leadingScreensForBatching = 2;
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:layout];
_collectionNode.dataSource = self;
_collectionNode.delegate = self;
_collectionNode.backgroundColor = [UIColor grayColor];
ASRangeTuningParameters preloadTuning;
preloadTuning.leadingBufferScreenfuls = 2;
preloadTuning.trailingBufferScreenfuls = 1;
[_collectionView setTuningParameters:preloadTuning forRangeType:ASLayoutRangeTypePreload];
[_collectionNode setTuningParameters:preloadTuning forRangeType:ASLayoutRangeTypePreload];
ASRangeTuningParameters preRenderTuning;
preRenderTuning.leadingBufferScreenfuls = 1;
preRenderTuning.trailingBufferScreenfuls = 0.5;
[_collectionView setTuningParameters:preRenderTuning forRangeType:ASLayoutRangeTypeDisplay];
[_collectionNode setTuningParameters:preRenderTuning forRangeType:ASLayoutRangeTypeDisplay];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
[_collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
[_collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
_data = [[NSMutableArray alloc] init];
@@ -85,7 +84,8 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
{
[super viewDidLoad];
[self.view addSubview:_collectionView];
// set any collectionView properties here (once the node's backing view is loaded)
_collectionNode.view.leadingScreensForBatching = 2;
[self fetchMoreCatsWithCompletion:nil];
}
@@ -115,10 +115,10 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
- (void)appendMoreItems:(NSInteger)numberOfNewItems completion:(void (^)(BOOL))completion {
NSArray *newData = [self getMoreData:numberOfNewItems];
dispatch_async(dispatch_get_main_queue(), ^{
[_collectionView performBatchUpdates:^{
[_collectionNode performBatchAnimated:YES updates:^{
[_data addObjectsFromArray:newData];
NSArray *addedIndexPaths = [self indexPathsForObjects:newData];
[_collectionView insertItemsAtIndexPaths:addedIndexPaths];
[_collectionNode insertItemsAtIndexPaths:addedIndexPaths];
} completion:completion];
});
}
@@ -142,19 +142,13 @@ static const CGFloat kVerticalSectionPadding = 20.0f;
return indexPaths;
}
- (void)viewWillLayoutSubviews
{
_collectionView.frame = self.view.bounds;
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[_collectionView.collectionViewLayout invalidateLayout];
[_collectionNode.view.collectionViewLayout invalidateLayout];
}
- (void)reloadTapped
{
[_collectionView reloadData];
[_collectionNode reloadData];
}
#pragma mark -