Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ @interface _ASCollectionViewCell : UICollectionViewCell

@implementation _ASCollectionViewCell

- (void)setNode:(ASCellNode *)node
{
_node = node;
node.selected = self.selected;
node.highlighted = self.highlighted;
}

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
_node.selected = selected;
}

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
_node.highlighted = highlighted;
}

Expand Down Expand Up @@ -478,11 +487,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

ASCellNode *node = [_dataController nodeAtIndexPath:indexPath];

[_rangeController configureContentView:cell.contentView forCellNode:node];

cell.node = node;

[_rangeController configureContentView:cell.contentView forCellNode:node];
return cell;
}

Expand Down
9 changes: 9 additions & 0 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,22 @@ - (void)didTransitionToState:(UITableViewCellStateMask)state
[super didTransitionToState:state];
}

- (void)setNode:(ASCellNode *)node
{
_node = node;
node.selected = self.selected;
node.highlighted = self.highlighted;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
_node.selected = selected;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
_node.highlighted = highlighted;
}

Expand Down
6 changes: 6 additions & 0 deletions examples/ASCollectionView/Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
25FDEC921BF31EE700CEB123 /* ItemNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 25FDEC911BF31EE700CEB123 /* ItemNode.m */; };
9B92C8811BC17D3000EE46B2 /* SupplementaryNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B92C8801BC17D3000EE46B2 /* SupplementaryNode.m */; };
9BA2CEA11BB2579C00D18414 /* Launchboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9BA2CEA01BB2579C00D18414 /* Launchboard.storyboard */; };
AC3C4A641A11F47200143C57 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A631A11F47200143C57 /* main.m */; };
Expand All @@ -17,6 +18,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
25FDEC901BF31EE700CEB123 /* ItemNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ItemNode.h; sourceTree = "<group>"; };
25FDEC911BF31EE700CEB123 /* ItemNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ItemNode.m; sourceTree = "<group>"; };
2DBAEE96397BB913350C4530 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
9B92C87F1BC17D3000EE46B2 /* SupplementaryNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SupplementaryNode.h; sourceTree = "<group>"; };
9B92C8801BC17D3000EE46B2 /* SupplementaryNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SupplementaryNode.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +86,8 @@
AC3C4A611A11F47200143C57 /* Supporting Files */,
9B92C87F1BC17D3000EE46B2 /* SupplementaryNode.h */,
9B92C8801BC17D3000EE46B2 /* SupplementaryNode.m */,
25FDEC901BF31EE700CEB123 /* ItemNode.h */,
25FDEC911BF31EE700CEB123 /* ItemNode.m */,
);
indentWidth = 2;
path = Sample;
Expand Down Expand Up @@ -228,6 +233,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
25FDEC921BF31EE700CEB123 /* ItemNode.m in Sources */,
AC3C4A6A1A11F47200143C57 /* ViewController.m in Sources */,
9B92C8811BC17D3000EE46B2 /* SupplementaryNode.m in Sources */,
AC3C4A671A11F47200143C57 /* AppDelegate.m in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions examples/ASCollectionView/Sample/ItemNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This file provided by Facebook is for non-commercial testing and evaluation
* purposes only. Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import <AsyncDisplayKit/AsyncDisplayKit.h>

@interface ItemNode : ASTextCellNode

- (instancetype)initWithString:(NSString *)string;

@end
49 changes: 49 additions & 0 deletions examples/ASCollectionView/Sample/ItemNode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* This file provided by Facebook is for non-commercial testing and evaluation
* purposes only. Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#import "ItemNode.h"

@implementation ItemNode

- (instancetype)initWithString:(NSString *)string
{
self = [super init];
if (self != nil) {
self.text = string;
[self updateBackgroundColor];
}
return self;
}

- (void)updateBackgroundColor
{
if (self.highlighted) {
self.backgroundColor = [UIColor grayColor];
} else if (self.selected) {
self.backgroundColor = [UIColor darkGrayColor];
} else {
self.backgroundColor = [UIColor lightGrayColor];
}
}

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateBackgroundColor];
}

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateBackgroundColor];
}

@end
7 changes: 2 additions & 5 deletions examples/ASCollectionView/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "SupplementaryNode.h"
#import "ItemNode.h"

@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
{
Expand Down Expand Up @@ -78,11 +79,7 @@ - (void)reloadTapped
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [NSString stringWithFormat:@"[%zd.%zd] says hi", indexPath.section, indexPath.item];
ASTextCellNode *node = [[ASTextCellNode alloc] init];
node.text = text;
node.backgroundColor = [UIColor lightGrayColor];

return node;
return [[ItemNode alloc] initWithString:text];
}

- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
Expand Down
23 changes: 23 additions & 0 deletions examples/Kittens/Sample/KittenNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,27 @@ - (void)toggleNodesSwap
}];
}

- (void)updateBackgroundColor
{
if (self.highlighted) {
self.backgroundColor = [UIColor lightGrayColor];
} else if (self.selected) {
self.backgroundColor = [UIColor blueColor];
} else {
self.backgroundColor = [UIColor whiteColor];
}
}

- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateBackgroundColor];
}

- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateBackgroundColor];
}

@end