From 84ad64029d447a2c9180289ddbca564138d4d862 Mon Sep 17 00:00:00 2001 From: Hannah Trosi Date: Thu, 13 Oct 2016 20:24:15 -0700 Subject: [PATCH] update example projects (note: ASCollectionView deprecation warnings expected) --- .../ASCollectionView/Sample/ViewController.m | 8 +++- .../Controller/VideoFeedNodeController.m | 2 +- examples/ASDKTube/Sample/ViewController.m | 4 +- .../ASDKgram/Sample/PhotoFeedNodeController.m | 4 +- .../Sample/ViewController.h | 4 +- .../Sample/ViewController.m | 40 ++++++++---------- .../Sample/MosaicCollectionViewLayout.h | 4 +- .../Sample/MosaicCollectionViewLayout.m | 14 +------ .../Sample/ViewController.h | 3 +- .../Sample/ViewController.m | 41 ++++++++----------- .../Sample/HorizontalScrollCellNode.h | 2 +- .../Sample/ViewController.h | 4 +- .../Sample/ViewController.m | 25 ++++------- 13 files changed, 65 insertions(+), 90 deletions(-) diff --git a/examples/ASCollectionView/Sample/ViewController.m b/examples/ASCollectionView/Sample/ViewController.m index 6e5e41ceec..302cbf6127 100644 --- a/examples/ASCollectionView/Sample/ViewController.m +++ b/examples/ASCollectionView/Sample/ViewController.m @@ -26,7 +26,7 @@ @interface ViewController () @property (nonatomic, strong) NSArray *data; @end -@interface ViewController () +@interface ViewController () @end @@ -49,12 +49,16 @@ - (void)viewDidLoad layout.headerReferenceSize = CGSizeMake(50.0, 50.0); layout.footerReferenceSize = CGSizeMake(50.0, 50.0); + // This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView. + // This functionality & example project remains for users who insist on using ASCollectionView. self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.collectionView.asyncDataSource = self; self.collectionView.asyncDelegate = self; self.collectionView.backgroundColor = [UIColor whiteColor]; + // This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView. + // This functionality & example project remains for users who insist on using ASCollectionView. [self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader]; [self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter]; [self.view addSubview:self.collectionView]; @@ -92,6 +96,8 @@ - (void)viewDidLoad - (void)reloadTapped { + // This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView. + // This functionality & example project remains for users who insist on using ASCollectionView. [self.collectionView reloadData]; } diff --git a/examples/ASDKTube/Sample/Controller/VideoFeedNodeController.m b/examples/ASDKTube/Sample/Controller/VideoFeedNodeController.m index 5c464f0dd3..dffa7887ed 100644 --- a/examples/ASDKTube/Sample/Controller/VideoFeedNodeController.m +++ b/examples/ASDKTube/Sample/Controller/VideoFeedNodeController.m @@ -52,7 +52,7 @@ - (void)loadView [self generateFeedData]; - [_tableNode.view reloadData]; + [_tableNode reloadData]; } - (void)generateFeedData diff --git a/examples/ASDKTube/Sample/ViewController.m b/examples/ASDKTube/Sample/ViewController.m index 2480c3d407..f70d4ebe14 100644 --- a/examples/ASDKTube/Sample/ViewController.m +++ b/examples/ASDKTube/Sample/ViewController.m @@ -50,7 +50,7 @@ - (void)loadView _videoFeedData = [[NSMutableArray alloc] initWithObjects:[[VideoModel alloc] init], [[VideoModel alloc] init], nil]; - [_tableNode.view reloadData]; + [_tableNode reloadData]; } - (void)viewWillAppear:(BOOL)animated @@ -216,4 +216,4 @@ - (ASVideoPlayerNode *)videoPlayerNode; return mainVerticalStack; }*/ -@end \ No newline at end of file +@end diff --git a/examples/ASDKgram/Sample/PhotoFeedNodeController.m b/examples/ASDKgram/Sample/PhotoFeedNodeController.m index 2a44028fdc..a11060b80e 100644 --- a/examples/ASDKgram/Sample/PhotoFeedNodeController.m +++ b/examples/ASDKgram/Sample/PhotoFeedNodeController.m @@ -144,7 +144,7 @@ - (void)insertNewRowsInTableView:(NSArray *)newPhotos [indexPaths addObject:path]; } - [_tableNode.view insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; + [_tableNode insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; } - (UIStatusBarStyle)preferredStatusBarStyle @@ -192,7 +192,7 @@ - (void)tableView:(ASTableView *)tableView willBeginBatchFetchWithContext:(ASBat - (void)resetAllData { [_photoFeed clearFeed]; - [_tableNode.view reloadData]; + [_tableNode reloadData]; [self refreshFeed]; } diff --git a/examples/CatDealsCollectionView/Sample/ViewController.h b/examples/CatDealsCollectionView/Sample/ViewController.h index fc52c022f2..db689fe324 100644 --- a/examples/CatDealsCollectionView/Sample/ViewController.h +++ b/examples/CatDealsCollectionView/Sample/ViewController.h @@ -15,8 +15,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#import +#import -@interface ViewController : UIViewController +@interface ViewController : ASViewController @end diff --git a/examples/CatDealsCollectionView/Sample/ViewController.m b/examples/CatDealsCollectionView/Sample/ViewController.m index 71bd7fa5d7..4cec349673 100644 --- a/examples/CatDealsCollectionView/Sample/ViewController.m +++ b/examples/CatDealsCollectionView/Sample/ViewController.m @@ -29,9 +29,9 @@ static const CGFloat kHorizontalSectionPadding = 10.0f; static const CGFloat kVerticalSectionPadding = 20.0f; -@interface ViewController () +@interface ViewController () { - ASCollectionView *_collectionView; + ASCollectionNode *_collectionNode; NSMutableArray *_data; } @@ -45,7 +45,7 @@ @implementation ViewController - (instancetype)init { - self = [super init]; + self = [super initWithNode:_collectionNode]; if (self) { @@ -53,24 +53,23 @@ - (instancetype)init 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 @@ - (void)viewDidLoad { [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 @@ - (void)fetchMoreCatsWithCompletion:(void (^)(BOOL))completion { - (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 @@ - (NSArray *)indexPathsForObjects:(NSArray *)data { return indexPaths; } -- (void)viewWillLayoutSubviews -{ - _collectionView.frame = self.view.bounds; -} - - - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { - [_collectionView.collectionViewLayout invalidateLayout]; + [_collectionNode.view.collectionViewLayout invalidateLayout]; } - (void)reloadTapped { - [_collectionView reloadData]; + [_collectionNode reloadData]; } #pragma mark - diff --git a/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.h b/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.h index 0acb1dde08..404e55d0a0 100644 --- a/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.h +++ b/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.h @@ -30,7 +30,7 @@ @end -@protocol MosaicCollectionViewLayoutDelegate +@protocol MosaicCollectionViewLayoutDelegate - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MosaicCollectionViewLayout *)layout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath; @@ -38,4 +38,4 @@ @interface MosaicCollectionViewLayoutInspector : NSObject -@end \ No newline at end of file +@end diff --git a/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.m b/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.m index 67f2505f83..bff0657e60 100644 --- a/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.m +++ b/examples/CustomCollectionView/Sample/MosaicCollectionViewLayout.m @@ -214,18 +214,6 @@ - (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSize return ASSizeRangeMake(CGSizeZero, [layout _headerSizeForSection:indexPath.section]); } -/** - * Asks the inspector for the number of supplementary sections in the collection view for the given kind. - */ -- (NSUInteger)collectionView:(ASCollectionView *)collectionView numberOfSectionsForSupplementaryNodeOfKind:(NSString *)kind -{ - if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { - return [[collectionView asyncDataSource] numberOfSectionsInCollectionView:collectionView]; - } else { - return 0; - } -} - /** * Asks the inspector for the number of supplementary views for the given kind in the specified section. */ @@ -238,4 +226,4 @@ - (NSUInteger)collectionView:(ASCollectionView *)collectionView supplementaryNod } } -@end \ No newline at end of file +@end diff --git a/examples/CustomCollectionView/Sample/ViewController.h b/examples/CustomCollectionView/Sample/ViewController.h index fc52c022f2..fb75aa3056 100644 --- a/examples/CustomCollectionView/Sample/ViewController.h +++ b/examples/CustomCollectionView/Sample/ViewController.h @@ -16,7 +16,8 @@ // #import +#import -@interface ViewController : UIViewController +@interface ViewController : ASViewController @end diff --git a/examples/CustomCollectionView/Sample/ViewController.m b/examples/CustomCollectionView/Sample/ViewController.m index c2aee53b2f..86e845af8a 100644 --- a/examples/CustomCollectionView/Sample/ViewController.m +++ b/examples/CustomCollectionView/Sample/ViewController.m @@ -23,10 +23,10 @@ static NSUInteger kNumberOfImages = 14; -@interface ViewController () +@interface ViewController () { NSMutableArray *_sections; - ASCollectionView *_collectionView; + ASCollectionNode *_collectionNode; MosaicCollectionViewLayoutInspector *_layoutInspector; } @@ -39,7 +39,7 @@ @implementation ViewController - (instancetype)init { - if (!(self = [super init])) + if (!(self = [super initWithNode:_collectionNode])) return nil; _sections = [NSMutableArray array]; @@ -59,44 +59,37 @@ - (instancetype)init _layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init]; - _collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; - _collectionView.asyncDataSource = self; - _collectionView.asyncDelegate = self; - _collectionView.layoutInspector = _layoutInspector; - _collectionView.backgroundColor = [UIColor whiteColor]; + _collectionNode.dataSource = self; + _collectionNode.delegate = self; + _collectionNode.backgroundColor = [UIColor whiteColor]; - [_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader]; + [_collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader]; return self; } -- (void)dealloc -{ - _collectionView.asyncDataSource = nil; - _collectionView.asyncDelegate = nil; -} - - (void)viewDidLoad { [super viewDidLoad]; - [self.view addSubview:_collectionView]; + _collectionNode.view.layoutInspector = _layoutInspector; } -- (void)viewWillLayoutSubviews +- (void)dealloc { - _collectionView.frame = self.view.bounds; + _collectionNode.dataSource = nil; + _collectionNode.delegate = nil; } - (void)reloadTapped { - [_collectionView reloadData]; + [_collectionNode reloadDataWithCompletion:^{}]; } #pragma mark - #pragma mark ASCollectionView data source. -- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { UIImage *image = _sections[indexPath.section][indexPath.item]; return ^{ @@ -105,7 +98,7 @@ - (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockFo } -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { NSDictionary *textAttributes = @{ NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline], @@ -117,17 +110,17 @@ - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplem return textCellNode; } -- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView +- (NSInteger)numberOfSectionsInCollectionView:(ASCollectionNode *)collectionNode { return _sections.count; } -- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section +- (NSInteger)collectionView:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section { return [_sections[section] count]; } -- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath +- (CGSize)collectionView:(ASCollectionNode *)collectionNode layout:(UICollectionViewLayout *)collectionViewLayout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath { return [(UIImage *)_sections[indexPath.section][indexPath.item] size]; } diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.h b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.h index 7443d66db5..07133747fb 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.h +++ b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.h @@ -21,7 +21,7 @@ * This ASCellNode contains an ASCollectionNode. It intelligently interacts with a containing ASCollectionView or ASTableView, * to preload and clean up contents as the user scrolls around both vertically and horizontally — in a way that minimizes memory usage. */ -@interface HorizontalScrollCellNode : ASCellNode +@interface HorizontalScrollCellNode : ASCellNode - (instancetype)initWithElementSize:(CGSize)size; diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.h b/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.h index fc52c022f2..db689fe324 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.h +++ b/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.h @@ -15,8 +15,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#import +#import -@interface ViewController : UIViewController +@interface ViewController : ASViewController @end diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.m b/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.m index fbc1cd7ee7..cfc66a8a5f 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.m +++ b/examples/HorizontalWithinVerticalScrolling/Sample/ViewController.m @@ -15,15 +15,14 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#import #import #import "ViewController.h" #import "HorizontalScrollCellNode.h" -@interface ViewController () +@interface ViewController () { - ASTableView *_tableView; + ASTableNode *_tableNode; } @end @@ -35,13 +34,12 @@ @implementation ViewController - (instancetype)init { - if (!(self = [super init])) + if (!(self = [super initWithNode:_tableNode])) return nil; - _tableView = [[ASTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; - _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; - _tableView.asyncDataSource = self; - _tableView.asyncDelegate = self; + _tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain]; + _tableNode.dataSource = self; + _tableNode.delegate = self; self.title = @"Horizontal Scrolling Gradients"; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRedo @@ -51,21 +49,16 @@ - (instancetype)init return self; } -- (void)reloadEverything -{ - [_tableView reloadData]; -} - - (void)viewDidLoad { [super viewDidLoad]; - [self.view addSubview:_tableView]; + _tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone; } -- (void)viewWillLayoutSubviews +- (void)reloadEverything { - _tableView.frame = self.view.bounds; + [_tableNode reloadDataWithCompletion:nil]; } #pragma mark - ASTableView.