Skip to content

Commit

Permalink
Sync UI from VertexAI for Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
1998code committed May 16, 2024
1 parent 812a514 commit 1b328ed
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import GenerativeAIUIComponents
import GoogleGenerativeAI
import GenerativeAIUIComponents
import SwiftUI

struct ConversationScreen: View {
Expand Down Expand Up @@ -94,6 +94,8 @@ struct ConversationScreen: View {
}

private func sendOrStop() {
focusedField = nil

if viewModel.busy {
viewModel.stop()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import GenerativeAIUIComponents
import GoogleGenerativeAI
import GenerativeAIUIComponents
import SwiftUI

struct FunctionCallingScreen: View {
Expand Down Expand Up @@ -65,6 +65,9 @@ struct FunctionCallingScreen: View {
}
}
})
.onTapGesture {
focusedField = nil
}
}
InputField("Message...", text: $userPrompt) {
Image(systemName: viewModel.busy ? "stop.circle.fill" : "arrow.up.circle.fill")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ import SwiftUI
struct PhotoReasoningScreen: View {
@StateObject var viewModel = PhotoReasoningViewModel()

enum FocusedField: Hashable {
case message
}

@FocusState
var focusedField: FocusedField?

var body: some View {
VStack {
MultimodalInputField(text: $viewModel.userInput, selection: $viewModel.selectedItems)
.focused($focusedField, equals: .message)
.onSubmit {
onSendTapped()
}
Expand All @@ -47,11 +55,16 @@ struct PhotoReasoningScreen: View {
}
}
.navigationTitle("Multimodal sample")
.onAppear {
focusedField = .message
}
}

// MARK: - Actions

private func onSendTapped() {
focusedField = nil

Task {
await viewModel.reason()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ struct SummarizeScreen: View {

var body: some View {
VStack {
Text("Enter some text, then tap on _Go_ to summarize it.")
HStack(alignment: .top) {
TextField("Enter text summarize", text: $userInput, axis: .vertical)
.textFieldStyle(.roundedBorder)
.onSubmit {
VStack(alignment: .leading) {
Text("Enter some text, then tap on _Go_ to summarize it.")
.padding(.horizontal, 6)
HStack(alignment: .top) {
TextField("Enter text summarize", text: $userInput, axis: .vertical)
.focused($focusedField, equals: .message)
.textFieldStyle(.roundedBorder)
.onSubmit {
onSummarizeTapped()
}
Button("Go") {
onSummarizeTapped()
}
Button("Go") {
onSummarizeTapped()
.padding(.top, 4)
}
.padding(.top, 4)
}
.padding([.horizontal, .bottom])
.padding(.horizontal, 16)

List {
HStack(alignment: .top) {
Expand All @@ -61,6 +65,8 @@ struct SummarizeScreen: View {
}

private func onSummarizeTapped() {
focusedField = nil

Task {
await viewModel.summarize(inputText: userInput)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public struct InputField<Label>: View where Label: View {
}

Button(action: submit, label: label)
.padding(.top, 4)
.padding(.bottom, 4)
}
}
.padding(.horizontal)
.padding(8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct MultimodalInputField: View {
Button(action: showChooseAttachmentTypePicker) {
Image(systemName: "plus")
}
.padding(.top, 4)
.padding(.top, 10)

VStack(alignment: .leading) {
TextField(
Expand Down Expand Up @@ -110,7 +110,7 @@ public struct MultimodalInputField: View {
Button(action: submit) {
Text("Go")
}
.padding(.top, 4)
.padding(.top, 8)
}
}
.padding(.horizontal)
Expand Down

0 comments on commit 1b328ed

Please sign in to comment.