Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lupacjiri opened this issue Jan 10, 2024 · 0 comments
Labels

Comments

@lupacjiri
Copy link

lupacjiri commented Jan 10, 2024

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.
@lupacjiri lupacjiri added the bug? label Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant