|
|
|
|
@ -9,26 +9,44 @@ import SwiftUI |
|
|
|
|
|
|
|
|
|
struct StopwatchFormView: View { |
|
|
|
|
|
|
|
|
|
enum StopwatchField: Int, Hashable { |
|
|
|
|
case name |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@FocusState private var focusedField: StopwatchField? |
|
|
|
|
|
|
|
|
|
var nameBinding: Binding<String> |
|
|
|
|
var imageBinding: Binding<CoolPic> |
|
|
|
|
var playSoundBinding: Binding<Bool> |
|
|
|
|
|
|
|
|
|
@EnvironmentObject var model: TimerModel |
|
|
|
|
|
|
|
|
|
var textFieldIsFocused: FocusState<Bool>.Binding |
|
|
|
|
// var textFieldIsFocused: FocusState<Bool>.Binding |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
|
|
|
|
|
Form { |
|
|
|
|
Section(header: Text("Name for tracking the activity")) { |
|
|
|
|
TextField("name", text: nameBinding) |
|
|
|
|
.focused(textFieldIsFocused) |
|
|
|
|
.focused($focusedField, equals: .name) |
|
|
|
|
.onSubmit { |
|
|
|
|
self.focusedField = nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SoundImageFormView(imageBinding: imageBinding, |
|
|
|
|
optionalSound: playSoundBinding) |
|
|
|
|
.environmentObject(self.model) |
|
|
|
|
|
|
|
|
|
}.toolbar { |
|
|
|
|
ToolbarItemGroup(placement: .keyboard) { |
|
|
|
|
Button { |
|
|
|
|
self.focusedField = nil |
|
|
|
|
} label: { |
|
|
|
|
Image(systemName: "keyboard.chevron.compact.down") |
|
|
|
|
} |
|
|
|
|
Spacer() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -41,8 +59,7 @@ struct StopwatchFormView_Previews: PreviewProvider { |
|
|
|
|
StopwatchFormView( |
|
|
|
|
nameBinding: .constant(""), |
|
|
|
|
imageBinding: .constant(.pic1), |
|
|
|
|
playSoundBinding: .constant(true), |
|
|
|
|
textFieldIsFocused: $textFieldIsFocused) |
|
|
|
|
playSoundBinding: .constant(true)) |
|
|
|
|
.environmentObject(TimerModel()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|