Skip to content

Commit b9966db

Browse files
committed
Cleanup suggestion view and add feature flags to some animations
1 parent 0b9ca7f commit b9966db

6 files changed

Lines changed: 77 additions & 49 deletions

File tree

Core/Sources/HostApp/DebugView.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import Preferences
22
import SwiftUI
33

44
final class DebugSettings: ObservableObject {
5-
@AppStorage(\.disableLazyVStack) var disableLazyVStack
5+
@AppStorage(\.animationACrashSuggestion) var animationACrashSuggestion
6+
@AppStorage(\.animationBCrashSuggestion) var animationBCrashSuggestion
7+
@AppStorage(\.animationCCrashSuggestion) var animationCCrashSuggestion
68
@AppStorage(\.preCacheOnFileOpen) var preCacheOnFileOpen
79
@AppStorage(\.useCustomScrollViewWorkaround) var useCustomScrollViewWorkaround
810
@AppStorage(\.triggerActionWithAccessibilityAPI) var triggerActionWithAccessibilityAPI
@@ -15,8 +17,14 @@ struct DebugSettingsView: View {
1517
var body: some View {
1618
ScrollView {
1719
Form {
18-
Toggle(isOn: $settings.disableLazyVStack) {
19-
Text("Disable LazyVStack")
20+
Toggle(isOn: $settings.animationACrashSuggestion) {
21+
Text("Enable Animation A")
22+
}
23+
Toggle(isOn: $settings.animationBCrashSuggestion) {
24+
Text("Enable Animation B")
25+
}
26+
Toggle(isOn: $settings.animationCCrashSuggestion) {
27+
Text("Enable Widget Breathing Animation")
2028
}
2129
Toggle(isOn: $settings.preCacheOnFileOpen) {
2230
Text("Cache editor information on file open")

Core/Sources/SuggestionWidget/CustomScrollView/CustomScrollView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ struct CustomScrollView<Content: View>: View {
4040
.listStyle(.plain)
4141
.frame(idealHeight: max(10, height))
4242
.onPreferenceChange(CustomScrollViewHeightPreferenceKey.self) { newHeight in
43-
height = newHeight
43+
Task { @MainActor in
44+
height = newHeight
45+
}
4446
}
4547
} else {
4648
ScrollView {
@@ -49,3 +51,4 @@ struct CustomScrollView<Content: View>: View {
4951
}
5052
}
5153
}
54+

Core/Sources/SuggestionWidget/SuggestionPanelView.swift

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Environment
2+
import Preferences
23
import SwiftUI
34

45
@MainActor
@@ -20,40 +21,35 @@ final class SuggestionPanelViewModel: ObservableObject {
2021
}
2122
}
2223

23-
enum ActiveTab {
24-
case suggestion
25-
}
26-
27-
@Published var content: Content? {
28-
didSet {
29-
requestApplicationPolicyUpdate?(self)
30-
}
31-
}
32-
33-
@Published var activeTab: ActiveTab {
34-
didSet {
35-
requestApplicationPolicyUpdate?(self)
36-
}
37-
}
38-
24+
@Published var content: Content?
3925
@Published var isPanelDisplayed: Bool
4026
@Published var alignTopToAnchor = false
4127
@Published var colorScheme: ColorScheme
4228

43-
var requestApplicationPolicyUpdate: ((SuggestionPanelViewModel) -> Void)?
44-
4529
public init(
4630
content: Content? = nil,
4731
isPanelDisplayed: Bool = false,
48-
activeTab: ActiveTab = .suggestion,
49-
colorScheme: ColorScheme = .dark,
50-
requestApplicationPolicyUpdate: ((SuggestionPanelViewModel) -> Void)? = nil
32+
colorScheme: ColorScheme = .dark
5133
) {
5234
self.content = content
5335
self.isPanelDisplayed = isPanelDisplayed
54-
self.activeTab = activeTab
5536
self.colorScheme = colorScheme
56-
self.requestApplicationPolicyUpdate = requestApplicationPolicyUpdate
37+
}
38+
}
39+
40+
extension View {
41+
@ViewBuilder
42+
func animation<V: Equatable>(
43+
featureFlag: KeyPath<UserDefaultPreferenceKeys, FeatureFlag>,
44+
_ animation: Animation?,
45+
value: V
46+
) -> some View {
47+
let isOn = UserDefaults.shared.value(for: featureFlag)
48+
if isOn {
49+
self.animation(animation, value: value)
50+
} else {
51+
self
52+
}
5753
}
5854
}
5955

@@ -70,21 +66,19 @@ struct SuggestionPanelView: View {
7066

7167
VStack {
7268
if let content = viewModel.content {
73-
if case .suggestion = viewModel.activeTab {
74-
ZStack(alignment: .topLeading) {
75-
switch content {
76-
case let .suggestion(suggestion):
77-
CodeBlockSuggestionPanel(suggestion: suggestion)
78-
case let .promptToCode(provider):
79-
PromptToCodePanel(provider: provider)
80-
case let .error(description):
81-
ErrorPanel(viewModel: viewModel, description: description)
82-
}
69+
ZStack(alignment: .topLeading) {
70+
switch content {
71+
case let .suggestion(suggestion):
72+
CodeBlockSuggestionPanel(suggestion: suggestion)
73+
case let .promptToCode(provider):
74+
PromptToCodePanel(provider: provider)
75+
case let .error(description):
76+
ErrorPanel(viewModel: viewModel, description: description)
8377
}
84-
.frame(maxWidth: .infinity, maxHeight: Style.panelHeight)
85-
.fixedSize(horizontal: false, vertical: true)
86-
.allowsHitTesting(viewModel.isPanelDisplayed)
8778
}
79+
.frame(maxWidth: .infinity, maxHeight: Style.panelHeight)
80+
.fixedSize(horizontal: false, vertical: true)
81+
.allowsHitTesting(viewModel.isPanelDisplayed)
8882
}
8983
}
9084
.frame(maxWidth: .infinity)
@@ -101,9 +95,16 @@ struct SuggestionPanelView: View {
10195
guard viewModel.content != nil else { return 0 }
10296
return 1
10397
}())
104-
.animation(.easeInOut(duration: 0.2), value: viewModel.content?.contentHash)
105-
.animation(.easeInOut(duration: 0.2), value: viewModel.activeTab)
106-
.animation(.easeInOut(duration: 0.2), value: viewModel.isPanelDisplayed)
98+
.animation(
99+
featureFlag: \.animationACrashSuggestion,
100+
.easeInOut(duration: 0.2),
101+
value: viewModel.content?.contentHash
102+
)
103+
.animation(
104+
featureFlag: \.animationBCrashSuggestion,
105+
.easeInOut(duration: 0.2),
106+
value: viewModel.isPanelDisplayed
107+
)
107108
.frame(maxWidth: Style.panelWidth, maxHeight: Style.panelHeight)
108109
}
109110
}
@@ -155,7 +156,6 @@ struct SuggestionPanelView_Both_DisplayingSuggestion_Preview: PreviewProvider {
155156
currentSuggestionIndex: 0
156157
)),
157158
isPanelDisplayed: true,
158-
activeTab: .suggestion,
159159
colorScheme: .dark
160160
))
161161
.frame(width: 450, height: 200)

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class SuggestionWidgetController: NSObject {
2727
it.canBecomeKeyChecker = { false }
2828
return it
2929
}()
30-
30+
3131
private lazy var widgetWindow = {
3232
let it = CanBecomeKeyWindow(
3333
contentRect: .zero,
@@ -262,7 +262,7 @@ public final class SuggestionWidgetController: NSObject {
262262
}
263263
}
264264
}
265-
265+
266266
func orderFront() {
267267
widgetWindow.orderFrontRegardless()
268268
tabWindow.orderFrontRegardless()
@@ -324,7 +324,7 @@ public extension SuggestionWidgetController {
324324
}
325325
}
326326
}
327-
327+
328328
func presentDetachedGlobalChat() {
329329
chatWindowViewModel.chatPanelInASeparateWindow = true
330330
Task {

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class WidgetViewModel: ObservableObject {
1919
let deadline = date.timeIntervalSince1970 + 20
2020
isProcessingCounters.append(IsProcessingCounter(expirationDate: deadline))
2121
isProcessing = true
22-
22+
2323
cleanupIsProcessingCounterTask?.cancel()
2424
cleanupIsProcessingCounterTask = Task { [weak self] in
2525
try await Task.sleep(nanoseconds: 20 * 1_000_000_000)
@@ -105,6 +105,7 @@ struct WidgetView: View {
105105
.scaleEffect(x: scale, y: scale)
106106
.opacity(!empty || viewModel.isProcessing ? 1 : 0)
107107
.animation(
108+
featureFlag: \.animationCCrashSuggestion,
108109
.easeInOut(duration: 1).repeatForever(autoreverses: true),
109110
value: processingProgress
110111
)
@@ -117,7 +118,11 @@ struct WidgetView: View {
117118
.padding(minimumLineWidth / 2)
118119
.scaleEffect(x: scale, y: scale)
119120
.opacity(!empty || viewModel.isProcessing ? 1 : 0)
120-
.animation(.easeInOut(duration: 1), value: processingProgress)
121+
.animation(
122+
featureFlag: \.animationCCrashSuggestion,
123+
.easeInOut(duration: 1),
124+
value: processingProgress
125+
)
121126
}
122127
}
123128
}

Tool/Sources/Preferences/Keys.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,17 @@ public extension UserDefaultPreferenceKeys {
326326
var triggerActionWithAccessibilityAPI: FeatureFlag {
327327
.init(defaultValue: true, key: "FeatureFlag-TriggerActionWithAccessibilityAPI")
328328
}
329+
330+
var animationACrashSuggestion: FeatureFlag {
331+
.init(defaultValue: true, key: "FeatureFlag-AnimationACrashSuggestion")
332+
}
333+
334+
var animationBCrashSuggestion: FeatureFlag {
335+
.init(defaultValue: true, key: "FeatureFlag-AnimationBCrashSuggestion")
336+
}
337+
338+
var animationCCrashSuggestion: FeatureFlag {
339+
.init(defaultValue: true, key: "FeatureFlag-AnimationCCrashSuggestion")
340+
}
329341
}
330342

0 commit comments

Comments
 (0)