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

MessageLabel cuts off text #1720

Open
Pro2005 opened this issue Jun 3, 2022 · 4 comments
Open

MessageLabel cuts off text #1720

Pro2005 opened this issue Jun 3, 2022 · 4 comments
Labels

Comments

@Pro2005
Copy link

Pro2005 commented Jun 3, 2022

First of all thank you for the great library. I found the issue when MessageLabel cuts off text.
I also prepared you test project where you can easy to reproduce it. In the example I use the same method for calculation label size that we have in MessageSizeCalculator.labelSize

I found that this issue is cased by this line

mutableText.addAttribute(.paragraphStyle, value: style, range: range)

inside MessageLabel.swift file

To Reproduce
Just run test project you will see that the text is cutting off in contrast of regular UILabel

Expected behavior
Whole text should be visible

Screenshots
https://www.screencast.com/t/6ECllmkScpC

Environment

  • What version of MessageKit are you using?
    I use main branch (6.1.0)
  • What version of iOS are you running on?
    iOS 14.7.1, iOS 15.2
  • What version of Swift are you running on?
    xCode 13.2.1, swift 5
  • What device(s) are you testing on? Are these simulators?
    It's possible to reproduce this issue on simulator and real devices
    15.2(any simulator),
    15.2 (iPhone 11)
    14.7.1 (iPhone 6s)
  • Is the issue you're experiencing reproducible in the example app?
    Yes, please use my project https://github.com/Pro2005/MessageKitIssue to understand the problem

Please help me to find correct solution because you know project better.

@Pro2005 Pro2005 added the bug? label Jun 3, 2022
@MuhtasimTanmoy
Copy link
Contributor

From your project you are trying to display this attributedText,

private func makeTestAttributedString() -> NSMutableAttributedString {
        let attributedText = NSMutableAttributedString(
            string: "Test\n\n\t\tItems with testmultiline issueend")
        attributedText.addAttribute(.font, value: UIFont.systemFont(ofSize: 15),
                                    range: .init(location: 0, length: 6))
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.alignment = NSTextAlignment.natural
        paragraphStyle.lineSpacing = 0
        paragraphStyle.paragraphSpacing = 0
        paragraphStyle.headIndent = 30
        paragraphStyle.tailIndent = 0
        paragraphStyle.firstLineHeadIndent = 0
        paragraphStyle.lineBreakMode = .byWordWrapping

        paragraphStyle.tabStops = [.init(textAlignment: .right,
                                         location: 22,
                                         options: [:]),
            .init(textAlignment: .left, location: 30, options: [:])]
        
        attributedText.addAttributes([
            .font: UIFont.systemFont(ofSize: 15),
            .paragraphStyle: paragraphStyle
        ], range: .init(location: 6, length: 3))
        
        attributedText.addAttribute(.font,
                                    value: UIFont.systemFont(ofSize: 15),
                                    range: .init(location: 9, length: 33))
        return attributedText
    }

Remove this line to make it work

   paragraphStyle.tabStops = [.init(textAlignment: .right,
                                         location: 22,
                                         options: [:]),
            .init(textAlignment: .left, location: 30, options: [:])]

Screenshot:

@MikasaAckerman
Copy link

MikasaAckerman commented Mar 5, 2023

@MuhtasimTanmoy
Hello!

I have similar problem, too.
スクリーンショット 2023-03-05 22 55 45

At the first line in incoming message, there should be 你好,有什么可以为您 【效劳的?】, but last 4 words were cutted.(From debug view' text in right side we can see the evidence.)

In the other hand, 3rd paragraph is also cutted.
There should be
'当你在手机或电脑上输入一个表情符号时,它实际上是由一系列Unicode字符组合而成的。这些Unicode字符是一个由国际组织制定的标准,它是一个给每个字符一个唯一代码的系统。

当发送者发送带有表情符号的消息时,这些字符将被传递给接收者的设备。接收者的设备通过解译这些字符,将其转换为相应的图像或图标,从而可以呈现出表情符号。在不同的应用程序和设备上,表情符号的图像样【式可能会有所不同,但它们的含义和基本形状都是相同的。

And I searched all issues but couldn't find answer, so I asked here.
Thank you in advance!

Environment

What version of MessageKit are you using?
main branch
What version of iOS are you running on?
iOS 16.3.1
What version of Swift are you running on?
Xcode 14.2, swift 5
What device(s) are you testing on? Are these simulators?
iPhone 14pro max

@BangGahee
Copy link

BangGahee commented Mar 7, 2023

I have similar problem, too.

image

The text below is the original.

안녕 반갑 반가워 안녕안녕 정말로반가워 ^.^!!! 정말로 정말너무너무너무 반가워 안녕 안녕 안녕 안녕안녕안녕 안 녕안 녕안녕 안녕안녕. 안녕하세요 반가워 안녕 정말로반가워 안녕하세요 정말 너무 정말 너무 !

The last 4 letters are cut off. (ex) 너무 !

I have applied a lot of solutions I know, but they don't work.

Please help me to find correct solution.

Thank you in advance.

Environment

  • What version of MessageKit are you using?
    I use main branch
  • What version of iOS are you running on?
    iOS 15.0
  • What version of Swift are you running on?
    xCode 14.1, swift 5
  • What device(s) are you testing on? Are these simulators?
    15.0 (iPhone 14)

@BangGahee
Copy link

BangGahee commented Mar 8, 2023

The text below is my solution in Korean.

    private func setupView() {
        numberOfLines = 0
        //lineBreakMode = .byWordWrapping //not working
        lineBreakMode = .byCharWrapping // working
    }

But I have to fix library.
Can I get the better solution?

※ The text below is not working..

//            let paragraphStyle = NSMutableParagraphStyle()
//            paragraphStyle.lineBreakStrategy = .hangulWordPriority

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

4 participants