forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextCellNode.m
More file actions
100 lines (83 loc) · 2.75 KB
/
Copy pathTextCellNode.m
File metadata and controls
100 lines (83 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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