forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuggestionPanelView.swift
More file actions
89 lines (82 loc) · 3.19 KB
/
SuggestionPanelView.swift
File metadata and controls
89 lines (82 loc) · 3.19 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import Foundation
import SwiftUI
@MainActor
final class SuggestionPanelDisplayController: ObservableObject {
@Published var alignTopToAnchor = false
@Published var isPanelOutOfFrame: Bool = false
@Published var isPanelDisplayed: Bool = false
init(
alignTopToAnchor: Bool = false,
isPanelOutOfFrame: Bool = false,
isPanelDisplayed: Bool = false
) {
self.alignTopToAnchor = alignTopToAnchor
self.isPanelDisplayed = isPanelDisplayed
self.isPanelOutOfFrame = isPanelOutOfFrame
}
}
struct SuggestionPanelView: View {
@ObservedObject var viewModel: SharedPanelViewModel
@ObservedObject var displayController: SuggestionPanelDisplayController
@AppStorage(\.suggestionPresentationMode) var suggestionPresentationMode
var body: some View {
VStack(spacing: 0) {
if !displayController.alignTopToAnchor {
Spacer()
.frame(minHeight: 0, maxHeight: .infinity)
.allowsHitTesting(false)
}
VStack {
if let content = viewModel.content {
ZStack(alignment: .topLeading) {
switch content {
case let .suggestion(suggestion):
switch suggestionPresentationMode {
case .nearbyTextCursor:
CodeBlockSuggestionPanel(suggestion: suggestion)
case .floatingWidget:
EmptyView()
}
default:
EmptyView()
}
}
.frame(maxWidth: .infinity, maxHeight: Style.inlineSuggestionMaxHeight)
.fixedSize(horizontal: false, vertical: true)
.allowsHitTesting(
displayController.isPanelDisplayed && !displayController.isPanelOutOfFrame
)
}
}
.frame(maxWidth: .infinity)
if displayController.alignTopToAnchor {
Spacer()
.frame(minHeight: 0, maxHeight: .infinity)
.allowsHitTesting(false)
}
}
.preferredColorScheme(viewModel.colorScheme)
.opacity({
guard displayController.isPanelDisplayed else { return 0 }
guard !displayController.isPanelOutOfFrame else { return 0 }
guard viewModel.content != nil else { return 0 }
return 1
}())
.animation(
featureFlag: \.animationACrashSuggestion,
.easeInOut(duration: 0.2),
value: viewModel.content?.contentHash
)
.animation(
featureFlag: \.animationBCrashSuggestion,
.easeInOut(duration: 0.2),
value: displayController.isPanelDisplayed
)
.animation(
featureFlag: \.animationBCrashSuggestion,
.easeInOut(duration: 0.2),
value: displayController.isPanelOutOfFrame
)
.frame(maxWidth: Style.inlineSuggestionMinWidth, maxHeight: Style.inlineSuggestionMaxHeight)
}
}