Fixes focus states

release
Laurent 3 years ago
parent 31f4d2963f
commit 9aaeba7cf5
  1. 2
      LeCountdown/Views/Countdown/CountdownFormView.swift
  2. 2
      LeCountdown/Views/NewDataView.swift
  3. 14
      LeCountdown/Views/Stopwatch/NewStopwatchView.swift
  4. 25
      LeCountdown/Views/Stopwatch/StopwatchFormView.swift

@ -50,7 +50,7 @@ struct CountdownFormView : View {
TextField("Name (activates tracking)", text: nameBinding)
.focused($focusedField, equals: .name)
.onSubmit {
self.focusNextField($focusedField)
self.focusedField = nil
}
}

@ -52,7 +52,7 @@ struct NewDataView: View {
NewStopwatchView(isPresented: $isPresented)
.tag(1)
.environment(\.managedObjectContext, viewContext)
}
}.tabViewStyle(.page(indexDisplayMode: .never))
}
}

@ -48,9 +48,7 @@ struct StopwatchEditView: View {
@State var errorShown: Bool = false
@State var error: Error? = nil
@FocusState private var textFieldIsFocused: Bool
@State var _isAdding: Bool = false
@Environment(\.isPresented) var envIsPresented
@ -69,8 +67,7 @@ struct StopwatchEditView: View {
}
StopwatchFormView(nameBinding: self.$nameString,
imageBinding: self.$image,
playSoundBinding: self.$playSound,
textFieldIsFocused: $textFieldIsFocused).environmentObject(self.model)
playSoundBinding: self.$playSound).environmentObject(self.model)
.onAppear {
self._onAppear()
}
@ -121,13 +118,6 @@ struct StopwatchEditView: View {
}
}
}
ToolbarItemGroup(placement: .keyboard) {
Button {
textFieldIsFocused = false
} label: {
Image(systemName: "keyboard.chevron.compact.down")
}
}
}
.navigationTitle("Edit stopwatch")
}

@ -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())
}
}

Loading…
Cancel
Save