Skip to content

Commit 39aa351

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Fix file picker titles.
Summary: #6179 {F1924184601} Reviewed By: mergennachin Differential Revision: D64260858
1 parent dabb14e commit 39aa351

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

examples/demo-apps/apple_ios/LLaMA/LLaMA/Application/ContentView.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct ContentView: View {
7373
@State private var imagePickerSourceType: UIImagePickerController.SourceType = .photoLibrary
7474

7575
@State private var showingSettings = false
76+
@FocusState private var textFieldFocused: Bool
7677

7778
enum PickerType {
7879
case model
@@ -102,18 +103,24 @@ struct ContentView: View {
102103
VStack {
103104
if showingSettings {
104105
VStack(spacing: 20) {
105-
Form {
106-
Section(header: Text("Model and Tokenizer")
107-
.font(.headline)
108-
.foregroundColor(.primary)) {
106+
HStack {
107+
VStack(spacing: 10) {
109108
Button(action: { pickerType = .model }) {
110-
Label(resourceManager.modelName == "" ? modelTitle : resourceManager.modelName, systemImage: "doc")
109+
Label(modelTitle, systemImage: "doc")
110+
.frame(maxWidth: .infinity, alignment: .leading)
111111
}
112112
Button(action: { pickerType = .tokenizer }) {
113-
Label(resourceManager.tokenizerName == "" ? tokenizerTitle : resourceManager.tokenizerName, systemImage: "doc")
113+
Label(tokenizerTitle, systemImage: "doc")
114+
.frame(maxWidth: .infinity, alignment: .leading)
114115
}
115116
}
117+
.padding()
118+
.background(Color.gray.opacity(0.1))
119+
.cornerRadius(10)
120+
.fixedSize(horizontal: true, vertical: false)
121+
Spacer()
116122
}
123+
.padding()
117124
}
118125
}
119126

@@ -123,8 +130,19 @@ struct ContentView: View {
123130
if value.translation.height > 10 {
124131
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
125132
}
133+
showingSettings = false
126134
}
127135
)
136+
.onTapGesture {
137+
showingSettings = false
138+
}
139+
.focused($textFieldFocused)
140+
.onChange(of: textFieldFocused) { oldValue, newValue in
141+
if newValue {
142+
showingSettings = false
143+
}
144+
}
145+
128146
HStack {
129147
Button(action: {
130148
imagePickerSourceType = .photoLibrary
@@ -164,6 +182,9 @@ struct ContentView: View {
164182
.stroke(isInputEnabled ? Color.blue : Color.gray, lineWidth: 1)
165183
)
166184
.disabled(!isInputEnabled)
185+
.onTapGesture {
186+
showingSettings = false
187+
}
167188

168189
Button(action: isGenerating ? stop : generate) {
169190
Image(systemName: isGenerating ? "stop.circle" : "arrowshape.up.circle.fill")
@@ -449,6 +470,7 @@ struct ContentView: View {
449470
private func handleFileImportResult(_ pickerType: PickerType?, _ result: Result<[URL], Error>) {
450471
switch result {
451472
case .success(let urls):
473+
showingSettings = false
452474
guard let url = urls.first, let pickerType else {
453475
withAnimation {
454476
messages.append(Message(type: .info, text: "Failed to select a file"))

0 commit comments

Comments
 (0)