TextEditor Issue with Long Text Input

I'm encountering an issue with the TextEditor in my app when users input long texts. Specifically, when entering a large amount of text with many lines, not all of the text is visible.

For example, after inputting the entire story of Cinderella, adding or deleting text causes the text towards the end to become obscured and not visible.

A sample project illustrating this issue is available on GitHub:
https://github.com/fuziki/TextEditorManyLinesIssue
I have included a video in the project file demonstrating this issue.

Is there a way to resolve this issue?

Platform and Development Environment.
iOS: iOS 17.5.1, Xcode 15.2 (15C500b)

Answered by DTS Engineer in 795429022

Please file a bug report using Feedback Assistant.

Alternatively using a UITextView wrapped in a UIViewRepresentable seems to work as expected. I hope that helps.

struct TextView: UIViewRepresentable {
    @Binding var text: String

    class Coordinator: NSObject, UITextViewDelegate {
        var parent: TextView

        init(_ parent: TextView) {
            self.parent = parent
        }

        func textViewDidChange(_ textView: UITextView) {
            parent.text = textView.text
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    func makeUIView(context: Context) -> UITextView {
        let textView = UITextView()
        textView.delegate = context.coordinator
        textView.isScrollEnabled = true
        return textView
    }

    func updateUIView(_ uiView: UITextView, context: Context) {
        uiView.text = text
    }
}

I had the issue in the past and I just fixed it by adding some 10 trailing spaces in the end. Not sure if anyone has a better fix for this.

Please file a bug report using Feedback Assistant.

Alternatively using a UITextView wrapped in a UIViewRepresentable seems to work as expected. I hope that helps.

struct TextView: UIViewRepresentable {
    @Binding var text: String

    class Coordinator: NSObject, UITextViewDelegate {
        var parent: TextView

        init(_ parent: TextView) {
            self.parent = parent
        }

        func textViewDidChange(_ textView: UITextView) {
            parent.text = textView.text
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    func makeUIView(context: Context) -> UITextView {
        let textView = UITextView()
        textView.delegate = context.coordinator
        textView.isScrollEnabled = true
        return textView
    }

    func updateUIView(_ uiView: UITextView, context: Context) {
        uiView.text = text
    }
}
TextEditor Issue with Long Text Input
 
 
Q