From 3dc0ed255c4fe5e4f1479e3763b4b8b2ad441ec9 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Mon, 2 Sep 2024 11:35:03 +1000 Subject: [PATCH] fix text got cut off unexpectedly in modals --- .../ConversationVC+Interaction.swift | 3 +- .../Components/ConfirmationModal.swift | 33 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 29a06b624..627fd5f3c 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1190,7 +1190,8 @@ extension ConversationVC: body: .attributedText( "urlOpenDescription" .put(key: "url", value: url.absoluteString) - .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) + .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)), + canScroll: true ), confirmTitle: "open".localized(), confirmStyle: .danger, diff --git a/SessionUIKit/Components/ConfirmationModal.swift b/SessionUIKit/Components/ConfirmationModal.swift index 0a12a5ea4..e25477a56 100644 --- a/SessionUIKit/Components/ConfirmationModal.swift +++ b/SessionUIKit/Components/ConfirmationModal.swift @@ -203,12 +203,12 @@ public class ConfirmationModal: Modal, UITextFieldDelegate { closeButton.pin(.right, to: .right, of: contentView, withInset: -8) } - private func layoutExplanationLabel(showScroll: Bool = true) { + private func layoutExplanationLabel(_ canScroll: Bool = true) { let labelWidth = view.frame.width - 4 * Values.veryLargeSpacing let maxLabelSize = CGSize(width: labelWidth, height: CGFloat.greatestFiniteMagnitude) let expectedLabelSize = explanationLabel.sizeThatFits(maxLabelSize) let lineHeight = explanationLabel.font.lineHeight - if showScroll { + if canScroll { explanationLabelContainerHeightConstraint.constant = min(expectedLabelSize.height, lineHeight * 5) } else { explanationLabelContainerHeightConstraint.constant = expectedLabelSize.height @@ -242,22 +242,23 @@ public class ConfirmationModal: Modal, UITextFieldDelegate { case .none: mainStackView.spacing = Values.smallSpacing - case .text(let text): + case .text(let text, let canScroll): mainStackView.spacing = Values.smallSpacing explanationLabel.text = text explanationLabelContainer.isHidden = false - self.layoutExplanationLabel() + self.layoutExplanationLabel(canScroll) - case .attributedText(let attributedText): + case .attributedText(let attributedText, let canScroll): mainStackView.spacing = Values.smallSpacing explanationLabel.attributedText = attributedText explanationLabelContainer.isHidden = false - self.layoutExplanationLabel() + self.layoutExplanationLabel(canScroll) case .input(let explanation, let placeholder, let value, let clearButton, let onTextChanged): explanationLabel.attributedText = explanation explanationLabelContainer.isHidden = (explanation == nil) - self.layoutExplanationLabel(showScroll: false) + let canScroll: Bool = false + self.layoutExplanationLabel(canScroll) textField.placeholder = placeholder textField.text = (value ?? "") textField.clearButtonMode = (clearButton ? .always : .never) @@ -515,8 +516,14 @@ public extension ConfirmationModal.Info { } case none - case text(String) - case attributedText(NSAttributedString) + case text( + _ text: String, + canScroll: Bool = false + ) + case attributedText( + _ attributedText: NSAttributedString, + canScroll: Bool = false + ) case input( explanation: NSAttributedString?, placeholder: String, @@ -538,8 +545,8 @@ public extension ConfirmationModal.Info { public static func == (lhs: ConfirmationModal.Info.Body, rhs: ConfirmationModal.Info.Body) -> Bool { switch (lhs, rhs) { case (.none, .none): return true - case (.text(let lhsText), .text(let rhsText)): return (lhsText == rhsText) - case (.attributedText(let lhsText), .attributedText(let rhsText)): return (lhsText == rhsText) + case (.text(let lhsText, _), .text(let rhsText, _)): return (lhsText == rhsText) + case (.attributedText(let lhsText, _), .attributedText(let rhsText, _)): return (lhsText == rhsText) case (.input(let lhsExplanation, let lhsPlaceholder, let lhsInitialValue, let lhsClearButton, _), .input(let rhsExplanation, let rhsPlaceholder, let rhsInitialValue, let rhsClearButton, _)): return ( @@ -572,8 +579,8 @@ public extension ConfirmationModal.Info { public func hash(into hasher: inout Hasher) { switch self { case .none: break - case .text(let text): text.hash(into: &hasher) - case .attributedText(let text): text.hash(into: &hasher) + case .text(let text, _): text.hash(into: &hasher) + case .attributedText(let text, _): text.hash(into: &hasher) case .input(let explanation, let placeholder, let initialValue, let clearButton, _): explanation.hash(into: &hasher)