Merge pull request #2047 from vector-im/riot_2046

BF: Weird text color when selecting a message
This commit is contained in:
manuroe 2018-09-24 15:32:42 +02:00 committed by GitHub
commit a7cf268b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 12 deletions

View file

@ -10,6 +10,7 @@ Improvements:
Bug fix:
* Fix missing read receipts when lazy-loading room members.
* Weird text color when selecting a message (#2046).
Changes in 0.7.3 (2018-08-27)
===============================================

View file

@ -19,6 +19,7 @@
#import "EventFormatter.h"
#import "AvatarGenerator.h"
#import "Tools.h"
static NSAttributedString *timestampVerticalWhitespace = nil;
static NSAttributedString *readReceiptVerticalWhitespace = nil;
@ -194,12 +195,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
if (selectedComponentIndex != NSNotFound && selectedComponentIndex != index && componentString.length)
{
// Apply alpha to blur this component
NSMutableAttributedString *customComponentString = [[NSMutableAttributedString alloc] initWithAttributedString:componentString];
UIColor *color = [componentString attribute:NSForegroundColorAttributeName atIndex:0 effectiveRange:nil];
color = [color colorWithAlphaComponent:0.2];
[customComponentString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, customComponentString.length)];
componentString = customComponentString;
componentString = [Tools setTextColorAlpha:.2 inAttributedString:componentString];
}
// Check whether the timestamp is displayed for this component, and check whether a vertical whitespace is required
@ -238,12 +234,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
if (selectedComponentIndex != NSNotFound && selectedComponentIndex != index && componentString.length)
{
// Apply alpha to blur this component
NSMutableAttributedString *customComponentString = [[NSMutableAttributedString alloc] initWithAttributedString:componentString];
UIColor *color = [componentString attribute:NSForegroundColorAttributeName atIndex:0 effectiveRange:nil];
color = [color colorWithAlphaComponent:0.2];
[customComponentString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, customComponentString.length)];
componentString = customComponentString;
componentString = [Tools setTextColorAlpha:.2 inAttributedString:componentString];
}
// Check whether the timestamp is displayed

View file

@ -54,4 +54,15 @@
*/
+ (NSURL*)fixURLWithSeveralHashKeys:(NSURL*)url;
#pragma mark - String utilities
/**
Change the alpha value of all text colors of an attibuted string.
@param alpha the alpha value to apply.
@param attributedString the attributed string to update.
@return a new attributed string.
*/
+ (NSAttributedString *)setTextColorAlpha:(CGFloat)alpha inAttributedString:(NSAttributedString*)attributedString;
@end

View file

@ -117,4 +117,29 @@
return fixedURL;
}
#pragma mark - String utilities
+ (NSAttributedString *)setTextColorAlpha:(CGFloat)alpha inAttributedString:(NSAttributedString*)attributedString
{
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString];
// Check all attributes one by one
[string enumerateAttributesInRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop)
{
// Replace only colored texts
if (attrs[NSForegroundColorAttributeName])
{
UIColor *color = attrs[NSForegroundColorAttributeName];
color = [color colorWithAlphaComponent:0.2];
NSMutableDictionary *newAttrs = [NSMutableDictionary dictionaryWithDictionary:attrs];
newAttrs[NSForegroundColorAttributeName] = color;
[string setAttributes:newAttrs range:range];
}
}];
return string;
}
@end