Remove rendered RCTText contents when moving offscreen

Summary:
When an `RCTText` instance moves offscreen (possibly due to parent clipping), we unset the layer's contents until it comes onscreen again.
This commit is contained in:
Alex Akers 2015-08-03 05:55:48 -07:00
parent e9f69bc2e4
commit 3e21f39a77
1 changed files with 29 additions and 10 deletions

View File

@ -84,17 +84,20 @@
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:textFrame.origin]; [layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:textFrame.origin];
__block UIBezierPath *highlightPath = nil; __block UIBezierPath *highlightPath = nil;
[layoutManager.textStorage enumerateAttributesInRange:glyphRange options:0 usingBlock:^(NSDictionary *attrs, NSRange range, __unused BOOL *stop){ NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
if ([attrs[RCTIsHighlightedAttributeName] boolValue]) { [layoutManager.textStorage enumerateAttribute:RCTIsHighlightedAttributeName inRange:characterRange options:0 usingBlock:^(NSNumber *value, NSRange range, BOOL *_) {
[layoutManager enumerateEnclosingRectsForGlyphRange:range withinSelectedGlyphRange:range inTextContainer:textContainer usingBlock:^(CGRect r, __unused BOOL *s){ if (!value.boolValue) {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(r, -2, -2) cornerRadius:2]; return;
if (highlightPath) {
[highlightPath appendPath:path];
} else {
highlightPath = path;
}
}];
} }
[layoutManager enumerateEnclosingRectsForGlyphRange:range withinSelectedGlyphRange:range inTextContainer:textContainer usingBlock:^(CGRect enclosingRect, __unused BOOL *__) {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(enclosingRect, -2, -2) cornerRadius:2];
if (highlightPath) {
[highlightPath appendPath:path];
} else {
highlightPath = path;
}
}];
}]; }];
if (highlightPath) { if (highlightPath) {
@ -130,6 +133,22 @@
return reactTag; return reactTag;
} }
- (void)didMoveToWindow
{
[super didMoveToWindow];
if (!self.window) {
self.layer.contents = nil;
if (_highlightLayer) {
[_highlightLayer removeFromSuperlayer];
_highlightLayer = nil;
}
} else if (_textStorage.length) {
[self setNeedsDisplay];
}
}
#pragma mark - Accessibility #pragma mark - Accessibility
- (NSString *)accessibilityLabel - (NSString *)accessibilityLabel