mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Add functioning header/footer supplementary view support to example
This commit is contained in:
committed by
Levi McCallum
parent
6e49e1f4d5
commit
e410595f42
18
examples/ASCollectionView/Sample/SupplementaryNode.h
Normal file
18
examples/ASCollectionView/Sample/SupplementaryNode.h
Normal file
@@ -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 SupplementaryNode : ASDisplayNode
|
||||
|
||||
- (instancetype)initWithText:(NSString *)text;
|
||||
|
||||
@end
|
||||
54
examples/ASCollectionView/Sample/SupplementaryNode.m
Normal file
54
examples/ASCollectionView/Sample/SupplementaryNode.m
Normal file
@@ -0,0 +1,54 @@
|
||||
/* 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 "SupplementaryNode.h"
|
||||
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
|
||||
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
|
||||
|
||||
static CGFloat kInsets = 15.0;
|
||||
|
||||
@implementation SupplementaryNode {
|
||||
ASTextNode *_textNode;
|
||||
}
|
||||
|
||||
- (instancetype)initWithText:(NSString *)text
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_textNode = [[ASTextNode alloc] init];
|
||||
_textNode.attributedString = [[NSAttributedString alloc] initWithString:text
|
||||
attributes:[self textAttributes]];
|
||||
[self addSubnode:_textNode];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASCenterLayoutSpec *center = [[ASCenterLayoutSpec alloc] init];
|
||||
center.child = _textNode;
|
||||
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
|
||||
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
|
||||
}
|
||||
|
||||
#pragma mark - Text Formatting
|
||||
|
||||
- (NSDictionary *)textAttributes
|
||||
{
|
||||
return @{
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:18.0],
|
||||
NSForegroundColorAttributeName: [UIColor whiteColor],
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,6 +12,7 @@
|
||||
#import "ViewController.h"
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
#import "SupplementaryNode.h"
|
||||
|
||||
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
|
||||
{
|
||||
@@ -32,8 +33,8 @@
|
||||
return nil;
|
||||
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
layout.headerReferenceSize = CGSizeMake(50.0, 50.0);
|
||||
layout.footerReferenceSize = CGSizeMake(50.0, 50.0);
|
||||
|
||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout asyncDataFetching:YES];
|
||||
_collectionView.asyncDataSource = self;
|
||||
@@ -79,7 +80,8 @@
|
||||
|
||||
- (ASDisplayNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
ASDisplayNode *node = [[ASDisplayNode alloc] init];
|
||||
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
|
||||
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];
|
||||
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
|
||||
node.backgroundColor = [UIColor blueColor];
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user