Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil backgroundColor in ASTextNode2 #trivial #841

Merged
merged 2 commits into from
Mar 17, 2018
Merged
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
14 changes: 9 additions & 5 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
[self prepareAttributedString:mutableText];

return @{
@"container": copiedContainer,
@"text": mutableText,
@"bgColor": self.backgroundColor
};
@"container": copiedContainer,
@"text": mutableText,
@"bgColor": self.backgroundColor ?: [NSNull null]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adlai-Holler Let me know if we should do more like:

if (self.backgroundColor) {
  return @{
   @"container": copiedContainer,
    @"text": mutableText,
    @"bgColor": self.backgroundColor
  }
}

  return @{
   @"container": copiedContainer,
    @"text": mutableText
  }

And remove the NSNull check in the display method.

};
}

/**
Expand Down Expand Up @@ -467,9 +467,13 @@ + (void)drawRect:(CGRect)bounds withParameters:(NSDictionary *)layoutDict isCanc
}

// Fill background color.
if (bgColor == (id)[NSNull null]) {
bgColor = nil;
}

// They may have already drawn into this context in the pre-context block
// so unfortunately we have to use the normal blend mode, not copy.
if (CGColorGetAlpha(bgColor.CGColor) > 0) {
if (bgColor && CGColorGetAlpha(bgColor.CGColor) > 0) {
[bgColor setFill];
UIRectFillUsingBlendMode(bounds, kCGBlendModeNormal);
}
Expand Down