candostdagdeviren / CDAlertView

Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
https://candostdagdeviren.github.io/CDAlertView/
MIT License
1.14k stars 86 forks source link

Add ability to make textField becomeFirstResponder #18

Closed mlchild closed 7 years ago

mlchild commented 7 years ago

This is an awesome library, thanks for doing it. It would be a cool enhancement if I could make the textField firstResponder so that the user could start typing immediately.

candostdagdeviren commented 7 years ago

HI @mlchild, thanks for the idea. This one should be easy. We can do it for the next release. Do you maybe have time to help out with this?

mlchild commented 7 years ago

Sure, I think could just add:

public func becomeFirstResponder() { textField.becomeFirstResponder() }

after the show/hide/add functions in CDAlertView.swift at line 320 (not sure how to do pull request, ha).

Could also do this one for symmetry:

public func resignFirstResponder() { textField.resignFirstResponder() }

candostdagdeviren commented 7 years ago

It's better to check with isTextFieldHidden property. If it is hidden, we don't need to interrupt current responder chain. So I would suggest that

public func becomeFirstResponder() {
    if !isTextFieldHidden {
        textField.becomeFirstResponder()
    }
}

same for resigning.

To do a PR, you should fork the repository first. This process will clone this repository to your account with saving connection to this one. Than you do your changes in forked repository (the one in your account). And from there, you will see New Pull Request button next to branch list. After pressing that, GitHub'll show you this repository and master branch as a base fork. And you only need to press Create Pull Request button in there :)