@@ -73,6 +73,7 @@ struct ContentView: View {
73
73
@State private var imagePickerSourceType : UIImagePickerController . SourceType = . photoLibrary
74
74
75
75
@State private var showingSettings = false
76
+ @FocusState private var textFieldFocused : Bool
76
77
77
78
enum PickerType {
78
79
case model
@@ -102,29 +103,46 @@ struct ContentView: View {
102
103
VStack {
103
104
if showingSettings {
104
105
VStack ( spacing: 20 ) {
105
- Form {
106
- Section ( header: Text ( " Model and Tokenizer " )
107
- . font ( . headline)
108
- . foregroundColor ( . primary) ) {
106
+ HStack {
107
+ VStack ( spacing: 10 ) {
109
108
Button ( action: { pickerType = . model } ) {
110
- Label ( resourceManager. modelName == " " ? modelTitle : resourceManager. modelName, systemImage: " doc " )
109
+ Label ( modelTitle, systemImage: " doc " )
110
+ . lineLimit ( 1 )
111
+ . truncationMode ( . middle)
112
+ . frame ( maxWidth: 300 , alignment: . leading)
111
113
}
112
114
Button ( action: { pickerType = . tokenizer } ) {
113
- Label ( resourceManager. tokenizerName == " " ? tokenizerTitle : resourceManager. tokenizerName, systemImage: " doc " )
115
+ Label ( tokenizerTitle, systemImage: " doc " )
116
+ . lineLimit ( 1 )
117
+ . truncationMode ( . middle)
118
+ . frame ( maxWidth: 300 , alignment: . leading)
114
119
}
115
120
}
121
+ . padding ( )
122
+ . background ( Color . gray. opacity ( 0.1 ) )
123
+ . cornerRadius ( 10 )
124
+ . fixedSize ( horizontal: true , vertical: false )
125
+ Spacer ( )
116
126
}
127
+ . padding ( )
117
128
}
118
129
}
119
130
120
131
MessageListView ( messages: $messages)
121
- . gesture (
132
+ . simultaneousGesture (
122
133
DragGesture ( ) . onChanged { value in
123
134
if value. translation. height > 10 {
124
- UIApplication . shared . sendAction ( #selector ( UIResponder . resignFirstResponder ) , to : nil , from : nil , for : nil )
135
+ hideKeyboard ( )
125
136
}
137
+ showingSettings = false
138
+ textFieldFocused = false
126
139
}
127
140
)
141
+ . onTapGesture {
142
+ showingSettings = false
143
+ textFieldFocused = false
144
+ }
145
+
128
146
HStack {
129
147
Button ( action: {
130
148
imagePickerSourceType = . photoLibrary
@@ -164,6 +182,11 @@ struct ContentView: View {
164
182
. stroke ( isInputEnabled ? Color . blue : Color . gray, lineWidth: 1 )
165
183
)
166
184
. disabled ( !isInputEnabled)
185
+ . focused ( $textFieldFocused)
186
+ . onAppear { textFieldFocused = false }
187
+ . onTapGesture {
188
+ showingSettings = false
189
+ }
167
190
168
191
Button ( action: isGenerating ? stop : generate) {
169
192
Image ( systemName: isGenerating ? " stop.circle " : " arrowshape.up.circle.fill " )
@@ -185,7 +208,7 @@ struct ContentView: View {
185
208
Button ( action: {
186
209
showingSettings. toggle ( )
187
210
} ) {
188
- Image ( systemName: " gearshape " )
211
+ Image ( systemName: " folder " )
189
212
. imageScale ( . large)
190
213
} ,
191
214
trailing:
@@ -465,6 +488,10 @@ struct ContentView: View {
465
488
case . tokenizer:
466
489
resourceManager. tokenizerPath = url. path
467
490
}
491
+ if resourceManager. isModelValid && resourceManager. isTokenizerValid {
492
+ showingSettings = false
493
+ textFieldFocused = true
494
+ }
468
495
case . failure( let error) :
469
496
withAnimation {
470
497
messages. append ( Message ( type: . info, text: " Failed to select a file: \( error. localizedDescription) " ) )
0 commit comments