mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[ASTextNode] Fix edge case where text truncator may not run (manually hosted nodes that are lacking the expected call to -measure).
This fixes the scenario described in https://github.com/facebook/AsyncDisplayKit/issues/1295
This commit is contained in:
@@ -189,9 +189,10 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
|||||||
// We add an assertion so we can track the rare conditions where a graphics context is not present
|
// We add an assertion so we can track the rare conditions where a graphics context is not present
|
||||||
ASDisplayNodeAssertNotNil(context, @"This is no good without a context.");
|
ASDisplayNodeAssertNotNil(context, @"This is no good without a context.");
|
||||||
|
|
||||||
// This renderer may not be the one that did the sizing. If that is the case its _currentScaleFactor will not be set, so we should compute it now
|
// This renderer may not be the one that did the sizing. If that is the case its truncation and currentScaleFactor may not have been evaluated.
|
||||||
if (_sizeIsCalculated == NO && isinf(_constrainedSize.width) == NO && [_attributes.pointSizeScaleFactors count] > 0) {
|
// If there's any possibility we need to truncate or scale (e.g. width is not infinite, perform the size calculation.
|
||||||
_currentScaleFactor = [[self fontSizeAdjuster] scaleFactor];
|
if (_sizeIsCalculated == NO && isinf(_constrainedSize.width) == NO) {
|
||||||
|
[self _calculateSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
CGRect shadowInsetBounds = [[self shadower] insetRectWithConstrainedRect:bounds];
|
CGRect shadowInsetBounds = [[self shadower] insetRectWithConstrainedRect:bounds];
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
10
examples/EditableText/Sample.xcworkspace/contents.xcworkspacedata
generated
Normal file
10
examples/EditableText/Sample.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "group:Sample.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Pods/Pods.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
||||||
@@ -17,6 +17,10 @@
|
|||||||
@interface ViewController () <ASEditableTextNodeDelegate>
|
@interface ViewController () <ASEditableTextNodeDelegate>
|
||||||
{
|
{
|
||||||
ASEditableTextNode *_textNode;
|
ASEditableTextNode *_textNode;
|
||||||
|
|
||||||
|
// These elements are a test case for ASTextNode truncation.
|
||||||
|
UILabel *_label;
|
||||||
|
ASTextNode *_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -44,6 +48,24 @@
|
|||||||
|
|
||||||
// the usual delegate methods are available; see ASEditableTextNodeDelegate
|
// the usual delegate methods are available; see ASEditableTextNodeDelegate
|
||||||
_textNode.delegate = self;
|
_textNode.delegate = self;
|
||||||
|
|
||||||
|
|
||||||
|
// Do any additional setup after loading the view, typically from a nib.
|
||||||
|
NSDictionary *attrs = @{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:12.0f] };
|
||||||
|
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"1\n2\n3\n4\n5" attributes:attrs];
|
||||||
|
|
||||||
|
_label = [[UILabel alloc] init];
|
||||||
|
_label.attributedText = string;
|
||||||
|
_label.backgroundColor = [UIColor lightGrayColor];
|
||||||
|
_label.numberOfLines = 3;
|
||||||
|
_label.frame = CGRectMake(20, 400, 40, 100);
|
||||||
|
|
||||||
|
_node = [[ASTextNode alloc] init];
|
||||||
|
_node.maximumNumberOfLines = 3;
|
||||||
|
_node.backgroundColor = [UIColor lightGrayColor];
|
||||||
|
_node.attributedString = string;
|
||||||
|
_node.frame = CGRectMake(70, 400, 40, 100);
|
||||||
|
// [_node measure:CGSizeMake(40, 50)]; No longer needed now that https://github.com/facebook/AsyncDisplayKit/issues/1295 is fixed.
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -53,6 +75,8 @@
|
|||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
[self.view addSubnode:_textNode];
|
[self.view addSubnode:_textNode];
|
||||||
|
[self.view addSubnode:_node];
|
||||||
|
[self.view addSubview:_label];
|
||||||
|
|
||||||
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]];
|
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user