iOS 12: Layout is NOT ended on setting attributedText of UITextView

Originator:vmagaziy
Number:rdar://44860856 Date Originated:September 28 2018
Status:Created Resolved:
Product:UIKit Product Version:12.0
Classification:UI Reproducible:Always
 
Summary: Starting from iOS 12 the layout is not performed until the content is scrolled to the end, which does not allow to position attachments properly. 

Notes:  According to documentation of `NSLayoutManager` it's stated that:

... both glyph generation and layout were always performed, in order, from the beginning to the end of the document.

And prior to iOS 12, setting `UITextView.attributedText` caused layout and as a result:

`NSLayoutManagerDelegate.layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutFor textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool)`

was called with `layoutFinishedFlag` set to true. As of iOS 12 it's not the case and this does not allow to update position of attachment glyphs.

Steps to Reproduce:
1) Build and run the TextViewTest sample application a device with iOS 12
2) Press the plus button in the navigation bar (perhaps several times for iPad)

Expected Results:
Text becomes bigger and positions of red and green rectangles is changed accordingly

Actual Results:
Red and green rectangles disappear (see attached screenshots)

Version/Build:
iOS 12.0 (16A366)

Additional information:
- Cannot be reproduced on iOS 10 and 11 as setting `UITextView.attributedText` causes layout (see attached backtrace for iOS 11.4)
- Can be worked around by calling `NSLayoutManager.ensureLayout(for container: NSTextContainer)` on updating `UITextView.attributedText` -- tap `Enable Workaround` in the sample application to check it out
- Cannot be reproduced if the content fits the screen or it's not "sparse" (contains lots of new lines, but continuous strings only)

Attachment can be found following the link: https://goo.gl/myQ7ft

Comments

Closed as a dup of https://openradar.appspot.com/45247730


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!