UITextView's text (or attributedText) is erasing right after ViewController was dismissing modally

There are two problems which have an one root. I present ViewController modally and it has UITextView in ScrollView, when I call dismiss it, right after that, the text on UITextView is erasing

This bug affects on following solution, describing here https://stackoverflow.com/questions/50011682/handling-scroll-views-with-custom-interactive-view-controller-presentation-an

And If I uncomment following code, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I unthouch screen, the text will be shown on screen.

class ChildViewController: UIViewController {

    private let descriptionTextView: UITextView = {
        let tv = UITextView()
        tv.font = .systemFont(ofSize: 15)
        tv.isSelectable = true
        tv.textContainer.lineFragmentPadding = .zero
        tv.textContainerInset = .zero
        tv.isEditable = false
        tv.isScrollEnabled = false
        tv.isUserInteractionEnabled = true
        tv.dataDetectorTypes = .link
        tv.bounces = false
        tv.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)

        tv.text = "There are two view controllers: ViewController and TextViewController. Both view controllers are showing a UITextView and a button. I've created a segue called \"textSegue\" when I press the \"Text\" button on the ViewController the text is passed to the TextViewController and displayed. On the TextViewController I can select the text and press the 'Bold' button to make the text bold. When I press the \"Back\" button, the TextViewController is dismissed and the ViewController will show the attributed text. The problem is, when I press the \"Text\" button again and the TextViewController shows, the text in the UITextView doesn't show the attributed text (it is'n bold anymore)."

        tv.translatesAutoresizingMaskIntoConstraints = false
        return tv

    }()

    private lazy var scrollView: UIScrollView = {
        let scrollView = UIScrollView()
        scrollView.bounces = false
        scrollView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)
        return scrollView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)
        view.layer.cornerRadius = 24

        view.addSubview(scrollView)

        scrollView.addSubview(descriptionTextView)
        addDismissButton()

        NSLayoutConstraint.activate([

            scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),

            scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),
            scrollView.rightAnchor.constraint(equalTo: view.rightAnchor),

            descriptionTextView.topAnchor.constraint(equalTo: scrollView.topAnchor),            descriptionTextView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            descriptionTextView.leftAnchor.constraint(equalTo: scrollView.leftAnchor),
            descriptionTextView.rightAnchor.constraint(equalTo: scrollView.rightAnchor),
            descriptionTextView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
        ])
    }

    private func addDismissButton() {
        let button = UIButton(type: .system)
        button.setTitle("Dismiss", for: .normal)
        button.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)
        view.addSubview(button)
        button.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            button.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            button.widthAnchor.constraint(equalToConstant: 200),
            button.heightAnchor.constraint(equalToConstant: 80),
            ])
    }    

    @objc func dismissSelf() {
        self.dismiss(animated: true)
    }
}
class ParentViewController: UIViewController {

    private let transition = PanelTransition()

    @IBAction func openDidPress(_ sender: Any) {
        let child = ChildViewController()

//        child.transitioningDelegate = transition
//        child.modalPresentationStyle = .custom

        child.modalPresentationStyle = .fullScreen
       
        present(child, animated: true)
    }
}

And If I uncomment following code child.transitioningDelegate = transition child.modalPresentationStyle = .custom, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I untouch the screen, the text will be shown on screen. And I could catch this on View Debuger, and text is existing in UITextView, but on screen is not. Is It bug on UITextView?

You dismiss the VC, not the textView, isn't it ?

Yes, I dismiss the VC, which includes the UITextView

Then you empty the TextView and you reload it with the lazy scrollView. Could you try to remove lazy attribute.

just tried to remove lazy attribute, the result is the same

here how it looks like

 the text is erased at the beginning, and after that controller goes away

That just means that iOS first dismisses the subviews and their content before dismissing the controller.

If that's a problem, you could hide the TextView before dismissing the controller.

UITextView's text (or attributedText) is erasing right after ViewController was dismissing modally
 
 
Q