-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathUIKitTextInteractionOverlay.swift
More file actions
38 lines (33 loc) · 1.36 KB
/
Copy pathUIKitTextInteractionOverlay.swift
File metadata and controls
38 lines (33 loc) · 1.36 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
37
38
#if TEXTUAL_ENABLE_TEXT_SELECTION && canImport(UIKit)
import SwiftUI
// MARK: - Overview
//
// `UIKitTextInteractionOverlay` bridges the shared `TextSelectionModel` into a `UIView`.
//
// The overlay reads exclusion rectangles for hit-testing. This allows embedded scrollable regions (like
// code blocks) to receive touch events while the parent handles text selection. The view hosts
// a `UITextInteraction` configured for selection and implements the `UITextInput` surface that
// UIKit uses for selection behavior.
struct UIKitTextInteractionOverlay: UIViewRepresentable {
private let model: TextSelectionModel
private let overflowFrames: [CGRect]
init(model: TextSelectionModel, overflowFrames: [CGRect]) {
self.model = model
self.overflowFrames = overflowFrames
}
func makeUIView(context: Context) -> UITextInteractionView {
UITextInteractionView(
model: model,
exclusionRects: overflowFrames,
openURL: context.environment.openURL,
selectionActions: context.environment.textSelectionActions
)
}
func updateUIView(_ uiView: UITextInteractionView, context: Context) {
uiView.model = model
uiView.exclusionRects = overflowFrames
uiView.openURL = context.environment.openURL
uiView.selectionActions = context.environment.textSelectionActions
}
}
#endif