Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions ComponentTextKit/CKTextComponentLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,30 @@ - (NSObject *)drawParameters

- (id)willDisplayAsynchronouslyWithDrawParameters:(id<NSObject>)drawParameters
{
return rasterContentsCache()->objectForKey({_renderer.attributes, _renderer.constrainedSize});
NSInteger userInterfaceStyle = 1;
if (@available(iOS 13.0, *)) {
UIView *view = (UIView *)self.delegate;
if ([view isKindOfClass:UIView.class]) {
userInterfaceStyle = (NSInteger)view.traitCollection.userInterfaceStyle;
}
}
return rasterContentsCache()->objectForKey({userInterfaceStyle, _renderer.attributes, _renderer.constrainedSize});
}

- (void)didDisplayAsynchronously:(id)newContents withDrawParameters:(id<NSObject>)drawParameters
{
if (newContents) {
NSInteger userInterfaceStyle = 1;
if (@available(iOS 13.0, *)) {
UIView *view = (UIView *)self.delegate;
if ([view isKindOfClass:UIView.class]) {
userInterfaceStyle = (NSInteger)view.traitCollection.userInterfaceStyle;
}
}

CGImageRef imageRef = (__bridge CGImageRef)newContents;
NSUInteger bytes = CGImageGetBytesPerRow(imageRef) * CGImageGetHeight(imageRef);
rasterContentsCache()->cacheObject({_renderer.attributes, _renderer.constrainedSize}, newContents, bytes);
rasterContentsCache()->cacheObject({userInterfaceStyle, _renderer.attributes, _renderer.constrainedSize}, newContents, bytes);
}
}

Expand Down
11 changes: 11 additions & 0 deletions ComponentTextKit/CKTextComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
[super traitCollectionDidChange:previousTraitCollection];

if (@available(iOS 13.0, *)) {
if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
[self.layer setNeedsDisplay];
}
}
}

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
if (![self.backgroundColor isEqual:backgroundColor]) {
Expand Down
6 changes: 4 additions & 2 deletions ComponentTextKit/TextKit/CKTextKitRendererCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ namespace CK {
*/
struct Key {

NSInteger userInterfaceStyle;
CKTextKitAttributes attributes;
CGSize constrainedSize;

Key(CKTextKitAttributes a, CGSize cs);
Key(NSInteger userInterfaceStyle, CKTextKitAttributes a, CGSize cs);

size_t hash;

Expand All @@ -79,7 +80,8 @@ namespace CK {
// These comparisons are in a specific order to reduce the overall cost of this function.
return hash == other.hash
&& CGSizeEqualToSize(constrainedSize, other.constrainedSize)
&& attributes == other.attributes;
&& attributes == other.attributes
&& userInterfaceStyle == other.userInterfaceStyle;
}
};

Expand Down
5 changes: 3 additions & 2 deletions ComponentTextKit/TextKit/CKTextKitRendererCache.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ void enteredBackgroundNotificationHandler(CFNotificationCenterRef center, void *
}

namespace Renderer {
Key::Key(CKTextKitAttributes a, CGSize cs) : attributes(a), constrainedSize(cs) {
Key::Key(NSInteger u, CKTextKitAttributes a, CGSize cs) : userInterfaceStyle(u), attributes(a), constrainedSize(cs) {
// Precompute hash to avoid paying cost every time getHash is called.
NSUInteger subhashes[] = {
attributes.hash(),
std::hash<CGFloat>()(constrainedSize.width),
std::hash<CGFloat>()(constrainedSize.height)
std::hash<CGFloat>()(constrainedSize.height),
std::hash<NSInteger>()(userInterfaceStyle)
};
hash = RCIntegerArrayHash(subhashes, CK_ARRAY_COUNT(subhashes));
}
Expand Down