forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTextNode2.h
247 lines (198 loc) · 8.82 KB
/
ASTextNode2.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//
// ASTextNode2.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/ASControlNode.h>
#if !ASTEXTNODE_EXPERIMENT_GLOBAL_ENABLE
// Import this to get ASTextNodeHighlightStyle
#import <AsyncDisplayKit/ASTextNode.h>
#else
@protocol ASTextNodeDelegate;
/**
* Highlight styles.
*/
typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
/**
* Highlight style for text on a light background.
*/
ASTextNodeHighlightStyleLight,
/**
* Highlight style for text on a dark background.
*/
ASTextNodeHighlightStyleDark
};
#endif
NS_ASSUME_NONNULL_BEGIN
/**
@abstract Draws interactive rich text.
@discussion Backed by the code in TextExperiment folder, on top of CoreText.
*/
@interface ASTextNode2 : ASControlNode
/**
@abstract The styled text displayed by the node.
@discussion Defaults to nil, no text is shown.
For inline image attachments, add an attribute of key NSAttachmentAttributeName, with a value of an NSTextAttachment.
*/
@property (nullable, nonatomic, copy) NSAttributedString *attributedText;
#pragma mark - Truncation
/**
@abstract The attributedText to use when the text must be truncated.
@discussion Defaults to a localized ellipsis character.
*/
@property (nullable, nonatomic, copy) NSAttributedString *truncationAttributedText;
/**
@summary The second attributed string appended for truncation.
@discussion This string will be highlighted on touches.
@default nil
*/
@property (nullable, nonatomic, copy) NSAttributedString *additionalTruncationMessage;
/**
@abstract Determines how the text is truncated to fit within the receiver's maximum size.
@discussion Defaults to NSLineBreakByWordWrapping.
@note Setting a truncationMode in attributedString will override the truncation mode set here.
*/
@property (nonatomic, assign) NSLineBreakMode truncationMode;
/**
@abstract If the text node is truncated. Text must have been sized first.
*/
@property (nonatomic, readonly, assign, getter=isTruncated) BOOL truncated;
/**
@abstract The maximum number of lines to render of the text before truncation.
@default 0 (No limit)
*/
@property (nonatomic, assign) NSUInteger maximumNumberOfLines;
/**
@abstract The number of lines in the text. Text must have been sized first.
*/
@property (nonatomic, readonly, assign) NSUInteger lineCount;
/**
* An array of path objects representing the regions where text should not be displayed.
*
* @discussion The default value of this property is an empty array. You can
* assign an array of UIBezierPath objects to exclude text from one or more regions in
* the text node's bounds. You can use this property to have text wrap around images,
* shapes or other text like a fancy magazine.
*/
@property (nullable, nonatomic, strong) NSArray<UIBezierPath *> *exclusionPaths;
#pragma mark - Placeholders
/**
* @abstract ASTextNode has a special placeholder behavior when placeholderEnabled is YES.
*
* @discussion Defaults to NO. When YES, it draws rectangles for each line of text,
* following the true shape of the text's wrapping. This visually mirrors the overall
* shape and weight of paragraphs, making the appearance of the finished text less jarring.
*/
@property (nonatomic, assign) BOOL placeholderEnabled;
/**
@abstract The placeholder color.
*/
@property (nullable, nonatomic, strong) UIColor *placeholderColor;
/**
@abstract Inset each line of the placeholder.
*/
@property (nonatomic, assign) UIEdgeInsets placeholderInsets;
#pragma mark - Shadow
/**
@abstract When you set these ASDisplayNode properties, they are composited into the bitmap instead of being applied by CA.
@property (nonatomic, assign) CGColorRef shadowColor;
@property (nonatomic, assign) CGFloat shadowOpacity;
@property (nonatomic, assign) CGSize shadowOffset;
@property (nonatomic, assign) CGFloat shadowRadius;
*/
/**
@abstract The number of pixels used for shadow padding on each side of the receiver.
@discussion Each inset will be less than or equal to zero, so that applying
UIEdgeInsetsRect(boundingRectForText, shadowPadding)
will return a CGRect large enough to fit both the text and the appropriate shadow padding.
*/
@property (nonatomic, readonly, assign) UIEdgeInsets shadowPadding;
#pragma mark - Positioning
/**
@abstract Returns an array of rects bounding the characters in a given text range.
@param textRange A range of text. Must be valid for the receiver's string.
@discussion Use this method to detect all the different rectangles a given range of text occupies.
The rects returned are not guaranteed to be contiguous (for example, if the given text range spans
a line break, the rects returned will be on opposite sides and different lines). The rects returned
are in the coordinate system of the receiver.
*/
- (NSArray<NSValue *> *)rectsForTextRange:(NSRange)textRange AS_WARN_UNUSED_RESULT;
/**
@abstract Returns an array of rects used for highlighting the characters in a given text range.
@param textRange A range of text. Must be valid for the receiver's string.
@discussion Use this method to detect all the different rectangles the highlights of a given range of text occupies.
The rects returned are not guaranteed to be contiguous (for example, if the given text range spans
a line break, the rects returned will be on opposite sides and different lines). The rects returned
are in the coordinate system of the receiver. This method is useful for visual coordination with a
highlighted range of text.
*/
- (NSArray<NSValue *> *)highlightRectsForTextRange:(NSRange)textRange AS_WARN_UNUSED_RESULT;
/**
@abstract Returns a bounding rect for the given text range.
@param textRange A range of text. Must be valid for the receiver's string.
@discussion The height of the frame returned is that of the receiver's line-height; adjustment for
cap-height and descenders is not performed. This method raises an exception if textRange is not
a valid substring range of the receiver's string.
*/
- (CGRect)frameForTextRange:(NSRange)textRange AS_WARN_UNUSED_RESULT;
/**
@abstract Returns the trailing rectangle of space in the receiver, after the final character.
@discussion Use this method to detect which portion of the receiver is not occupied by characters.
The rect returned is in the coordinate system of the receiver.
*/
- (CGRect)trailingRect AS_WARN_UNUSED_RESULT;
#pragma mark - Actions
/**
@abstract The set of attribute names to consider links. Defaults to NSLinkAttributeName.
*/
@property (nonatomic, copy) NSArray<NSString *> *linkAttributeNames;
/**
@abstract Indicates whether the receiver has an entity at a given point.
@param point The point, in the receiver's coordinate system.
@param attributeNameOut The name of the attribute at the point. Can be NULL.
@param rangeOut The ultimate range of the found text. Can be NULL.
@result YES if an entity exists at `point`; NO otherwise.
*/
- (nullable id)linkAttributeValueAtPoint:(CGPoint)point attributeName:(out NSString * _Nullable * _Nullable)attributeNameOut range:(out NSRange * _Nullable)rangeOut AS_WARN_UNUSED_RESULT;
/**
@abstract The style to use when highlighting text.
*/
@property (nonatomic, assign) ASTextNodeHighlightStyle highlightStyle;
/**
@abstract The range of text highlighted by the receiver. Changes to this property are not animated by default.
*/
@property (nonatomic, assign) NSRange highlightRange;
/**
@abstract Set the range of text to highlight, with optional animation.
@param highlightRange The range of text to highlight.
@param animated Whether the text should be highlighted with an animation.
*/
- (void)setHighlightRange:(NSRange)highlightRange animated:(BOOL)animated;
/**
@abstract Responds to actions from links in the text node.
@discussion The delegate must be set before the node is loaded, and implement
textNode:longPressedLinkAttribute:value:atPoint:textRange: in order for
the long press gesture recognizer to be installed.
*/
@property (nonatomic, weak) id<ASTextNodeDelegate> delegate;
/**
@abstract If YES and a long press is recognized, touches are cancelled. Default is NO
*/
@property (nonatomic, assign) BOOL longPressCancelsTouches;
/**
@abstract if YES will not intercept touches for non-link areas of the text. Default is NO.
*/
@property (nonatomic, assign) BOOL passthroughNonlinkTouches;
+ (void)enableDebugging;
@end
@interface ASTextNode2 (Unavailable)
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable;
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock __unavailable;
@end
NS_ASSUME_NONNULL_END