Tweak message cells.

pull/1/head
Matthew Chen 7 years ago
parent d425809fa3
commit 0b04397e21

@ -67,8 +67,20 @@ NS_ASSUME_NONNULL_BEGIN
@"Message shown in conversation view that offers to block an unknown user.") @"Message shown in conversation view that offers to block an unknown user.")
selector:@selector(block)]; selector:@selector(block)];
UIStackView *buttonStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.addToContactsButton,
self.addToProfileWhitelistButton,
self.blockButton,
]];
buttonStackView.axis = UILayoutConstraintAxisVertical;
buttonStackView.spacing = self.vSpacing;
// Ensure all of the buttons have the same width.
buttonStackView.alignment = UIStackViewAlignmentFill;
buttonStackView.layoutMargins = UIEdgeInsetsZero;
self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.titleLabel, self.titleLabel,
buttonStackView,
]]; ]];
self.stackView.axis = UILayoutConstraintAxisVertical; self.stackView.axis = UILayoutConstraintAxisVertical;
self.stackView.spacing = self.vSpacing; self.stackView.spacing = self.vSpacing;
@ -118,37 +130,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert( OWSAssert(
interaction.hasBlockOffer || interaction.hasAddToContactsOffer || interaction.hasAddToProfileWhitelistOffer); interaction.hasBlockOffer || interaction.hasAddToContactsOffer || interaction.hasAddToProfileWhitelistOffer);
CGFloat buttonWidth = 0.f; self.addToContactsButton.hidden = !interaction.hasAddToContactsOffer;
if (interaction.hasAddToContactsOffer) { self.addToProfileWhitelistButton.hidden = !interaction.hasAddToProfileWhitelistOffer;
[self.stackView addArrangedSubview:self.addToContactsButton]; self.blockButton.hidden = !interaction.hasBlockOffer;
buttonWidth = MAX(buttonWidth, [self.addToContactsButton sizeThatFits:CGSizeZero].width);
}
if (interaction.hasAddToProfileWhitelistOffer) {
[self.stackView addArrangedSubview:self.addToProfileWhitelistButton];
buttonWidth = MAX(buttonWidth, [self.addToProfileWhitelistButton sizeThatFits:CGSizeZero].width);
}
if (interaction.hasBlockOffer) {
[self.stackView addArrangedSubview:self.blockButton];
buttonWidth = MAX(buttonWidth, [self.blockButton sizeThatFits:CGSizeZero].width);
}
buttonWidth = (2 * self.buttonHPadding + (CGFloat)ceil(buttonWidth));
CGFloat hMargins = (self.layoutInfo.fullWidthGutterLeading + self.layoutInfo.fullWidthGutterTrailing);
CGFloat maxButtonWidth = self.layoutInfo.viewWidth - hMargins;
buttonWidth = MIN(buttonWidth, maxButtonWidth);
CGFloat buttonHeight = self.buttonHeight;
[NSLayoutConstraint deactivateConstraints:self.layoutConstraints]; [NSLayoutConstraint deactivateConstraints:self.layoutConstraints];
self.layoutConstraints = @[ self.layoutConstraints = @[
[self.addToContactsButton autoSetDimension:ALDimensionWidth toSize:buttonWidth],
[self.addToProfileWhitelistButton autoSetDimension:ALDimensionWidth toSize:buttonWidth],
[self.blockButton autoSetDimension:ALDimensionWidth toSize:buttonWidth],
[self.addToContactsButton autoSetDimension:ALDimensionHeight toSize:buttonHeight],
[self.addToProfileWhitelistButton autoSetDimension:ALDimensionHeight toSize:buttonHeight],
[self.blockButton autoSetDimension:ALDimensionHeight toSize:buttonHeight],
[self.stackView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.topVMargin], [self.stackView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.topVMargin],
[self.stackView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.bottomVMargin], [self.stackView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.bottomVMargin],
// TODO: Honor "full-width gutters"? // TODO: Honor "full-width gutters"?
@ -172,11 +159,6 @@ NS_ASSUME_NONNULL_BEGIN
return 5.f; return 5.f;
} }
- (CGFloat)buttonHPadding
{
return 60.f;
}
- (CGFloat)vSpacing - (CGFloat)vSpacing
{ {
return 5.f; return 5.f;
@ -248,15 +230,6 @@ NS_ASSUME_NONNULL_BEGIN
[self.delegate tappedUnknownContactBlockOfferMessage:self.interaction]; [self.delegate tappedUnknownContactBlockOfferMessage:self.interaction];
} }
- (void)prepareForReuse
{
[super prepareForReuse];
[self.addToContactsButton removeFromSuperview];
[self.addToProfileWhitelistButton removeFromSuperview];
[self.blockButton removeFromSuperview];
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save