Measure friend request view height dynamically

pull/14/head
Niels Andriesse
parent f38ddd052e
commit b215cdd9fd

@ -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)
}
}

@ -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);

Loading…
Cancel
Save