mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 15:52:40 +00:00
RoomBubbleCellData: Add a property to display the timestamp of the selected component on the left when there is enough space.
This commit is contained in:
parent
98c95fb849
commit
b234a09bf1
2 changed files with 22 additions and 4 deletions
|
@ -40,6 +40,11 @@ typedef NS_ENUM(NSInteger, RoomBubbleCellDataTag)
|
||||||
*/
|
*/
|
||||||
@property(nonatomic) BOOL showTimestampForSelectedComponent;
|
@property(nonatomic) BOOL showTimestampForSelectedComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicate true to display the timestamp of the selected component on the left when there is enough space (YES by default).
|
||||||
|
*/
|
||||||
|
@property(nonatomic) BOOL displayTimestampForSelectedComponentOnLeftWhenPossible;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The event id of the current selected event inside the bubble. Default is nil.
|
The event id of the current selected event inside the bubble. Default is nil.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,8 +27,19 @@
|
||||||
static NSAttributedString *timestampVerticalWhitespace = nil;
|
static NSAttributedString *timestampVerticalWhitespace = nil;
|
||||||
static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
|
|
||||||
|
@interface RoomBubbleCellData()
|
||||||
|
|
||||||
|
@property(nonatomic, readonly) BOOL addVerticalWhitespaceForSelectedComponentTimestamp;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation RoomBubbleCellData
|
@implementation RoomBubbleCellData
|
||||||
|
|
||||||
|
- (BOOL)addVerticalWhitespaceForSelectedComponentTimestamp
|
||||||
|
{
|
||||||
|
return self.showTimestampForSelectedComponent && !self.displayTimestampForSelectedComponentOnLeftWhenPossible;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Override MXKRoomBubbleCellData
|
#pragma mark - Override MXKRoomBubbleCellData
|
||||||
|
|
||||||
- (instancetype)initWithEvent:(MXEvent *)event andRoomState:(MXRoomState *)roomState andRoomDataSource:(MXKRoomDataSource *)roomDataSource2
|
- (instancetype)initWithEvent:(MXEvent *)event andRoomState:(MXRoomState *)roomState andRoomDataSource:(MXKRoomDataSource *)roomDataSource2
|
||||||
|
@ -68,6 +79,8 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
|
|
||||||
// Reset attributedTextMessage to force reset MXKRoomCellData parameters
|
// Reset attributedTextMessage to force reset MXKRoomCellData parameters
|
||||||
self.attributedTextMessage = nil;
|
self.attributedTextMessage = nil;
|
||||||
|
|
||||||
|
self.displayTimestampForSelectedComponentOnLeftWhenPossible = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -202,7 +215,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the timestamp is displayed for this component, and check whether a vertical whitespace is required
|
// Check whether the timestamp is displayed for this component, and check whether a vertical whitespace is required
|
||||||
if (((selectedComponentIndex == index && self.showTimestampForSelectedComponent) || lastMessageIndex == index) && (self.shouldHideSenderInformation || self.shouldHideSenderName))
|
if (((selectedComponentIndex == index && self.addVerticalWhitespaceForSelectedComponentTimestamp) || lastMessageIndex == index) && (self.shouldHideSenderInformation || self.shouldHideSenderName))
|
||||||
{
|
{
|
||||||
currentAttributedTextMsg = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
currentAttributedTextMsg = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
||||||
[currentAttributedTextMsg appendAttributedString:componentString];
|
[currentAttributedTextMsg appendAttributedString:componentString];
|
||||||
|
@ -237,7 +250,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the timestamp is displayed
|
// Check whether the timestamp is displayed
|
||||||
if ((selectedComponentIndex == index && self.showTimestampForSelectedComponent) || lastMessageIndex == index)
|
if ((selectedComponentIndex == index && self.addVerticalWhitespaceForSelectedComponentTimestamp) || lastMessageIndex == index)
|
||||||
{
|
{
|
||||||
[currentAttributedTextMsg appendAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
[currentAttributedTextMsg appendAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
||||||
}
|
}
|
||||||
|
@ -290,7 +303,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
NSInteger lastMessageIndex = self.containsLastMessage ? self.mostRecentComponentIndex : NSNotFound;
|
NSInteger lastMessageIndex = self.containsLastMessage ? self.mostRecentComponentIndex : NSNotFound;
|
||||||
|
|
||||||
// Check whether the timestamp is displayed for this first component, and check whether a vertical whitespace is required
|
// Check whether the timestamp is displayed for this first component, and check whether a vertical whitespace is required
|
||||||
if (((selectedComponentIndex == index && self.showTimestampForSelectedComponent) || lastMessageIndex == index) && (self.shouldHideSenderInformation || self.shouldHideSenderName))
|
if (((selectedComponentIndex == index && self.addVerticalWhitespaceForSelectedComponentTimestamp) || lastMessageIndex == index) && (self.shouldHideSenderInformation || self.shouldHideSenderName))
|
||||||
{
|
{
|
||||||
attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
||||||
[attributedString appendAttributedString:component.attributedTextMessage];
|
[attributedString appendAttributedString:component.attributedTextMessage];
|
||||||
|
@ -318,7 +331,7 @@ static NSAttributedString *readReceiptVerticalWhitespace = nil;
|
||||||
{
|
{
|
||||||
// Prepare its attributed string by considering potential vertical margin required to display timestamp.
|
// Prepare its attributed string by considering potential vertical margin required to display timestamp.
|
||||||
NSAttributedString *componentString;
|
NSAttributedString *componentString;
|
||||||
if ((selectedComponentIndex == index && self.showTimestampForSelectedComponent) || lastMessageIndex == index)
|
if ((selectedComponentIndex == index && self.addVerticalWhitespaceForSelectedComponentTimestamp) || lastMessageIndex == index)
|
||||||
{
|
{
|
||||||
NSMutableAttributedString *componentAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
NSMutableAttributedString *componentAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[RoomBubbleCellData timestampVerticalWhitespace]];
|
||||||
[componentAttributedString appendAttributedString:component.attributedTextMessage];
|
[componentAttributedString appendAttributedString:component.attributedTextMessage];
|
||||||
|
|
Loading…
Reference in a new issue