@@ -225,6 +225,46 @@ extension AttributedLabel {
225225
226226 var urlHandler : URLHandler ?
227227
228+ override init ( frame: CGRect ) {
229+ super. init ( frame: frame)
230+
231+ if #available( iOS 17 . 0 , * ) {
232+ registerForTraitChanges ( [ UITraitPreferredContentSizeCategory . self] ) { (
233+ view: LabelView ,
234+ previousTraitCollection: UITraitCollection
235+ ) in
236+ view. invalidateLinkBoundingShapeCaches ( )
237+ }
238+ } else {
239+ NotificationCenter
240+ . default
241+ . addObserver (
242+ self ,
243+ selector: #selector( sizeCategoryChanged ( notification: ) ) ,
244+ name: UIContentSizeCategory . didChangeNotification,
245+ object: nil
246+ )
247+ }
248+ }
249+
250+ deinit {
251+ if #available( iOS 17 . 0 , * ) {
252+ // Do nothing
253+ } else {
254+ NotificationCenter
255+ . default
256+ . removeObserver ( self )
257+ }
258+ }
259+
260+ @objc private func sizeCategoryChanged( notification: Notification ) {
261+ invalidateLinkBoundingShapeCaches ( )
262+ }
263+
264+ required init ? ( coder: NSCoder ) {
265+ fatalError ( " init(coder:) has not been implemented " )
266+ }
267+
228268 func update( model: AttributedLabel , text: NSAttributedString , environment: Environment , isMeasuring: Bool ) {
229269 let previousAttributedText = isMeasuring ? nil : attributedText
230270
@@ -754,7 +794,7 @@ extension AttributedLabel {
754794 )
755795 }
756796
757- return UIAccessibility . convertToScreenCoordinates ( . init( cgPath: cgPath) , in : container )
797+ return . init( cgPath: cgPath)
758798 } ( )
759799
760800 return . init( firstRect: firstRect, path: path)
@@ -814,7 +854,13 @@ extension AttributedLabel {
814854
815855 override var accessibilityPath : UIBezierPath ? {
816856 set { assertionFailure ( " cannot set accessibilityPath " ) }
817- get { link. boundingShape. path }
857+ get {
858+ if let path = link. boundingShape. path? . copy ( ) as? UIBezierPath , let container = link. container {
859+ return UIAccessibility . convertToScreenCoordinates ( path, in: container)
860+ }
861+
862+ return nil
863+ }
818864 }
819865
820866 override var accessibilityLabel : String ? {
0 commit comments