Fix 'contact cell vs. message details layout' issue.

pull/1/head
Matthew Chen 7 years ago committed by Michael Kirk
parent 2ecbf1bb65
commit c8d0a80032

@ -27,6 +27,10 @@ extern const CGFloat kContactCellAvatarTextMargin;
- (void)setAttributedSubtitle:(nullable NSAttributedString *)attributedSubtitle; - (void)setAttributedSubtitle:(nullable NSAttributedString *)attributedSubtitle;
- (BOOL)hasAccessoryText;
- (void)ows_setAccessoryView:(UIView *)accessoryView;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -24,8 +24,9 @@ const CGFloat kContactCellAvatarTextMargin = 12;
@property (nonatomic) UILabel *profileNameLabel; @property (nonatomic) UILabel *profileNameLabel;
@property (nonatomic) UIImageView *avatarView; @property (nonatomic) UIImageView *avatarView;
@property (nonatomic) UILabel *subtitleLabel; @property (nonatomic) UILabel *subtitleLabel;
@property (nonatomic) UILabel *ows_accessoryView; @property (nonatomic) UILabel *ows_accessoryLabel;
@property (nonatomic) UIStackView *nameContainerView; @property (nonatomic) UIStackView *nameContainerView;
@property (nonatomic) UIView *ows_accessoryViewContainer;
@property (nonatomic) OWSContactsManager *contactsManager; @property (nonatomic) OWSContactsManager *contactsManager;
@property (nonatomic) NSString *recipientId; @property (nonatomic) NSString *recipientId;
@ -65,9 +66,11 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.subtitleLabel = [UILabel new]; self.subtitleLabel = [UILabel new];
self.subtitleLabel.textColor = [UIColor ows_darkGrayColor]; self.subtitleLabel.textColor = [UIColor ows_darkGrayColor];
self.ows_accessoryView = [[UILabel alloc] init]; self.ows_accessoryLabel = [[UILabel alloc] init];
self.ows_accessoryView.textAlignment = NSTextAlignmentRight; self.ows_accessoryLabel.textAlignment = NSTextAlignmentRight;
self.ows_accessoryView.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; self.ows_accessoryLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
self.ows_accessoryViewContainer = [UIView containerView];
self.nameContainerView = [[UIStackView alloc] initWithArrangedSubviews:@[ self.nameContainerView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.nameLabel, self.nameLabel,
@ -77,10 +80,14 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.nameContainerView.axis = UILayoutConstraintAxisVertical; self.nameContainerView.axis = UILayoutConstraintAxisVertical;
self.nameContainerView.alignment = UIStackViewAlignmentFill; self.nameContainerView.alignment = UIStackViewAlignmentFill;
[self.avatarView setContentHuggingHorizontalHigh];
[self.nameContainerView setContentHuggingHorizontalLow];
[self.ows_accessoryViewContainer setContentHuggingHorizontalHigh];
UIStackView *hStackView = [[UIStackView alloc] initWithArrangedSubviews:@[ UIStackView *hStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.avatarView, self.avatarView,
self.nameContainerView, self.nameContainerView,
self.ows_accessoryView, self.ows_accessoryViewContainer,
]]; ]];
hStackView.axis = UILayoutConstraintAxisHorizontal; hStackView.axis = UILayoutConstraintAxisHorizontal;
hStackView.spacing = kContactCellAvatarTextMargin; hStackView.spacing = kContactCellAvatarTextMargin;
@ -101,7 +108,7 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.nameLabel.font = [UIFont ows_dynamicTypeBodyFont]; self.nameLabel.font = [UIFont ows_dynamicTypeBodyFont];
self.profileNameLabel.font = [UIFont ows_regularFontWithSize:11.f]; self.profileNameLabel.font = [UIFont ows_regularFontWithSize:11.f];
self.subtitleLabel.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 - (void)configureWithSignalAccount:(SignalAccount *)signalAccount contactsManager:(OWSContactsManager *)contactsManager
@ -131,7 +138,8 @@ const CGFloat kContactCellAvatarTextMargin = 12;
[self updateAvatar]; [self updateAvatar];
if (self.accessoryMessage) { 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. // 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]; [OWSAvatarBuilder buildImageForThread:thread diameter:kContactCellAvatarSize contactsManager:contactsManager];
if (self.accessoryMessage) { 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. // 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.nameLabel.text = nil;
self.subtitleLabel.text = nil; self.subtitleLabel.text = nil;
self.profileNameLabel.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 - (void)otherUsersProfileDidChange:(NSNotification *)notification
@ -272,6 +284,26 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.subtitleLabel.attributedText = attributedSubtitle; 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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -28,6 +28,10 @@ NS_ASSUME_NONNULL_BEGIN
- (NSAttributedString *)verifiedSubtitle; - (NSAttributedString *)verifiedSubtitle;
- (BOOL)hasAccessoryText;
- (void)ows_setAccessoryView:(UIView *)accessoryView;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -97,6 +97,16 @@ NS_ASSUME_NONNULL_BEGIN
self.accessoryType = UITableViewCellAccessoryNone; self.accessoryType = UITableViewCellAccessoryNone;
} }
- (BOOL)hasAccessoryText
{
return [self.cellView hasAccessoryText];
}
- (void)ows_setAccessoryView:(UIView *)accessoryView
{
return [self.cellView ows_setAccessoryView:accessoryView];
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -208,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN
[cell configureWithThread:thread contactsManager:helper.contactsManager]; [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. // Don't add a disappearing messages indicator if we've already added a "blocked" label.
__block OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; __block OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
[self.uiDatabaseConnection [self.uiDatabaseConnection
@ -227,7 +227,7 @@ NS_ASSUME_NONNULL_BEGIN
disappearingTimerConfigurationView.tintColor = disappearingTimerConfigurationView.tintColor =
[UIColor colorWithWhite:0.5f alpha:1.f]; [UIColor colorWithWhite:0.5f alpha:1.f];
cell.accessoryView = disappearingTimerConfigurationView; [cell ows_setAccessoryView:disappearingTimerConfigurationView];
} }
} }

Loading…
Cancel
Save