11import Environment
2+ import Preferences
23import 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 )
0 commit comments