Add contentWidth property to ConversationViewCell.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent d7f24e4808
commit e77292c2a9

@ -54,9 +54,15 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) ConversationViewItem *viewItem; @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; @property (nonatomic) BOOL isCellVisible;
- (void)loadForDisplay:(int)contentWidth; @property (nonatomic) int contentWidth;
- (void)loadForDisplay;
- (CGSize)cellSizeForViewWidth:(int)viewWidth contentWidth:(int)contentWidth; - (CGSize)cellSizeForViewWidth:(int)viewWidth contentWidth:(int)contentWidth;

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

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

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

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

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

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

Loading…
Cancel
Save