diff --git a/SignalMessaging/Views/ContactCellView.h b/SignalMessaging/Views/ContactCellView.h index 8e9d95a19..8d639cf58 100644 --- a/SignalMessaging/Views/ContactCellView.h +++ b/SignalMessaging/Views/ContactCellView.h @@ -27,6 +27,10 @@ extern const CGFloat kContactCellAvatarTextMargin; - (void)setAttributedSubtitle:(nullable NSAttributedString *)attributedSubtitle; +- (BOOL)hasAccessoryText; + +- (void)ows_setAccessoryView:(UIView *)accessoryView; + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/Views/ContactCellView.m b/SignalMessaging/Views/ContactCellView.m index fd88dbff7..6479ec386 100644 --- a/SignalMessaging/Views/ContactCellView.m +++ b/SignalMessaging/Views/ContactCellView.m @@ -24,8 +24,9 @@ const CGFloat kContactCellAvatarTextMargin = 12; @property (nonatomic) UILabel *profileNameLabel; @property (nonatomic) UIImageView *avatarView; @property (nonatomic) UILabel *subtitleLabel; -@property (nonatomic) UILabel *ows_accessoryView; +@property (nonatomic) UILabel *ows_accessoryLabel; @property (nonatomic) UIStackView *nameContainerView; +@property (nonatomic) UIView *ows_accessoryViewContainer; @property (nonatomic) OWSContactsManager *contactsManager; @property (nonatomic) NSString *recipientId; @@ -65,9 +66,11 @@ const CGFloat kContactCellAvatarTextMargin = 12; self.subtitleLabel = [UILabel new]; self.subtitleLabel.textColor = [UIColor ows_darkGrayColor]; - self.ows_accessoryView = [[UILabel alloc] init]; - self.ows_accessoryView.textAlignment = NSTextAlignmentRight; - self.ows_accessoryView.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + self.ows_accessoryLabel = [[UILabel alloc] init]; + self.ows_accessoryLabel.textAlignment = NSTextAlignmentRight; + self.ows_accessoryLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + + self.ows_accessoryViewContainer = [UIView containerView]; self.nameContainerView = [[UIStackView alloc] initWithArrangedSubviews:@[ self.nameLabel, @@ -77,10 +80,14 @@ const CGFloat kContactCellAvatarTextMargin = 12; self.nameContainerView.axis = UILayoutConstraintAxisVertical; self.nameContainerView.alignment = UIStackViewAlignmentFill; + [self.avatarView setContentHuggingHorizontalHigh]; + [self.nameContainerView setContentHuggingHorizontalLow]; + [self.ows_accessoryViewContainer setContentHuggingHorizontalHigh]; + UIStackView *hStackView = [[UIStackView alloc] initWithArrangedSubviews:@[ self.avatarView, self.nameContainerView, - self.ows_accessoryView, + self.ows_accessoryViewContainer, ]]; hStackView.axis = UILayoutConstraintAxisHorizontal; hStackView.spacing = kContactCellAvatarTextMargin; @@ -101,7 +108,7 @@ const CGFloat kContactCellAvatarTextMargin = 12; self.nameLabel.font = [UIFont ows_dynamicTypeBodyFont]; self.profileNameLabel.font = [UIFont ows_regularFontWithSize:11.f]; self.subtitleLabel.font = [UIFont ows_regularFontWithSize:11.f]; - self.ows_accessoryView.font = [UIFont ows_mediumFontWithSize:13.f]; + self.ows_accessoryLabel.font = [UIFont ows_mediumFontWithSize:13.f]; } - (void)configureWithSignalAccount:(SignalAccount *)signalAccount contactsManager:(OWSContactsManager *)contactsManager @@ -131,7 +138,8 @@ const CGFloat kContactCellAvatarTextMargin = 12; [self updateAvatar]; if (self.accessoryMessage) { - self.ows_accessoryView.text = self.accessoryMessage; + self.ows_accessoryLabel.text = self.accessoryMessage; + [self ows_setAccessoryView:self.ows_accessoryLabel]; } // Force layout, since imageView isn't being initally rendered on App Store optimized build. @@ -172,7 +180,8 @@ const CGFloat kContactCellAvatarTextMargin = 12; [OWSAvatarBuilder buildImageForThread:thread diameter:kContactCellAvatarSize contactsManager:contactsManager]; if (self.accessoryMessage) { - self.ows_accessoryView.text = self.accessoryMessage; + self.ows_accessoryLabel.text = self.accessoryMessage; + [self ows_setAccessoryView:self.ows_accessoryLabel]; } // Force layout, since imageView isn't being initally rendered on App Store optimized build. @@ -235,7 +244,10 @@ const CGFloat kContactCellAvatarTextMargin = 12; self.nameLabel.text = nil; self.subtitleLabel.text = nil; self.profileNameLabel.text = nil; - self.ows_accessoryView.text = nil; + self.ows_accessoryLabel.text = nil; + for (UIView *subview in self.ows_accessoryViewContainer.subviews) { + [subview removeFromSuperview]; + } } - (void)otherUsersProfileDidChange:(NSNotification *)notification @@ -272,6 +284,26 @@ const CGFloat kContactCellAvatarTextMargin = 12; self.subtitleLabel.attributedText = attributedSubtitle; } +- (BOOL)hasAccessoryText +{ + return self.accessoryMessage.length > 0; +} + +- (void)ows_setAccessoryView:(UIView *)accessoryView +{ + OWSAssert(accessoryView); + OWSAssert(self.ows_accessoryViewContainer); + OWSAssert(self.ows_accessoryViewContainer.subviews.count < 1); + + [self.ows_accessoryViewContainer addSubview:accessoryView]; + + // Trailing-align the accessory view. + [accessoryView autoPinEdgeToSuperviewMargin:ALEdgeTop]; + [accessoryView autoPinEdgeToSuperviewMargin:ALEdgeBottom]; + [accessoryView autoPinEdgeToSuperviewMargin:ALEdgeTrailing]; + [accessoryView autoPinEdgeToSuperviewMargin:ALEdgeLeading relation:NSLayoutRelationGreaterThanOrEqual]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/Views/ContactTableViewCell.h b/SignalMessaging/Views/ContactTableViewCell.h index b51d18cfd..0554b6521 100644 --- a/SignalMessaging/Views/ContactTableViewCell.h +++ b/SignalMessaging/Views/ContactTableViewCell.h @@ -28,6 +28,10 @@ NS_ASSUME_NONNULL_BEGIN - (NSAttributedString *)verifiedSubtitle; +- (BOOL)hasAccessoryText; + +- (void)ows_setAccessoryView:(UIView *)accessoryView; + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/Views/ContactTableViewCell.m b/SignalMessaging/Views/ContactTableViewCell.m index 15c3e7022..9eba9c7a7 100644 --- a/SignalMessaging/Views/ContactTableViewCell.m +++ b/SignalMessaging/Views/ContactTableViewCell.m @@ -97,6 +97,16 @@ NS_ASSUME_NONNULL_BEGIN self.accessoryType = UITableViewCellAccessoryNone; } +- (BOOL)hasAccessoryText +{ + return [self.cellView hasAccessoryText]; +} + +- (void)ows_setAccessoryView:(UIView *)accessoryView +{ + return [self.cellView ows_setAccessoryView:accessoryView]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/contacts/SelectThreadViewController.m b/SignalMessaging/contacts/SelectThreadViewController.m index be7b92642..29f89bb59 100644 --- a/SignalMessaging/contacts/SelectThreadViewController.m +++ b/SignalMessaging/contacts/SelectThreadViewController.m @@ -208,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN [cell configureWithThread:thread contactsManager:helper.contactsManager]; - if (cell.accessoryView == nil) { + if (!cell.hasAccessoryText) { // Don't add a disappearing messages indicator if we've already added a "blocked" label. __block OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; [self.uiDatabaseConnection @@ -227,7 +227,7 @@ NS_ASSUME_NONNULL_BEGIN disappearingTimerConfigurationView.tintColor = [UIColor colorWithWhite:0.5f alpha:1.f]; - cell.accessoryView = disappearingTimerConfigurationView; + [cell ows_setAccessoryView:disappearingTimerConfigurationView]; } }