-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASTextNode] Implement an example comparing ASTextNode 1 & 2 behavior. (
#570) * fix SIMULATE_WEB_RESPONSE not imported #449 * add constraint to using catching for layout * Add TextNode example to test Yoga Layout * update Yoga version * add debugging log * fix lisence * clean up * clean up * fix lisence warning * add shared scheme * change sdk version * revert some metadata * Merge FlexLayoutExample to TextStressText. Add flags to control different TextNode used. * clean up * fix lisence and syntax * clean up * remove xcworkspacedata * Tiny coding style changes * Another tiny change related to code style
- Loading branch information
1 parent
c12509e
commit dce7ab3
Showing
9 changed files
with
284 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
platform :ios, '8.0' | ||
target 'Sample' do | ||
pod 'Texture', :path => '../..' | ||
pod 'Texture/Yoga', :path => '../..' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples_extra/TextStressTest/Sample/CollectionViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// CollectionViewController.h | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface CollectionViewController : ASViewController | ||
@end |
67 changes: 67 additions & 0 deletions
67
examples_extra/TextStressTest/Sample/CollectionViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// CollectionViewController.m | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import "CollectionViewController.h" | ||
#import "TextCellNode.h" | ||
|
||
@interface CollectionViewController() <ASCollectionDataSource, ASCollectionDelegate> | ||
{ | ||
ASCollectionNode *_collectionNode; | ||
NSArray<NSString *> *_labels; | ||
TextCellNode *_cellNode; | ||
} | ||
|
||
@end | ||
|
||
@implementation CollectionViewController | ||
|
||
- (instancetype)init | ||
{ | ||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; | ||
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:flowLayout]; | ||
CGRect rect = [[UIApplication sharedApplication] statusBarFrame]; | ||
_collectionNode.contentInset = UIEdgeInsetsMake(rect.size.height, 0, 0, 0); | ||
self = [super initWithNode:_collectionNode]; | ||
if (self) { | ||
_collectionNode.delegate = self; | ||
_collectionNode.dataSource = self; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
_collectionNode.backgroundColor = [UIColor whiteColor]; | ||
_labels = @[@"Fight of the Living Dead: Experiment Fight of the Living Dead: Experiment", @"S1 • E1"]; | ||
} | ||
|
||
- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section | ||
{ | ||
return 1; | ||
} | ||
|
||
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return ^{ | ||
_cellNode = [[TextCellNode alloc] initWithText1:_labels[0] text2:_labels[1]]; | ||
return _cellNode; | ||
}; | ||
} | ||
|
||
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode constrainedSizeForItemAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
CGFloat width = collectionNode.view.bounds.size.width; | ||
return ASSizeRangeMake(CGSizeMake(width, 0.0f), CGSizeMake(width, CGFLOAT_MAX)); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// TabBarController.h | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface TabBarController : ASTabBarController | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// TabBarController.m | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import "TabBarController.h" | ||
|
||
@interface TabBarController () | ||
@end | ||
|
||
@implementation TabBarController | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// TextCellNode.h | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
|
||
@interface TextCellNode : ASCellNode | ||
- (instancetype)initWithText1:(NSString *)text1 text2:(NSString *)text2; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// TextCellNode.m | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import "TextCellNode.h" | ||
#import <AsyncDisplayKit/AsyncDisplayKit.h> | ||
#import <AsyncDisplayKit/ASDisplayNode+Beta.h> | ||
|
||
#ifndef USE_ASTEXTNODE_2 | ||
#define USE_ASTEXTNODE_2 1 | ||
#endif | ||
|
||
@interface TextCellNode() | ||
{ | ||
#if USE_ASTEXTNODE_2 | ||
ASTextNode2 *_label1; | ||
ASTextNode2 *_label2; | ||
#else | ||
ASTextNode *_label1; | ||
ASTextNode *_label2; | ||
#endif | ||
} | ||
@end | ||
|
||
@implementation TextCellNode | ||
|
||
- (instancetype)initWithText1:(NSString *)text1 text2:(NSString *)text2 | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
self.automaticallyManagesSubnodes = YES; | ||
self.clipsToBounds = YES; | ||
#if USE_ASTEXTNODE_2 | ||
_label1 = [[ASTextNode2 alloc] init]; | ||
_label2 = [[ASTextNode2 alloc] init]; | ||
#else | ||
_label1 = [[ASTextNode alloc] init]; | ||
_label2 = [[ASTextNode alloc] init]; | ||
#endif | ||
|
||
_label1.attributedText = [[NSAttributedString alloc] initWithString:text1]; | ||
_label2.attributedText = [[NSAttributedString alloc] initWithString:text2]; | ||
|
||
_label1.maximumNumberOfLines = 1; | ||
_label1.truncationMode = NSLineBreakByTruncatingTail; | ||
_label2.maximumNumberOfLines = 1; | ||
_label2.truncationMode = NSLineBreakByTruncatingTail; | ||
|
||
[self simpleSetupYogaLayout]; | ||
} | ||
return self; | ||
} | ||
|
||
/** | ||
This is to text a row with two labels, the first should be truncated with "...". | ||
Layout is like: [l1Container[_label1], label2]. | ||
This shows a bug of ASTextNode2. | ||
*/ | ||
- (void)simpleSetupYogaLayout | ||
{ | ||
[self.style yogaNodeCreateIfNeeded]; | ||
[_label1.style yogaNodeCreateIfNeeded]; | ||
[_label2.style yogaNodeCreateIfNeeded]; | ||
|
||
_label1.style.flexGrow = 0; | ||
_label1.style.flexShrink = 1; | ||
_label1.backgroundColor = [UIColor lightGrayColor]; | ||
|
||
_label2.style.flexGrow = 0; | ||
_label2.style.flexShrink = 0; | ||
_label2.backgroundColor = [UIColor greenColor]; | ||
|
||
ASDisplayNode *l1Container = [ASDisplayNode yogaVerticalStack]; | ||
|
||
// TODO(fix ASTextNode2): next two line will show the bug of TextNode2 | ||
// which works for ASTextNode though | ||
// see discussion here: https://github.com/TextureGroup/Texture/pull/553 | ||
l1Container.style.alignItems = ASStackLayoutAlignItemsCenter; | ||
_label1.style.alignSelf = ASStackLayoutAlignSelfStart; | ||
|
||
l1Container.style.flexGrow = 0; | ||
l1Container.style.flexShrink = 1; | ||
|
||
l1Container.yogaChildren = @[_label1]; | ||
|
||
self.style.justifyContent = ASStackLayoutJustifyContentSpaceBetween; | ||
self.style.alignItems = ASStackLayoutAlignItemsStart; | ||
self.style.flexDirection = ASStackLayoutDirectionHorizontal; | ||
self.yogaChildren = @[l1Container, _label2]; | ||
} | ||
|
||
@end |