Love exploring this package but I'm having some trouble understanding a debug statement. I have a Form
of Sections
with TextFields
, each of which is connected to @BindingState
variables in my feature's State
. I have a binding
action, my Action implements BindableAction
, and I have a top level BindingReducer
initialized in my feature's reducer. Yet when I try to type in any of the TextFields
, I get one or two letters, then the contents erase and reset, and I get a purple error (recreated below). I have compared my code to elsewhere in my project where I have a similar set up (which works) and simply cannot identify where I've gone astray. Further, I'm curious if I'm missing something conceptually about how to debug these type of issues. I know TextField
has some errors with bindings but I'm not sure if this is related.
import ComposableArchitecture
import SwiftUI
struct NewDeck: Reducer {
@Dependency(\.uuid) var uuid
@Dependency(\.date.now) var date
public struct State: Equatable {
@BindingState var focus: Field? = .name
@BindingState var name: String = "" // these are the faulty BindingStates
@BindingState var subject: String = ""
@BindingState var tagsString: String = ""
@BindingState var selectedColor: Color = .white
init(focus: Field = .name) {
self.focus = focus
}
enum Field: Hashable {
case name
case subject
case tags
}
}
public enum Action: BindableAction, Equatable {
case binding(BindingAction<State>)
case delegate(Delegate)
case saveDeck
enum Delegate: Equatable {
case saveDeck(DeckModel)
}
}
var body: some ReducerOf<Self> {
BindingReducer()
Reduce { state, action in
switch action {
case .binding:
return .none
case .delegate:
return .none
case .saveDeck:
let deck = DeckModel(id: uuid(), name: state.name, dateCreated: date, dateLastStudied: date)
return .run { send in
await send(.delegate(.saveDeck(deck)))
}
}
}
}
}
struct NewDeckView: View {
var store: StoreOf<NewDeck>
@FocusState var focus: NewDeck.State.Field?
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
Form {
Section(header: Text("Deck Information")) {
TextField(
"Name",
text: viewStore.$name
)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.focused(self.$focus, equals: .name)
TextField(
"Subject",
text: viewStore.$subject
)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.focused(self.$focus, equals: .subject)
TextField(
"Tags (separated by spaces)",
text: viewStore.$tagsString
)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.focused(self.$focus, equals: .tags)
}
Section(header: Text("Color")) {
ColorPicker("Color", selection: viewStore.$selectedColor, supportsOpacity: false)
}
Button {
viewStore.send(.saveDeck)
} label: {
Text("Save Deck")
}
}
.navigationBarTitle("Create New Deck", displayMode: .inline)
}
}
}
### Error Message
2023-08-15 07:38:04.306789-0400 arabic-pencil-app[40994:4234536] [ComposableArchitecture] A binding action sent from a view store for binding state defined at "arabic_pencil_app/NewDeck.swift:23" was not handled. …
Action:
NewDeck.Action.binding(.set(_, ""))
To fix this, invoke "BindingReducer()" from your feature reducer's "body".
2023-08-15 07:38:04.307136-0400 arabic-pencil-app[40994:4234536] [ComposableArchitecture] A binding action sent from a view store for binding state defined at "arabic_pencil_app/NewDeck.swift:23" was not handled. …
Action:
NewDeck.Action.binding(.set(_, ""))
To fix this, invoke "BindingReducer()" from your feature reducer's "body".
[ad infinitum, multiple per keystroke]
Hoping some sharp eyed forum citizen can guide me down from the mountains of madness over this. Thanks!