mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
MXKRoomBubbleTableViewCell: Add properties regarding attributed text blank space positioning.
This commit is contained in:
parent
2430a81fc0
commit
2e908c5dae
2 changed files with 40 additions and 6 deletions
|
@ -239,6 +239,16 @@ extern NSString *const kMXKRoomBubbleCellUrlItemInteraction;
|
|||
*/
|
||||
@property (nonatomic) WKWebView *attachmentWebView;
|
||||
|
||||
/**
|
||||
Indicate true if the cell needs vertical space in the text to position UI components.
|
||||
*/
|
||||
@property (nonatomic, readonly) BOOL isTextViewNeedsPositioningVerticalSpace;
|
||||
|
||||
/**
|
||||
Use bubbleData.attributedTextMessage or bubbleData.attributedTextMessageWithoutPositioningSpace according to isTextViewNeedsPositioningVerticalSpace value.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSAttributedString *suitableAttributedTextMessage;
|
||||
|
||||
/**
|
||||
Called during the designated initializer of the UITableViewCell class to set the default
|
||||
properties values.
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#import "MXKMessageTextView.h"
|
||||
#import "UITextView+MatrixKit.h"
|
||||
|
||||
#import "GeneratedInterface-Swift.h"
|
||||
|
||||
#pragma mark - Constant definitions
|
||||
NSString *const kMXKRoomBubbleCellTapOnMessageTextView = @"kMXKRoomBubbleCellTapOnMessageTextView";
|
||||
NSString *const kMXKRoomBubbleCellTapOnSenderNameLabel = @"kMXKRoomBubbleCellTapOnSenderNameLabel";
|
||||
|
@ -122,6 +124,7 @@ static BOOL _disableLongPressGestureOnEvent;
|
|||
_allTextHighlighted = NO;
|
||||
_isAutoAnimatedGif = NO;
|
||||
_tmpSubviews = [NSMutableArray array];
|
||||
_isTextViewNeedsPositioningVerticalSpace = YES;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
|
@ -366,18 +369,23 @@ static BOOL _disableLongPressGestureOnEvent;
|
|||
{
|
||||
if (_allTextHighlighted)
|
||||
{
|
||||
NSMutableAttributedString *highlightedString = [[NSMutableAttributedString alloc] initWithAttributedString:bubbleData.attributedTextMessage];
|
||||
NSMutableAttributedString *highlightedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.suitableAttributedTextMessage];
|
||||
UIColor *color = self.tintColor ? self.tintColor : [UIColor lightGrayColor];
|
||||
[highlightedString addAttribute:NSBackgroundColorAttributeName value:color range:NSMakeRange(0, highlightedString.length)];
|
||||
self.messageTextView.attributedText = highlightedString;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.messageTextView.attributedText = bubbleData.attributedTextMessage;
|
||||
self.messageTextView.attributedText = self.suitableAttributedTextMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSAttributedString *)suitableAttributedTextMessage
|
||||
{
|
||||
return self.isTextViewNeedsPositioningVerticalSpace ? bubbleData.attributedTextMessage : bubbleData.attributedTextMessageWithoutPositioningSpace;
|
||||
}
|
||||
|
||||
- (void)highlightTextMessageForEvent:(NSString*)eventId
|
||||
{
|
||||
if (self.messageTextView)
|
||||
|
@ -389,7 +397,7 @@ static BOOL _disableLongPressGestureOnEvent;
|
|||
else
|
||||
{
|
||||
// Restore original string
|
||||
self.messageTextView.attributedText = bubbleData.attributedTextMessage;
|
||||
self.messageTextView.attributedText = self.suitableAttributedTextMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -559,14 +567,14 @@ static BOOL _disableLongPressGestureOnEvent;
|
|||
// Underline attached file name
|
||||
if (self.isBubbleDataContainsFileAttachment)
|
||||
{
|
||||
NSMutableAttributedString *updatedText = [[NSMutableAttributedString alloc] initWithAttributedString:bubbleData.attributedTextMessage];
|
||||
NSMutableAttributedString *updatedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.suitableAttributedTextMessage];
|
||||
[updatedText addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, updatedText.length)];
|
||||
|
||||
newText = updatedText;
|
||||
}
|
||||
else
|
||||
{
|
||||
newText = bubbleData.attributedTextMessage;
|
||||
newText = self.suitableAttributedTextMessage;
|
||||
}
|
||||
|
||||
// update the text only if it is required
|
||||
|
@ -927,8 +935,24 @@ static BOOL _disableLongPressGestureOnEvent;
|
|||
}
|
||||
else if (cell.messageTextView)
|
||||
{
|
||||
CGFloat maxTextViewWidth;
|
||||
|
||||
RoomTimelineConfiguration *timelineConfiguration = [RoomTimelineConfiguration shared];
|
||||
|
||||
id<RoomCellLayoutUpdating> cellLayoutUpdater = timelineConfiguration.currentStyle.cellLayoutUpdater;
|
||||
|
||||
// Handle updated text view layout if needed
|
||||
if (cellLayoutUpdater)
|
||||
{
|
||||
maxTextViewWidth = [cellLayoutUpdater maximumTextViewWidthFor:cell cellData:cellData maximumCellWidth:maxWidth];
|
||||
}
|
||||
else
|
||||
{
|
||||
maxTextViewWidth = maxWidth - (cell.msgTextViewLeadingConstraint.constant + cell.msgTextViewTrailingConstraint.constant);
|
||||
}
|
||||
|
||||
// Update maximum width available for the textview
|
||||
bubbleData.maxTextViewWidth = maxWidth - (cell.msgTextViewLeadingConstraint.constant + cell.msgTextViewTrailingConstraint.constant);
|
||||
bubbleData.maxTextViewWidth = maxTextViewWidth;
|
||||
|
||||
// Retrieve the suggested height of the message content
|
||||
rowHeight = bubbleData.contentSize.height;
|
||||
|
|
Loading…
Reference in a new issue