mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +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
@@ -15,7 +15,7 @@
|
||||
// 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
|
||||
|
||||
@@ -24,45 +24,47 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@interface ViewController () <ASTableViewDataSource, ASTableViewDelegate>
|
||||
@interface ViewController () <ASTableDataSource, ASTableDelegate>
|
||||
|
||||
@property (nonatomic, strong) ASTableView *tableView;
|
||||
@property (nonatomic, strong) ASTableNode *tableNode;
|
||||
@property (nonatomic, strong) NSMutableArray *socialAppDataSource;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
_tableNode = [[ASTableNode alloc] initWithStyle:UITableViewStylePlain];
|
||||
|
||||
self = [super initWithNode:_tableNode];
|
||||
|
||||
if (self) {
|
||||
|
||||
_tableNode.delegate = self;
|
||||
_tableNode.dataSource = self;
|
||||
_tableNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
self.title = @"Timeline";
|
||||
|
||||
[self createSocialAppDataSource];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
_tableView.asyncDataSource = nil;
|
||||
_tableView.asyncDelegate = nil;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.tableView = [[ASTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
|
||||
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // SocialAppNode has its own separator
|
||||
self.tableView.asyncDataSource = self;
|
||||
self.tableView.asyncDelegate = self;
|
||||
[self.view addSubview:self.tableView];
|
||||
|
||||
// SocialAppNode has its own separator
|
||||
self.tableNode.view.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
}
|
||||
|
||||
#pragma mark - Data Model
|
||||
|
||||
- (void)createSocialAppDataSource
|
||||
{
|
||||
_socialAppDataSource = [[NSMutableArray alloc] init];
|
||||
@@ -116,9 +118,9 @@
|
||||
[_socialAppDataSource addObject:newPost];
|
||||
}
|
||||
|
||||
#pragma mark - ASTableView
|
||||
#pragma mark - ASTableNode
|
||||
|
||||
- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
|
||||
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
Post *post = self.socialAppDataSource[indexPath.row];
|
||||
return ^{
|
||||
@@ -126,14 +128,14 @@
|
||||
};
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return self.socialAppDataSource.count;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
PostNode *postNode = (PostNode *)[_tableView nodeForRowAtIndexPath:indexPath];
|
||||
PostNode *postNode = (PostNode *)[_tableNode nodeForRowAtIndexPath:indexPath];
|
||||
Post *post = self.socialAppDataSource[indexPath.row];
|
||||
|
||||
BOOL shouldRasterize = postNode.shouldRasterizeDescendants;
|
||||
@@ -142,7 +144,7 @@
|
||||
|
||||
NSLog(@"%@ rasterization for %@'s post: %@", shouldRasterize ? @"Enabling" : @"Disabling", post.name, postNode);
|
||||
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
[tableNode deselectRowAtIndexPath:indexPath animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user