Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class HtmlStyle {
}

private fun withOpacity(color: Int, alpha: Int): Int {
// Do not apply opacity to transparent color
if (Color.alpha(color) == 0) return color
val a = alpha.coerceIn(0, 255)
return (color and 0x00FFFFFF) or (a shl 24)
}
Expand Down
5 changes: 3 additions & 2 deletions ios/styles/InlineCodeStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "FontExtension.h"
#import "OccurenceUtils.h"
#import "ParagraphsUtils.h"
#import "ColorExtension.h"

@implementation InlineCodeStyle {
EnrichedTextInputView *_input;
Expand Down Expand Up @@ -33,7 +34,7 @@ - (void)addAttributes:(NSRange)range {
NSRange currentRange = [value rangeValue];
[_input->textView.textStorage beginEditing];

[_input->textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[[_input->config inlineCodeBgColor] colorWithAlphaComponent:0.4] range:currentRange];
[_input->textView.textStorage addAttribute:NSBackgroundColorAttributeName value:[[_input->config inlineCodeBgColor] colorWithAlphaIfNotTransparent:0.4] range:currentRange];
[_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange];
[_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange];
[_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:[_input->config inlineCodeFgColor] range:currentRange];
Expand All @@ -53,7 +54,7 @@ - (void)addAttributes:(NSRange)range {

- (void)addTypingAttributes {
NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy];
newTypingAttrs[NSBackgroundColorAttributeName] = [[_input->config inlineCodeBgColor] colorWithAlphaComponent:0.4];
newTypingAttrs[NSBackgroundColorAttributeName] = [[_input->config inlineCodeBgColor] colorWithAlphaIfNotTransparent:0.4];
newTypingAttrs[NSForegroundColorAttributeName] = [_input->config inlineCodeFgColor];
newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config inlineCodeFgColor];
newTypingAttrs[NSStrikethroughColorAttributeName] = [_input->config inlineCodeFgColor];
Expand Down
5 changes: 3 additions & 2 deletions ios/styles/MentionStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "TextInsertionUtils.h"
#import "WordsUtils.h"
#import "UIView+React.h"
#import "ColorExtension.h"

// custom NSAttributedStringKey to differentiate from links
static NSString *const MentionAttributeName = @"MentionAttributeName";
Expand Down Expand Up @@ -154,7 +155,7 @@ - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSStr
NSForegroundColorAttributeName: styleProps.color,
NSUnderlineColorAttributeName: styleProps.color,
NSStrikethroughColorAttributeName: styleProps.color,
NSBackgroundColorAttributeName: [styleProps.backgroundColor colorWithAlphaComponent:0.4],
NSBackgroundColorAttributeName: [styleProps.backgroundColor colorWithAlphaIfNotTransparent:0.4],
} mutableCopy];

if(styleProps.decorationLine == DecorationUnderline) {
Expand Down Expand Up @@ -186,7 +187,7 @@ - (void)addMentionAtRange:(NSRange)range params:(MentionParams *)params {
NSForegroundColorAttributeName: styleProps.color,
NSUnderlineColorAttributeName: styleProps.color,
NSStrikethroughColorAttributeName: styleProps.color,
NSBackgroundColorAttributeName: [styleProps.backgroundColor colorWithAlphaComponent:0.4],
NSBackgroundColorAttributeName: [styleProps.backgroundColor colorWithAlphaIfNotTransparent:0.4],
} mutableCopy];

if(styleProps.decorationLine == DecorationUnderline) {
Expand Down
1 change: 1 addition & 0 deletions ios/utils/ColorExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

@interface UIColor (ColorExtension)
- (BOOL)isEqualToColor:(UIColor *)otherColor;
- (UIColor *)colorWithAlphaIfNotTransparent:(CGFloat)newAlpha;
@end
9 changes: 9 additions & 0 deletions ios/utils/ColorExtension.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ - (BOOL)isEqualToColor:(UIColor *)otherColor {

return [selfColor isEqual:otherColor];
}

- (UIColor *)colorWithAlphaIfNotTransparent:(CGFloat)newAlpha {
CGFloat alpha = 0.0;
[self getRed:nil green:nil blue:nil alpha:&alpha];
if (alpha > 0.0) {
return [self colorWithAlphaComponent:newAlpha];
}
return self;
}
@end
Loading