Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you change PIN styling without clearing it first? #44

Closed
kosakoytim opened this issue May 27, 2020 · 3 comments
Closed

How do you change PIN styling without clearing it first? #44

kosakoytim opened this issue May 27, 2020 · 3 comments

Comments

@kosakoytim
Copy link

I have a case where i need to change my PIN style text color, underline color when the PIN input is invalid. I can't seem to do this without calling pin.clearPin() which will reload the view and clear all the input. Is there another way to do this?
Thanks

@xornorik
Copy link
Owner

xornorik commented May 27, 2020

There is a way in which you can do this, although it's a little ugly.

The didChangeCallback gives you the pin that has been entered so far, this can be stored on the presenting layer (ViewController). You can then set the error styling, call clearPin() and follow it up by pasting the partial (or complete) pin using the pastePin method.

The pasting will have to be delayed by a small offset in order for the view to have time to render itself before the pin is copied (hence ugly 😅).

errorState

pinView.didChangeCallback = { pin in
    self.tempPinStore = pin
    print("The entered pin is \(pin)") 
}

// toggle error state
pinView.textColor = .red
pinView.activeBorderLineColor = .red
pinView.borderLineColor = .red
pinView.becomeFirstResponderAtIndex = tempPinStore.count
clearPin()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
    self.pinView.pastePin(pin: self.tempPinStore)
}

Thanks for sharing your use-case, will try and improve on the way this is handled.
Do let me know if this resolves your problem.

@kosakoytim
Copy link
Author

I actually tried a similar method earlier, but got an error because i didn't add a delay for the rendering. This will solve for now, thanks!

@xornorik
Copy link
Owner

xornorik commented Aug 2, 2020

@kosakoytim
I have added a completionHandler for the clearPin method in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants