mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
[Examples] 2.0 Collection/Table API updates (#2390)
* update VerticalWithinHorizontal example * update SocialAppLayout * update Kittens * update HorizontalWithinVerticalScrolling * update AsyncDisplayKitOverview * update CustomCollectionView * CatDealsCollectionView * update Swift * address @appleguy's comment * updates for tableNode deselectRowAtIndexPath
This commit is contained in:
committed by
Adlai Holler
parent
0d439a43b6
commit
0b7dfcc54d
@@ -53,12 +53,12 @@
|
||||
|
||||
#pragma mark - <ASCollectionDataSource, ASCollectionDelegate>
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return ^{
|
||||
ASTextCellNode *cellNode = [ASTextCellNode new];
|
||||
@@ -68,7 +68,7 @@
|
||||
};
|
||||
}
|
||||
|
||||
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return ASSizeRangeMake(CGSizeMake(100, 100));
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
|
||||
#pragma mark - <ASCollectionDataSource, ASCollectionDelegate>
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return ^{
|
||||
ASTextCellNode *cellNode = [ASTextCellNode new];
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
|
||||
@protocol ASLayoutSpecListEntry <NSObject>
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface OverviewComponentsViewController : UIViewController
|
||||
@interface OverviewComponentsViewController : ASViewController
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,12 +31,15 @@
|
||||
|
||||
typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constrainedSize);
|
||||
|
||||
|
||||
#pragma mark - OverviewDisplayNodeWithSizeBlock
|
||||
|
||||
@interface OverviewDisplayNodeWithSizeBlock : ASDisplayNode<ASLayoutSpecListEntry>
|
||||
|
||||
@property (nonatomic, copy) NSString *entryTitle;
|
||||
@property (nonatomic, copy) NSString *entryDescription;
|
||||
@property (nonatomic, copy) OverviewDisplayNodeSizeThatFitsBlock sizeThatFitsBlock;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OverviewDisplayNodeWithSizeBlock
|
||||
@@ -54,11 +57,14 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - OverviewTitleDescriptionCellNode
|
||||
|
||||
@interface OverviewTitleDescriptionCellNode : ASCellNode
|
||||
|
||||
@property (nonatomic, strong) ASTextNode *titleNode;
|
||||
@property (nonatomic, strong) ASTextNode *descriptionNode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OverviewTitleDescriptionCellNode
|
||||
@@ -91,16 +97,35 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - OverviewComponentsViewController
|
||||
|
||||
@interface OverviewComponentsViewController ()
|
||||
|
||||
@property (nonatomic, copy) NSArray *data;
|
||||
@property (nonatomic, strong) ASTableNode *tableNode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OverviewComponentsViewController
|
||||
|
||||
#pragma mark - UIViewController
|
||||
|
||||
#pragma mark - Lifecycle Methods
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
_tableNode = [ASTableNode new];
|
||||
|
||||
self = [super initWithNode:_tableNode];
|
||||
|
||||
if (self) {
|
||||
_tableNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
_tableNode.delegate = (id<ASTableDelegate>)self;
|
||||
_tableNode.dataSource = (id<ASTableDataSource>)self;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
@@ -109,18 +134,17 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
self.title = @"AsyncDisplayKit";
|
||||
|
||||
[self setupData];
|
||||
[self setupTableNode];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
ASTableView *tableView = self.tableNode.view;
|
||||
[tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];
|
||||
[_tableNode deselectRowAtIndexPath:_tableNode.view.indexPathForSelectedRow animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Setup
|
||||
|
||||
#pragma mark - Data Model
|
||||
|
||||
- (void)setupData
|
||||
{
|
||||
@@ -452,16 +476,6 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
self.data = mutableData;
|
||||
}
|
||||
|
||||
- (void)setupTableNode
|
||||
{
|
||||
_tableNode = [ASTableNode new];
|
||||
_tableNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
_tableNode.frame = self.view.bounds;
|
||||
_tableNode.delegate = (id<ASTableDelegate>)self;
|
||||
_tableNode.dataSource = (id<ASTableDataSource>)self;
|
||||
[self.view addSubnode:_tableNode];
|
||||
}
|
||||
|
||||
#pragma mark - Parent / Child Helper
|
||||
|
||||
- (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child
|
||||
@@ -505,22 +519,22 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
|
||||
#pragma mark - <ASTableDataSource / ASTableDelegate>
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
- (NSInteger)numberOfSectionsInTableNode:(ASTableNode *)tableNode
|
||||
{
|
||||
return self.data.count;
|
||||
}
|
||||
|
||||
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||||
- (nullable NSString *)tableNode:(ASTableNode *)tableNode titleForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return self.data[section][@"title"];
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(ASTableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return [self.data[section][@"data"] count];
|
||||
}
|
||||
|
||||
- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
// You should get the node or data you want to pass to the cell node outside of the ASCellNodeBlock
|
||||
ASDisplayNode<ASLayoutSpecListEntry> *node = self.data[indexPath.section][@"data"][indexPath.row];
|
||||
@@ -542,7 +556,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr
|
||||
};
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
ASDisplayNode *node = self.data[indexPath.section][@"data"][indexPath.row];
|
||||
OverviewDetailViewController *detail = [[OverviewDetailViewController alloc] initWithNode:node];
|
||||
|
||||
Reference in New Issue
Block a user