Skip to content

Message cell has wrong height when using NSAttributedString constructed from Markdown  #1825

Description

@lupacjiri

Describe the bug
Message cells using NSAttributedString constructed from Markdown String have height calculated wrong.

To Reproduce
Steps/code to reproduce the behavior in example app:

  1. In SampleData.swift file, replace attributedString(with:) implementation with code below.
let markdownString = "1. **Decide on the fasting method** (16/8, 5:2, etc.)\n2. *Consult with a healthcare provider* if you have health issues\n3. **Plan your meal times** to fit your schedule\n4. *Start with a shorter fasting period* and gradually increase\n5. **Drink plenty of water** to stay hydrated\n6. *Prepare healthy meals* for eating periods\n7. **Listen to your body** and adjust as needed\n8. *Avoid binge eating* after fasting periods\n9. **Stay consistent** with your fasting schedule\n10. *Track your progress* and make changes if necessary"
if #available(iOS 15, *) {
    let markdownFormattingOptions = AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)
    var mutableAttributedString = (try? NSMutableAttributedString(markdown: markdownString, options: markdownFormattingOptions)) ?? NSMutableAttributedString(string: markdownString)
    mutableAttributedString.addAttributes([.font: UIFont.systemFont(ofSize: 13)], range: .init(location: 0, length: mutableAttributedString.string.count))
    return mutableAttributedString
}
return NSAttributedString(string: markdownString)
  1. In SampleData.swift file, replace randomMessage(allowedSenders:) implementation with code below.
let uniqueID = UUID().uuidString
let user = allowedSenders.random()!
let attributedText = attributedString(with: "")
return MockMessage(attributedText: attributedText, user: user, messageId: uniqueID, date: dateAddingRandomTime())
  1. Run the app, select advanced example and see the issue.

Expected behavior
Message cell should be sized correctly without cutting off text.

Screenshots
Text is cut off at the last line

Simulator Screenshot - iPhone 15 Pro - 2024-01-10 at 14 08 57

Environment

  • What version of MessageKit are you using?
    MessageKit 4.2.0
  • What version of iOS are you running on?
    iOS 17.2
  • What version of Swift are you running on?
    Swift 5
  • What device(s) are you testing on? Are these simulators?
    iPhone 15 Pro (simulator)
  • Is the issue you're experiencing reproducible in the example app?
    Yes, see steps to reproduce.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions