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

Commit

Permalink
update example projects (note: ASCollectionView deprecation warnings …
Browse files Browse the repository at this point in the history
…expected)
  • Loading branch information
hannahmbanana authored and Adlai Holler committed Oct 14, 2016
1 parent 7313ca8 commit 84ad640
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 90 deletions.
8 changes: 7 additions & 1 deletion examples/ASCollectionView/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @interface ViewController ()
@property (nonatomic, strong) NSArray *data;
@end

@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>

@end

Expand All @@ -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];
Expand Down Expand Up @@ -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];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)loadView

[self generateFeedData];

[_tableNode.view reloadData];
[_tableNode reloadData];
}

- (void)generateFeedData
Expand Down
4 changes: 2 additions & 2 deletions examples/ASDKTube/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,4 +216,4 @@ - (ASVideoPlayerNode *)videoPlayerNode;
return mainVerticalStack;
}*/

@end
@end
4 changes: 2 additions & 2 deletions examples/ASDKgram/Sample/PhotoFeedNodeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ - (void)insertNewRowsInTableView:(NSArray *)newPhotos
[indexPaths addObject:path];
}

[_tableNode.view insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[_tableNode insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
}

- (UIStatusBarStyle)preferredStatusBarStyle
Expand Down Expand Up @@ -192,7 +192,7 @@ - (void)tableView:(ASTableView *)tableView willBeginBatchFetchWithContext:(ASBat
- (void)resetAllData
{
[_photoFeed clearFeed];
[_tableNode.view reloadData];
[_tableNode reloadData];
[self refreshFeed];
}

Expand Down
4 changes: 2 additions & 2 deletions examples/CatDealsCollectionView/Sample/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/AsyncDisplayKit.h>

@interface ViewController : UIViewController
@interface ViewController : ASViewController

@end
40 changes: 17 additions & 23 deletions examples/CatDealsCollectionView/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
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;
}

Expand All @@ -45,32 +45,31 @@ @implementation ViewController

- (instancetype)init
{
self = [super init];
self = [super initWithNode:_collectionNode];

if (self) {

self.title = @"Cat Deals";

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];

Expand All @@ -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];
}

Expand Down Expand Up @@ -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];
});
}
Expand All @@ -142,19 +142,13 @@ - (NSArray *)indexPathsForObjects:(NSArray *)data {
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 -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

@end

@protocol MosaicCollectionViewLayoutDelegate <ASCollectionViewDelegate>
@protocol MosaicCollectionViewLayoutDelegate <ASCollectionDelegate>

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(MosaicCollectionViewLayout *)layout originalItemSizeAtIndexPath:(NSIndexPath *)indexPath;

@end

@interface MosaicCollectionViewLayoutInspector : NSObject <ASCollectionViewLayoutInspecting>

@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -238,4 +226,4 @@ - (NSUInteger)collectionView:(ASCollectionView *)collectionView supplementaryNod
}
}

@end
@end
3 changes: 2 additions & 1 deletion examples/CustomCollectionView/Sample/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//

#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/AsyncDisplayKit.h>

@interface ViewController : UIViewController
@interface ViewController : ASViewController

@end
41 changes: 17 additions & 24 deletions examples/CustomCollectionView/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

static NSUInteger kNumberOfImages = 14;

@interface ViewController () <ASCollectionViewDataSource, MosaicCollectionViewLayoutDelegate>
@interface ViewController () <ASCollectionDataSource, ASCollectionDelegate>
{
NSMutableArray *_sections;
ASCollectionView *_collectionView;
ASCollectionNode *_collectionNode;
MosaicCollectionViewLayoutInspector *_layoutInspector;
}

Expand All @@ -39,7 +39,7 @@ @implementation ViewController

- (instancetype)init
{
if (!(self = [super init]))
if (!(self = [super initWithNode:_collectionNode]))
return nil;

_sections = [NSMutableArray array];
Expand All @@ -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 ^{
Expand All @@ -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],
Expand All @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ASCollectionViewDelegate, ASCollectionViewDataSource>
@interface HorizontalScrollCellNode : ASCellNode <ASCollectionDelegate, ASCollectionDataSource>

- (instancetype)initWithElementSize:(CGSize)size;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/AsyncDisplayKit.h>

@interface ViewController : UIViewController
@interface ViewController : ASViewController

@end
Loading

0 comments on commit 84ad640

Please sign in to comment.