@@ -105,11 +105,68 @@ public struct ChatView<MessageContent: View, InputViewContent: View, MenuAction:
105105 mainView
106106 . background ( chatBackground ( ) )
107107 . environmentObject ( keyboardState)
108-
108+ . onAppear {
109+ if isGiphyAvailable ( ) {
110+ if let giphyKey = giphyConfig. giphyKey {
111+ if !giphyConfigured {
112+ giphyConfigured = true
113+ Giphy . configure ( apiKey: giphyKey)
114+ }
115+ } else {
116+ print ( " WARNING: giphy key not provided, please pass a key using giphyConfig " )
117+ }
118+ }
119+ }
120+ . onChange ( of: inputViewModel. text) { _ , newValue in
121+ inputViewCustomizationParameters. onInputTextChange ? ( newValue)
122+ }
123+ . onChange ( of: inputViewCustomizationParameters. externalInputText) {
124+ DispatchQueue . main. async {
125+ inputViewModel. text = inputViewCustomizationParameters. externalInputText ?? " "
126+ }
127+ }
128+ . onChange ( of: selectedGiphyMedia) {
129+ if let giphyMedia = selectedGiphyMedia {
130+ inputViewModel. attachments. giphyMedia = giphyMedia
131+ inputViewModel. send ( )
132+ }
133+ }
134+ . onChange ( of: inputViewModel. showPicker) { _ , newValue in
135+ if newValue {
136+ globalFocusState. focus = nil
137+ }
138+ }
139+ . onChange ( of: inputViewModel. showGiphyPicker) { _ , newValue in
140+ if newValue {
141+ globalFocusState. focus = nil
142+ }
143+ }
144+ . sheet ( isPresented: $inputViewModel. showGiphyPicker) {
145+ if giphyConfig. giphyKey != nil {
146+ GiphyEditorView (
147+ giphyConfig: giphyConfig,
148+ selectedMedia: $selectedGiphyMedia
149+ )
150+ . environmentObject ( globalFocusState)
151+ } else {
152+ Text ( " no giphy key found " )
153+ }
154+ }
155+ . fullScreenCover ( isPresented: $inputViewModel. showPicker) {
156+ AttachmentsEditor (
157+ inputViewModel: inputViewModel,
158+ inputViewBuilder: inputViewBuilder,
159+ mediaPickerParameters: inputViewCustomizationParameters. mediaPickerParameters,
160+ availableInputs: inputViewCustomizationParameters. availableInputs,
161+ localization: chatCustomizationParameters. localization
162+ )
163+ . environmentObject ( globalFocusState)
164+ . environmentObject ( keyboardState)
165+ }
109166 . fullScreenCover ( isPresented: $viewModel. fullscreenAttachmentPresented) {
110167 let attachments = sections. flatMap { section in section. rows. flatMap { $0. message. attachments } }
111168 let index = attachments. firstIndex { $0. id == viewModel. fullscreenAttachmentItem? . id }
112-
169+
113170 GeometryReader { g in
114171 FullscreenMediaPages (
115172 viewModel: FullscreenMediaPagesViewModel (
@@ -124,66 +181,6 @@ public struct ChatView<MessageContent: View, InputViewContent: View, MenuAction:
124181 . ignoresSafeArea ( )
125182 }
126183 }
127- // .onAppear {
128- // if isGiphyAvailable() {
129- // if let giphyKey = giphyConfig.giphyKey {
130- // if !giphyConfigured {
131- // giphyConfigured = true
132- // Giphy.configure(apiKey: giphyKey)
133- // }
134- // } else {
135- // print("WARNING: giphy key not provided, please pass a key using giphyConfig")
136- // }
137- // }
138- // }
139- // .onChange(of: inputViewModel.text) { _ , newValue in
140- // inputViewCustomizationParameters.onInputTextChange?(newValue)
141- // }
142- // .onChange(of: inputViewCustomizationParameters.externalInputText) {
143- // DispatchQueue.main.async {
144- // inputViewModel.text = inputViewCustomizationParameters.externalInputText ?? ""
145- // }
146- // }
147- // .onChange(of: selectedGiphyMedia) {
148- // if let giphyMedia = selectedGiphyMedia {
149- // inputViewModel.attachments.giphyMedia = giphyMedia
150- // inputViewModel.send()
151- // }
152- // }
153- // .sheet(isPresented: $inputViewModel.showGiphyPicker) {
154- // if giphyConfig.giphyKey != nil {
155- // GiphyEditorView(
156- // giphyConfig: giphyConfig,
157- // selectedMedia: $selectedGiphyMedia
158- // )
159- // .environmentObject(globalFocusState)
160- // } else {
161- // Text("no giphy key found")
162- // }
163- // }
164- // .fullScreenCover(isPresented: $inputViewModel.showPicker) {
165- // AttachmentsEditor(
166- // inputViewModel: inputViewModel,
167- // inputViewBuilder: inputViewBuilder,
168- // mediaPickerParameters: inputViewCustomizationParameters.mediaPickerParameters,
169- // availableInputs: inputViewCustomizationParameters.availableInputs,
170- // localization: chatCustomizationParameters.localization,
171- // messageStyler: messageCustomizationParameters.styler
172- // )
173- // .environmentObject(globalFocusState)
174- // .environmentObject(keyboardState)
175- // }
176-
177- . onChange ( of: inputViewModel. showPicker) { _ , newValue in
178- if newValue {
179- globalFocusState. focus = nil
180- }
181- }
182- . onChange ( of: inputViewModel. showGiphyPicker) { _ , newValue in
183- if newValue {
184- globalFocusState. focus = nil
185- }
186- }
187184 . background {
188185 // assume all the time views have same width, like "00:00"
189186 if let anyMessage = sections. first? . rows. first? . message, timeViewSize == . zero {
0 commit comments