Skip to content

Commit e8bbb72

Browse files
authored
Sync UI from VertexAI for Firebase (#172)
1 parent 29fdb77 commit e8bbb72

File tree

6 files changed

+37
-13
lines changed

6 files changed

+37
-13
lines changed

Examples/GenerativeAISample/ChatSample/Screens/ConversationScreen.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct ConversationScreen: View {
9494
}
9595

9696
private func sendOrStop() {
97+
focusedField = nil
98+
9799
if viewModel.busy {
98100
viewModel.stop()
99101
} else {

Examples/GenerativeAISample/FunctionCallingSample/Screens/FunctionCallingScreen.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ struct FunctionCallingScreen: View {
6565
}
6666
}
6767
})
68+
.onTapGesture {
69+
focusedField = nil
70+
}
6871
}
6972
InputField("Message...", text: $userPrompt) {
7073
Image(systemName: viewModel.busy ? "stop.circle.fill" : "arrow.up.circle.fill")

Examples/GenerativeAISample/GenerativeAIMultimodalSample/Screens/PhotoReasoningScreen.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ import SwiftUI
2020
struct PhotoReasoningScreen: View {
2121
@StateObject var viewModel = PhotoReasoningViewModel()
2222

23+
enum FocusedField: Hashable {
24+
case message
25+
}
26+
27+
@FocusState
28+
var focusedField: FocusedField?
29+
2330
var body: some View {
2431
VStack {
2532
MultimodalInputField(text: $viewModel.userInput, selection: $viewModel.selectedItems)
33+
.focused($focusedField, equals: .message)
2634
.onSubmit {
2735
onSendTapped()
2836
}
@@ -47,11 +55,16 @@ struct PhotoReasoningScreen: View {
4755
}
4856
}
4957
.navigationTitle("Multimodal sample")
58+
.onAppear {
59+
focusedField = .message
60+
}
5061
}
5162

5263
// MARK: - Actions
5364

5465
private func onSendTapped() {
66+
focusedField = nil
67+
5568
Task {
5669
await viewModel.reason()
5770
}

Examples/GenerativeAISample/GenerativeAITextSample/Screens/SummarizeScreen.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ struct SummarizeScreen: View {
2828

2929
var body: some View {
3030
VStack {
31-
Text("Enter some text, then tap on _Go_ to summarize it.")
32-
HStack(alignment: .top) {
33-
TextField("Enter text summarize", text: $userInput, axis: .vertical)
34-
.textFieldStyle(.roundedBorder)
35-
.onSubmit {
31+
VStack(alignment: .leading) {
32+
Text("Enter some text, then tap on _Go_ to summarize it.")
33+
.padding(.horizontal, 6)
34+
HStack(alignment: .top) {
35+
TextField("Enter text summarize", text: $userInput, axis: .vertical)
36+
.focused($focusedField, equals: .message)
37+
.textFieldStyle(.roundedBorder)
38+
.onSubmit {
39+
onSummarizeTapped()
40+
}
41+
Button("Go") {
3642
onSummarizeTapped()
3743
}
38-
Button("Go") {
39-
onSummarizeTapped()
44+
.padding(.top, 4)
4045
}
41-
.padding(.top, 4)
4246
}
43-
.padding([.horizontal, .bottom])
47+
.padding(.horizontal, 16)
4448

4549
List {
4650
HStack(alignment: .top) {
@@ -61,6 +65,8 @@ struct SummarizeScreen: View {
6165
}
6266

6367
private func onSummarizeTapped() {
68+
focusedField = nil
69+
6470
Task {
6571
await viewModel.summarize(inputText: userInput)
6672
}

Examples/GenerativeAISample/GenerativeAIUIComponents/Sources/GenerativeAIUIComponents/InputField.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public struct InputField<Label>: View where Label: View {
6060
}
6161

6262
Button(action: submit, label: label)
63-
.padding(.top, 4)
63+
.padding(.bottom, 4)
6464
}
6565
}
66-
.padding(.horizontal)
66+
.padding(8)
6767
}
6868
}
6969

Examples/GenerativeAISample/GenerativeAIUIComponents/Sources/GenerativeAIUIComponents/MultimodalInputField.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct MultimodalInputField: View {
6969
Button(action: showChooseAttachmentTypePicker) {
7070
Image(systemName: "plus")
7171
}
72-
.padding(.top, 4)
72+
.padding(.top, 10)
7373

7474
VStack(alignment: .leading) {
7575
TextField(
@@ -110,7 +110,7 @@ public struct MultimodalInputField: View {
110110
Button(action: submit) {
111111
Text("Go")
112112
}
113-
.padding(.top, 4)
113+
.padding(.top, 8)
114114
}
115115
}
116116
.padding(.horizontal)

0 commit comments

Comments
 (0)