fix squashed cells on ios9/10

must specify rowHeight automatic

Furthermore, we can't mix static and automatic sizing within a single tableView
This commit is contained in:
Michael Kirk 2018-07-17 12:24:21 -06:00
parent 573f60ee5a
commit a6a09f4d9f
2 changed files with 44 additions and 51 deletions

View File

@ -231,6 +231,9 @@ const CGFloat kIconViewLength = 24;
{ {
[super viewDidLoad]; [super viewDidLoad];
self.tableView.estimatedRowHeight = 45;
self.tableView.rowHeight = UITableViewAutomaticDimension;
_disappearingMessagesDurationLabel = [UILabel new]; _disappearingMessagesDurationLabel = [UILabel new];
self.disappearingMessagesDurations = [OWSDisappearingMessagesConfiguration validDurationsSeconds]; self.disappearingMessagesDurations = [OWSDisappearingMessagesConfiguration validDurationsSeconds];
@ -372,19 +375,10 @@ const CGFloat kIconViewLength = 24;
cell.contentView.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *topView = [UIView containerView];
[cell.contentView addSubview:topView];
[topView autoPinLeadingAndTrailingToSuperviewMargin];
[topView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[topView autoSetDimension:ALDimensionHeight toSize:kOWSTable_DefaultCellHeight];
NSString *iconName NSString *iconName
= (strongSelf.disappearingMessagesConfiguration.isEnabled ? @"ic_timer" = (strongSelf.disappearingMessagesConfiguration.isEnabled ? @"ic_timer"
: @"ic_timer_disabled"); : @"ic_timer_disabled");
UIImageView *iconView = [strongSelf viewForIconWithName:iconName]; UIImageView *iconView = [strongSelf viewForIconWithName:iconName];
[topView addSubview:iconView];
[iconView autoVCenterInSuperview];
[iconView autoPinLeadingToSuperviewMargin];
UILabel *rowLabel = [UILabel new]; UILabel *rowLabel = [UILabel new];
rowLabel.text = NSLocalizedString( rowLabel.text = NSLocalizedString(
@ -392,19 +386,19 @@ const CGFloat kIconViewLength = 24;
rowLabel.textColor = [UIColor blackColor]; rowLabel.textColor = [UIColor blackColor];
rowLabel.font = [UIFont ows_dynamicTypeBodyFont]; rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[topView addSubview:rowLabel];
[rowLabel autoVCenterInSuperview];
[rowLabel autoPinLeadingToTrailingEdgeOfView:iconView offset:weakSelf.iconSpacing];
UISwitch *switchView = [UISwitch new]; UISwitch *switchView = [UISwitch new];
switchView.on = strongSelf.disappearingMessagesConfiguration.isEnabled; switchView.on = strongSelf.disappearingMessagesConfiguration.isEnabled;
[switchView addTarget:strongSelf [switchView addTarget:strongSelf
action:@selector(disappearingMessagesSwitchValueDidChange:) action:@selector(disappearingMessagesSwitchValueDidChange:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];
[topView addSubview:switchView];
[switchView autoVCenterInSuperview]; UIStackView *topRow =
[switchView autoPinLeadingToTrailingEdgeOfView:rowLabel offset:weakSelf.iconSpacing]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]];
[switchView autoPinTrailingToSuperviewMargin]; topRow.spacing = self.iconSpacing;
topRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:topRow];
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
UILabel *subtitleLabel = [UILabel new]; UILabel *subtitleLabel = [UILabel new];
subtitleLabel.text = NSLocalizedString( subtitleLabel.text = NSLocalizedString(
@ -414,7 +408,7 @@ const CGFloat kIconViewLength = 24;
subtitleLabel.numberOfLines = 0; subtitleLabel.numberOfLines = 0;
subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell.contentView addSubview:subtitleLabel]; [cell.contentView addSubview:subtitleLabel];
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topView]; [subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:8];
[subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel]; [subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel];
[subtitleLabel autoPinTrailingToSuperviewMargin]; [subtitleLabel autoPinTrailingToSuperviewMargin];
[subtitleLabel autoPinBottomToSuperviewMargin]; [subtitleLabel autoPinBottomToSuperviewMargin];
@ -435,25 +429,21 @@ const CGFloat kIconViewLength = 24;
cell.contentView.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *topView = [UIView containerView];
[cell.contentView addSubview:topView];
[topView autoPinLeadingAndTrailingToSuperviewMargin];
[topView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[topView autoSetDimension:ALDimensionHeight toSize:kOWSTable_DefaultCellHeight];
UIImageView *iconView = [strongSelf viewForIconWithName:@"ic_timer"]; UIImageView *iconView = [strongSelf viewForIconWithName:@"ic_timer"];
[topView addSubview:iconView];
[iconView autoVCenterInSuperview];
[iconView autoPinLeadingToSuperviewMargin];
UILabel *rowLabel = strongSelf.disappearingMessagesDurationLabel; UILabel *rowLabel = strongSelf.disappearingMessagesDurationLabel;
[strongSelf updateDisappearingMessagesDurationLabel]; [strongSelf updateDisappearingMessagesDurationLabel];
rowLabel.textColor = [UIColor blackColor]; rowLabel.textColor = [UIColor blackColor];
rowLabel.font = [UIFont ows_dynamicTypeBodyFont]; rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; // don't truncate useful duration info which is in the tail
[topView addSubview:rowLabel]; rowLabel.lineBreakMode = NSLineBreakByTruncatingHead;
[rowLabel autoVCenterInSuperview];
[rowLabel autoPinLeadingToTrailingEdgeOfView:iconView offset:weakSelf.iconSpacing]; UIStackView *topRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
topRow.spacing = self.iconSpacing;
topRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:topRow];
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
UISlider *slider = [UISlider new]; UISlider *slider = [UISlider new];
slider.maximumValue = (float)(strongSelf.disappearingMessagesDurations.count - 1); slider.maximumValue = (float)(strongSelf.disappearingMessagesDurations.count - 1);
@ -464,7 +454,7 @@ const CGFloat kIconViewLength = 24;
action:@selector(durationSliderDidChange:) action:@selector(durationSliderDidChange:)
forControlEvents:UIControlEventValueChanged]; forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:slider]; [cell.contentView addSubview:slider];
[slider autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topView]; [slider autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:6];
[slider autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel]; [slider autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel];
[slider autoPinTrailingToSuperviewMargin]; [slider autoPinTrailingToSuperviewMargin];
[slider autoPinBottomToSuperviewMargin]; [slider autoPinBottomToSuperviewMargin];
@ -531,9 +521,6 @@ const CGFloat kIconViewLength = 24;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_notification_sound"]; UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_notification_sound"];
[cell.contentView addSubview:iconView];
[iconView autoVCenterInSuperview];
[iconView autoPinLeadingToSuperviewMargin];
UILabel *rowLabel = [UILabel new]; UILabel *rowLabel = [UILabel new];
rowLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND", rowLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
@ -541,9 +528,13 @@ const CGFloat kIconViewLength = 24;
rowLabel.textColor = [UIColor blackColor]; rowLabel.textColor = [UIColor blackColor];
rowLabel.font = [UIFont ows_dynamicTypeBodyFont]; rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[cell.contentView addSubview:rowLabel];
[rowLabel autoVCenterInSuperview]; UIStackView *contentRow =
[rowLabel autoPinLeadingToTrailingEdgeOfView:iconView offset:weakSelf.iconSpacing]; [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
contentRow.spacing = self.iconSpacing;
contentRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:contentRow];
[contentRow autoPinEdgesToSuperviewMargins];
OWSSound sound = [OWSSounds notificationSoundForThread:self.thread]; OWSSound sound = [OWSSounds notificationSoundForThread:self.thread];
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound]; cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
@ -568,9 +559,6 @@ const CGFloat kIconViewLength = 24;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_mute_thread"]; UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_mute_thread"];
[cell.contentView addSubview:iconView];
[iconView autoVCenterInSuperview];
[iconView autoPinLeadingToSuperviewMargin];
UILabel *rowLabel = [UILabel new]; UILabel *rowLabel = [UILabel new];
rowLabel.text = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_LABEL", rowLabel.text = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_LABEL",
@ -578,9 +566,6 @@ const CGFloat kIconViewLength = 24;
rowLabel.textColor = [UIColor blackColor]; rowLabel.textColor = [UIColor blackColor];
rowLabel.font = [UIFont ows_dynamicTypeBodyFont]; rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[cell.contentView addSubview:rowLabel];
[rowLabel autoVCenterInSuperview];
[rowLabel autoPinLeadingToTrailingEdgeOfView:iconView offset:weakSelf.iconSpacing];
NSString *muteStatus = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_NOT_MUTED", NSString *muteStatus = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_NOT_MUTED",
@"Indicates that the current thread is not muted."); @"Indicates that the current thread is not muted.");
@ -611,6 +596,13 @@ const CGFloat kIconViewLength = 24;
[dateFormatter stringFromDate:mutedUntilDate]]; [dateFormatter stringFromDate:mutedUntilDate]];
} }
UIStackView *contentRow =
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
contentRow.spacing = self.iconSpacing;
contentRow.alignment = UIStackViewAlignmentCenter;
[cell.contentView addSubview:contentRow];
[contentRow autoPinEdgesToSuperviewMargins];
cell.detailTextLabel.text = muteStatus; cell.detailTextLabel.text = muteStatus;
return cell; return cell;
} }
@ -692,19 +684,17 @@ const CGFloat kIconViewLength = 24;
cell.preservesSuperviewLayoutMargins = YES; cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES;
[cell.contentView addSubview:iconView];
[iconView autoVCenterInSuperview];
[iconView autoPinLeadingToSuperviewMargin];
UILabel *rowLabel = [UILabel new]; UILabel *rowLabel = [UILabel new];
rowLabel.text = name; rowLabel.text = name;
rowLabel.textColor = [UIColor blackColor]; rowLabel.textColor = [UIColor blackColor];
rowLabel.font = [UIFont ows_dynamicTypeBodyFont]; rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail; rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[cell.contentView addSubview:rowLabel];
[rowLabel autoVCenterInSuperview]; UIStackView *contentRow = [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
[rowLabel autoPinLeadingToTrailingEdgeOfView:iconView offset:self.iconSpacing]; contentRow.spacing = self.iconSpacing;
[rowLabel autoPinTrailingToSuperviewMargin];
[cell.contentView addSubview:contentRow];
[contentRow autoPinEdgesToSuperviewMargins];
return cell; return cell;
} }

View File

@ -102,6 +102,9 @@ NS_ASSUME_NONNULL_BEGIN
self.title = _thread.groupModel.groupName; self.title = _thread.groupModel.groupName;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 45;
[self updateTableContents]; [self updateTableContents];
} }