-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathAttachmentAttribute.swift
More file actions
36 lines (31 loc) · 1.37 KB
/
Copy pathAttachmentAttribute.swift
File metadata and controls
36 lines (31 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import SwiftUI
// MARK: - Overview
//
// Attachments are stored in attributed content as a `Textual.Attachment` attribute, but SwiftUI
// `Text` can’t embed arbitrary views. The rendering pipeline converts these runs into placeholder
// `Text` segments and uses an overlay to draw the real views at the resolved layout positions.
//
// `AttachmentAttribute` is attached to the placeholder runs during `Text` construction. It carries:
// - the original attachment value (type-erased as `AnyAttachment`)
// - the run's `PresentationIntent` (used by formatters and higher-level rendering)
//
// `Text.Layout.Run` exposes lightweight accessors so overlay code can discover attachments without
// reaching back into the original attributed string.
@available(iOS 18, macOS 15, tvOS 18, watchOS 11, visionOS 2, *)
struct AttachmentAttribute: TextAttribute {
var attachment: AnyAttachment
var presentationIntent: PresentationIntent?
init(_ attachment: AnyAttachment, presentationIntent: PresentationIntent?) {
self.attachment = attachment
self.presentationIntent = presentationIntent
}
}
@available(iOS 18, macOS 15, tvOS 18, watchOS 11, visionOS 2, *)
extension Text.Layout.Run {
var attachment: AnyAttachment? {
self[AttachmentAttribute.self]?.attachment
}
var attachmentPresentationIntent: PresentationIntent? {
self[AttachmentAttribute.self]?.presentationIntent
}
}