iPhoneNumberField
iPhoneNumberField copied to clipboard
iOS 13 BUG crash
iOS 14 & 15 working correctly, but on iOS 13 We keep getting
Fatal error: Accessing State<Bool> outside View.body: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-24.4/Core/State.swift, line 44
Xcode complaining about this line from the library's code :
Coordinator(text: $text,
isFirstResponder: externalIsFirstResponder ?? $internalIsFirstResponder, <-- HERE
onBeginEditing: onBeginEditingHandler,
onEditingChange: onEditingChangeHandler,
onEndEditing: onEndEditingHandler,
onClear: onClearHandler,
onReturn: onReturnHandler)
}
Here our code :
iPhoneNumberField("xxx-xxx-xxxx", text: $phoneNumber)
.defaultRegion("IL")
.font(UIFont(name: "Poppins-Medium", size: idiom == .pad ? 30 : 20))
.textFieldStyle(.none)
.prefixHidden(false)
.maximumDigits(10)
.flagHidden(true)
.flagSelectable(false)
.clearsOnEditingBegan(true)
// .multilineTextAlignment(.leading)
.introspectTextField { textField in
if let text = textField.text, text.isEmpty {
textField.becomeFirstResponder()
}
}
We are pretty sure its a bug from the library What's your thoughts?
Is this library still maintained ?
Looks like you are setting internalIsFirstResponder
outside of the body
! You must never change the @State
from outside. try making it private
to find where is the cause of this bug
Thanks, This one is resolved we just changed the order of the modifiers, but looks like there is another one coming from the internal files of the library
@MojtabaHs
We are not using the State property outside of the body
we declare the instance of PhoneNumber
in a var phoneView: some View {}
then just calling it in the body
var body: some View {
phoneView
}
Update
Even with a constant String its crashing
iPhoneNumberField(nil , text: .constant("********"))
Pretty sure it's coming from the lib, can you take a look ?
Greetings,
Can you provide an example project?