ASTextNode wrong text layout fix

This commit is contained in:
Alexey Glushkov 2015-11-22 11:56:12 +03:00
parent e16d32bb60
commit 42f56defbf
2 changed files with 25 additions and 15 deletions

View File

@ -246,25 +246,13 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
- (void)setFrame:(CGRect)frame - (void)setFrame:(CGRect)frame
{ {
[super setFrame:frame]; [super setFrame:frame];
if (!CGSizeEqualToSize(frame.size, _constrainedSize)) { [self _invalidateRendererIfNeeded:frame.size];
// Our bounds have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
} }
- (void)setBounds:(CGRect)bounds - (void)setBounds:(CGRect)bounds
{ {
[super setBounds:bounds]; [super setBounds:bounds];
if (!CGSizeEqualToSize(bounds.size, _constrainedSize)) { [self _invalidateRendererIfNeeded:bounds.size];
// Our bounds have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
} }
#pragma mark - Renderer Management #pragma mark - Renderer Management
@ -299,6 +287,26 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
_renderer = nil; _renderer = nil;
} }
- (BOOL)_needInvalidateRenderer:(CGSize)newSize
{
return !CGSizeEqualToSize(newSize, _constrainedSize);
}
- (void)_invalidateRendererIfNeeded {
[self _invalidateRendererIfNeeded:self.view.bounds.size];
}
- (void)_invalidateRendererIfNeeded:(CGSize)newSize
{
if ([self _needInvalidateRenderer:newSize]) {
// Our bounds of frame have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
}
#pragma mark - Shadow Drawer Management #pragma mark - Shadow Drawer Management
- (ASTextNodeShadower *)_shadower - (ASTextNodeShadower *)_shadower
{ {
@ -410,6 +418,8 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
- (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
{ {
[self _invalidateRendererIfNeeded];
// Offset the text origin by any shadow padding // Offset the text origin by any shadow padding
UIEdgeInsets shadowPadding = [self shadowPadding]; UIEdgeInsets shadowPadding = [self shadowPadding];
CGPoint textOrigin = CGPointMake(self.bounds.origin.x - shadowPadding.left, self.bounds.origin.y - shadowPadding.top); CGPoint textOrigin = CGPointMake(self.bounds.origin.x - shadowPadding.left, self.bounds.origin.y - shadowPadding.top);

View File

@ -10,4 +10,4 @@ SPEC CHECKSUMS:
FBSnapshotTestCase: 3dc3899168747a0319c5278f5b3445c13a6532dd FBSnapshotTestCase: 3dc3899168747a0319c5278f5b3445c13a6532dd
OCMock: a6a7dc0e3997fb9f35d99f72528698ebf60d64f2 OCMock: a6a7dc0e3997fb9f35d99f72528698ebf60d64f2
COCOAPODS: 0.38.2 COCOAPODS: 0.39.0