Closed Little-tale closed 1 month ago
Hi @Little-tale, this is not an issue with the library, but rather just how SwiftUI works. You cannot make modifications to the state powering a TextField
binding in the willSet
/didSet
. SwiftUI will just ignore those changes.
This issue has come up a lot, so I recommend searching the discussions for possible workarounds. Here is is the most recent time that it came up.
Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there!
Description
From Swift UI to TCA Failed to configure membership logic. While configuring the logic of TextField for phone number configuration
I've confirmed that it works fine on iOS 16 and below, and it doesn't work from 17.
` // SignUpFeature case let .contactChanged(phones):
let clean = phones.filter { $0.isNumber }
let result = TextValid.TextValidate(phones, caseOf: .phoneNumber)
print("sss") // // state.user.contact = phones state.user.contact = formatPhoneNumber(clean) state.contactValid = result return .none
/// View VStack (alignment: .leading) { Text(Const.SignUpView.contact.title) TextField( Const.SignUpView.contact.placeHolder, text: $store.user.contact.sending(.contactChanged) ) .modifier(DefaultTextFieldViewModifier()) } .padding(.horizontal, 30) `
The code was configured as above. However, contrary to expectations, TextField only reflects the value entered by the user and does not reflect the value that goes through my logic.
For testing, simply
state.contactValid = " NONE " Even when you say that, NONE is reflected only in the beginning After that, it's not reflected.
How do I solve this problem?
Checklist
main
branch of this package.Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
The Composable Architecture version information
1.10.4
Destination operating system
iOS 16, 17
Xcode version information
Xcode 15.3
Swift Compiler version information
No response