Add contentWidth property to ConversationViewCell.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-10-16 08:41:46 -04:00
parent d7f24e4808
commit e77292c2a9
7 changed files with 20 additions and 10 deletions

View File

@ -54,9 +54,15 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) ConversationViewItem *viewItem;
// Cells are prefetched but expensive cells (e.g. media) should only load
// when visible and unload when no longer visible. Non-visible cells can
// cache their contents on their ConversationViewItem, but that cache may
// be evacuated before the cell becomes visible again.
@property (nonatomic) BOOL isCellVisible;
- (void)loadForDisplay:(int)contentWidth;
@property (nonatomic) int contentWidth;
- (void)loadForDisplay;
- (CGSize)cellSizeForViewWidth:(int)viewWidth contentWidth:(int)contentWidth;

View File

@ -16,9 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
self.viewItem = nil;
self.delegate = nil;
self.isCellVisible = NO;
self.contentWidth = 0;
}
- (void)loadForDisplay:(int)contentWidth
- (void)loadForDisplay
{
OWSFail(@"%@ This method should be overridden.", self.logTag);
}

View File

@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay:(int)contentWidth
- (void)loadForDisplay
{
OWSAssert(self.viewItem);
OWSAssert([self.viewItem.interaction isKindOfClass:[OWSContactOffersInteraction class]]);

View File

@ -207,7 +207,7 @@ NS_ASSUME_NONNULL_BEGIN
return (TSMessage *)self.viewItem.interaction;
}
- (void)loadForDisplay:(int)contentWidth
- (void)loadForDisplay
{
OWSAssert(self.viewItem);
OWSAssert(self.viewItem.interaction);
@ -220,7 +220,7 @@ NS_ASSUME_NONNULL_BEGIN
= isIncoming ? [self.bubbleFactory incoming] : [self.bubbleFactory outgoing];
self.bubbleImageView.image = bubbleImageData.messageBubbleImage;
[self updateDateHeader:contentWidth];
[self updateDateHeader];
[self updateFooter];
switch (self.cellType) {
@ -263,8 +263,10 @@ NS_ASSUME_NONNULL_BEGIN
// });
}
- (void)updateDateHeader:(int)contentWidth
- (void)updateDateHeader
{
OWSAssert(self.contentWidth > 0);
static NSDateFormatter *dateHeaderDateFormatter = nil;
static NSDateFormatter *dateHeaderTimeFormatter = nil;
static dispatch_once_t onceToken;
@ -312,7 +314,7 @@ NS_ASSUME_NONNULL_BEGIN
self.dateHeaderConstraints = @[
// Date headers should be visually centered within the conversation view,
// so they need to extend outside the cell's boundaries.
[self.dateHeaderLabel autoSetDimension:ALDimensionWidth toSize:contentWidth],
[self.dateHeaderLabel autoSetDimension:ALDimensionWidth toSize:self.contentWidth],
(self.isIncoming ? [self.dateHeaderLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading]
: [self.dateHeaderLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing]),
[self.dateHeaderLabel autoPinEdgeToSuperviewEdge:ALEdgeTop],

View File

@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay:(int)contentWidth
- (void)loadForDisplay
{
OWSAssert(self.viewItem);

View File

@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay:(int)contentWidth
- (void)loadForDisplay
{
OWSAssert(self.viewItem);
OWSAssert([self.viewItem.interaction isKindOfClass:[TSUnreadIndicatorInteraction class]]);

View File

@ -4025,8 +4025,9 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
}
cell.viewItem = viewItem;
cell.delegate = self;
cell.contentWidth = self.layout.contentWidth;
[cell loadForDisplay:self.layout.contentWidth];
[cell loadForDisplay];
return cell;
}