diff --git a/Signal/src/Loki/FriendRequestView.swift b/Signal/src/Loki/FriendRequestView.swift index 8e992d212..92ea195b4 100644 --- a/Signal/src/Loki/FriendRequestView.swift +++ b/Signal/src/Loki/FriendRequestView.swift @@ -4,6 +4,9 @@ @objc weak var delegate: FriendRequestViewDelegate? // MARK: Components + private lazy var buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight() + private lazy var buttonHeight = buttonFont.pointSize * 48 / 17 + private lazy var label: UILabel = { let result = UILabel() result.textColor = Theme.secondaryColor @@ -34,8 +37,6 @@ buttonStackView.axis = .horizontal buttonStackView.distribution = .fillEqually mainStackView.addArrangedSubview(buttonStackView) - let buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight() - let buttonHeight = buttonFont.pointSize * 48 / 17 let acceptButton = OWSFlatButton.button(title: NSLocalizedString("Accept", comment: ""), font: buttonFont, titleColor: .ows_materialBlue, backgroundColor: .white, target: self, selector: #selector(accept)) acceptButton.autoSetDimension(.height, toSize: buttonHeight) buttonStackView.addArrangedSubview(acceptButton) @@ -60,4 +61,16 @@ @objc private func decline() { delegate?.declineFriendRequest(message) } + + // MARK: Measuring + @objc static func calculateHeight(message: TSIncomingMessage, conversationStyle: ConversationStyle) -> CGFloat { + let width = conversationStyle.contentWidth + let topSpacing: CGFloat = 12 + let dummyFriendRequestView = FriendRequestView() + dummyFriendRequestView.message = message + let messageHeight = dummyFriendRequestView.label.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)).height + let buttonHeight = dummyFriendRequestView.buttonHeight + let totalHeight = topSpacing + messageHeight + buttonHeight + return totalHeight.rounded(.up) + } } diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 39b221c6f..f873c9321 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -371,7 +371,7 @@ NS_ASSUME_NONNULL_BEGIN } if (self.isIncomingFriendRequest) { - cellSize.height += 98; // TODO: Measure dynamically + cellSize.height += [FriendRequestView calculateHeightWithMessage:(TSIncomingMessage *)self.viewItem.interaction conversationStyle:self.conversationStyle]; } cellSize = CGSizeCeil(cellSize);