iPhoneNumberField icon indicating copy to clipboard operation
iPhoneNumberField copied to clipboard

iOS 13 BUG crash

Open Dave181295 opened this issue 2 years ago • 6 comments

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?

Dave181295 avatar Feb 15 '22 09:02 Dave181295

Is this library still maintained ?

Dave181295 avatar Jul 26 '22 11:07 Dave181295

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

MojtabaHs avatar Jul 27 '22 07:07 MojtabaHs

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

Screen Shot 2022-07-27 at 10 36 49

@MojtabaHs

Dave181295 avatar Jul 27 '22 07:07 Dave181295

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
}

Dave181295 avatar Jul 27 '22 07:07 Dave181295

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,

Dave181295 avatar Jul 27 '22 09:07 Dave181295

Can you provide an example project?

MojtabaHs avatar Aug 08 '22 12:08 MojtabaHs