forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatDraftScope.swift
More file actions
26 lines (24 loc) · 1.01 KB
/
Copy pathChatDraftScope.swift
File metadata and controls
26 lines (24 loc) · 1.01 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
import SwiftUI
/// Subscribes to the composer draft on behalf of exactly the subtree that has
/// to redraw while the reader types, and hands that subtree a binding.
///
/// The composer text is not published on `ChatProvider` (see
/// `ChatComposerDraft`), so a page observing the provider is no longer woken by
/// typing. Any view whose appearance genuinely depends on the live text — the
/// input field itself, and Home's ask bar whose width tracks the typed string —
/// wraps itself in this scope instead, which keeps the per-keystroke
/// invalidation inside the composer.
struct ChatDraftScope<Content: View>: View {
@ObservedObject var draft: ChatComposerDraft
@ViewBuilder var content: (Binding<String>) -> Content
var body: some View {
content(
Binding(
get: { draft.text },
// Route writes through `setText` so a reader edit still advances the
// revision and schedules persistence exactly as a provider write does.
set: { draft.setText($0) }
)
)
}
}