MojtabaHs / iPhoneNumberField

Elegant SwiftUI phone number textField.
MIT License
528 stars 87 forks source link

cannot assign keyboard type and cannot add done button in toolbar #80

Closed hussnainahmaddd closed 1 year ago

hussnainahmaddd commented 1 year ago

Hey i am currently using this package for my swiftui project and i can't access keyboardtype atribute plus i cannot done button as toolbar item to iphoneTextfield....

.keyboardType(.default) .submitLabel(.done) i want to access these.

Note: I am using package to use this library.

raduncicen commented 1 year ago

I have the same issue :/

Kn3cht commented 1 year ago

+1 Same issue

raduncicen commented 1 year ago

@Kn3cht Here is what I used to solve the issue for now.

You can use the configuration closure of the iPhoneNumberField to add a done button. I hope it helps! :)

iPhoneNumberField("(000) 000-0000",
                  text: viewStore.binding(\.$phoneNumber),
                  isEditing: $isEditingPhoneNumber,
                  configuration: { view in
    func getDoneButton() -> UIToolbar {
        let doneToolbar: UIToolbar = UIToolbar()
        doneToolbar.barStyle = .default
        let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

        let doneButton = UIButton(frame: .init(origin: .zero, size: .init(width: 28, height: 78)))
        doneButton.heightAnchor.constraint(equalToConstant: 28).isActive = true
        doneButton.widthAnchor.constraint(equalToConstant: 78).isActive = true
        doneButton.layer.cornerRadius = 14
        doneButton.setTitle("NEXT", for: .normal)
        doneButton.backgroundColor = .systemBlue
        doneButton.setTitleColor(.white, for: .normal)
        doneButton.titleLabel?.font = .contentSemibold
        doneButton.addAction(.init(handler: { _ in
            isEditingPhoneNumber = false
            setFocusField(.email)
        }), for: .touchUpInside)
        let done = UIBarButtonItem(customView: doneButton)

        var items = [UIBarButtonItem]()
        items.append(flexSpace)
        items.append(done)

        doneToolbar.items = items
        doneToolbar.sizeToFit()
        return doneToolbar
    }
    view.inputAccessoryView = getDoneButton()
})
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.