Skip to content

Commit 0dd170d

Browse files
author
Hannah Troisi
authored
clean up ASCollectionView example project (facebookarchive#2384)
1 parent 1fbcefd commit 0dd170d

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

examples/ASCollectionView/Sample/ItemNode.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ @implementation ItemNode
2222
- (instancetype)initWithString:(NSString *)string
2323
{
2424
self = [super init];
25+
2526
if (self != nil) {
2627
self.text = string;
2728
[self updateBackgroundColor];
2829
}
30+
2931
return self;
3032
}
3133

@@ -43,12 +45,14 @@ - (void)updateBackgroundColor
4345
- (void)setSelected:(BOOL)selected
4446
{
4547
[super setSelected:selected];
48+
4649
[self updateBackgroundColor];
4750
}
4851

4952
- (void)setHighlighted:(BOOL)highlighted
5053
{
5154
[super setHighlighted:highlighted];
55+
5256
[self updateBackgroundColor];
5357
}
5458

examples/ASCollectionView/Sample/PresentingViewController.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ - (void)viewDidLoad
3030
{
3131
[super viewDidLoad];
3232

33-
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
33+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details"
34+
style:UIBarButtonItemStylePlain
35+
target:self
36+
action:@selector(pushNewViewController)];
3437
}
3538

3639
- (void)pushNewViewController

examples/ASCollectionView/Sample/SupplementaryNode.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ @implementation SupplementaryNode
3232
- (instancetype)initWithText:(NSString *)text
3333
{
3434
self = [super init];
35+
3536
if (self != nil) {
3637
_textNode = [[ASTextNode alloc] init];
3738
_textNode.attributedText = [[NSAttributedString alloc] initWithString:text
3839
attributes:[self textAttributes]];
3940
[self addSubnode:_textNode];
4041
}
42+
4143
return self;
4244
}
4345

@@ -47,6 +49,7 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
4749
center.centeringOptions = ASCenterLayoutSpecCenteringXY;
4850
center.child = self.textNode;
4951
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
52+
5053
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
5154
}
5255

examples/ASCollectionView/Sample/ViewController.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@
2121
#import "SupplementaryNode.h"
2222
#import "ItemNode.h"
2323

24-
@interface ViewController ()
24+
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>
25+
2526
@property (nonatomic, strong) ASCollectionView *collectionView;
2627
@property (nonatomic, strong) NSArray *data;
27-
@end
28-
29-
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>
3028

3129
@end
3230

33-
3431
@implementation ViewController
3532

33+
#pragma mark - Lifecycle
34+
3635
- (void)dealloc
3736
{
3837
self.collectionView.asyncDataSource = nil;
@@ -52,20 +51,24 @@ - (void)viewDidLoad
5251
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
5352
// This functionality & example project remains for users who insist on using ASCollectionView.
5453
self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
55-
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
5654
self.collectionView.asyncDataSource = self;
5755
self.collectionView.asyncDelegate = self;
56+
57+
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
5858
self.collectionView.backgroundColor = [UIColor whiteColor];
5959

6060
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
6161
// This functionality & example project remains for users who insist on using ASCollectionView.
6262
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
6363
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
64+
6465
[self.view addSubview:self.collectionView];
6566

6667
#if !SIMULATE_WEB_RESPONSE
6768
self.navigationItem.leftItemsSupplementBackButton = YES;
68-
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
69+
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
70+
target:self
71+
action:@selector(reloadTapped)];
6972
#endif
7073

7174
#if SIMULATE_WEB_RESPONSE
@@ -94,15 +97,16 @@ - (void)viewDidLoad
9497
#endif
9598
}
9699

100+
#pragma mark - Button Actions
101+
97102
- (void)reloadTapped
98103
{
99104
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
100105
// This functionality & example project remains for users who insist on using ASCollectionView.
101106
[self.collectionView reloadData];
102107
}
103108

104-
#pragma mark -
105-
#pragma mark ASCollectionView data source.
109+
#pragma mark - ASCollectionView Data Source
106110

107111
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath;
108112
{

0 commit comments

Comments
 (0)