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

Focus() in Input! #74

Closed
leommh-zz opened this issue Feb 28, 2019 · 20 comments
Closed

Focus() in Input! #74

leommh-zz opened this issue Feb 28, 2019 · 20 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed Type: Enhancement New feature or request

Comments

@leommh-zz
Copy link

Is your feature request related to a problem? Please describe.
The inputs do not pass the functions of focus (), blur (), among others of the TextInput of React Native.

Describe the solution you'd like
I would like these functions to be passed so that I could control focus and transfer from one input to another after I finish entering the value.

Describe alternatives you've considered
When the line:
ref = {input => (this.input = input)}
is added to the TextInput automatically the Input class wins the properties.

When creating the function:
function focusOnTextInput () {
return this.input.focus ()
};
It automatically causes the input to be focused, if it were to pass that function forward when the Input was imported, it was just to use it and the input would be focused.

But I tried to do this and the input does not show this function in its this, I do not know if it is because of the "withGalio" that is doing something, but the function does not come when using the input.

Additional context
Here is an example I could do by creating a customizable TextInput of mine!

1

2

@palingheorghe palingheorghe added Type: Enhancement New feature or request help wanted Extra attention is needed For discussion labels Mar 1, 2019
@iamshrikantjha
Copy link

Image 1
whatsapp image 2019-03-02 at 12 34 16 am
Image 2

whatsapp image 2019-03-02 at 12 34 11 am

When we are using expo application then in Login Screen option there is an issue with input.
Sorry I am not very much experienced but can I try to fix this?

@iamshrikantjha
Copy link

whatsapp image 2019-03-02 at 12 40 16 am
Same issue with register screen

@leommh-zz
Copy link
Author

Man, since it's an open library, I think you can try to sort and upload a pull request here in the project.

To try to give you a help and believe that this is happening because of the "KeyboardAvoidingView", this component has a property called keyboardVerticalOffset that defines how much effect it will apply when the input is selected.

Doc Official: https://facebook.github.io/react-native/docs/keyboardavoidingview

@hetmann
Copy link
Collaborator

hetmann commented Mar 19, 2019

@leommh maybe you can try using: https://reactjs.org/docs/forwarding-refs.html

@sam1463
Copy link
Contributor

sam1463 commented Jul 4, 2019

Another option, much like ref forwarding, but that would allow refs to either the galio input or the react-native textinput, would be to just add an onRef (or otherwise named) prop to the galio input component, which is then just passed to the text input.

// when you render the galio component
<Input
    onRef={input => { this.input = input }}
    ....
/>
// proposed changes to the galio component (in render method)
<TextInput
            ref={this.props.onRef} // passes the ref fn on to the text input
            style={inputStyles}
            keyboardType={type}
            secureTextEntry={isPassword}
            placeholderTextColor={placeholderTextColor}
            underlineColorAndroid="transparent"
            {...props}
          />

If that would be ok, I can open a PR. I've just changed it locally and it's working

@palingheorghe
Copy link
Collaborator

@sam1463 's solution is now included in v0.6

Thanks for your help!

@initzx
Copy link

initzx commented Oct 27, 2019

Hello, is there an example of how to get galio working with focus(). It doesn't seem to work for me, when i set onRef on the input i wish to focus on

@sam1463
Copy link
Contributor

sam1463 commented Oct 28, 2019

@initzx It should work to use it like this:

// in method where you want to focus on the input
this.input.focus();

...

// in render method
return (
  ...other stuff
  <Input
    onRef={(ref) => { this.input = ref; }}
    ...other input props
  />
  ...more stuff
);

@palingheorghe
Copy link
Collaborator

Thank you for explaining @sam1463 ! Just noticed the new Input misses that prop so it might not work. This needs to be updated asap so I'll reopen the issue.

@palingheorghe palingheorghe reopened this Oct 28, 2019
@palingheorghe palingheorghe added good first issue Good for newcomers and removed For discussion labels Oct 28, 2019
@sam1463
Copy link
Contributor

sam1463 commented Oct 28, 2019

@palingheorghe oh yeah good catch! It looks like in this commit when that component was changed from a class component to a functional one, the onRef prop got removed, probably just a bad merge resolution since that prop had only just barely made it into the repo before that.
e487742

@palingheorghe
Copy link
Collaborator

You think you can push another PR for this issue? @sam1463

@sam1463
Copy link
Contributor

sam1463 commented Oct 28, 2019

Yep, fixed it locally last night but haven't had time to open a PR yet. I should be able to when I get home later today.

@palingheorghe
Copy link
Collaborator

Thank you for your help! Looking forward to the PR!

@ammar-sheikh
Copy link

hey @sam1463
kindly can you push the PR!

@sam1463
Copy link
Contributor

sam1463 commented Dec 11, 2019

I already created one. For me, it's linked right above your comment, but in case that's not visible to you for some reason, it's here: #145

@palingheorghe
Copy link
Collaborator

Hi @ammar-sheikh ! I'll push the PR to the master server as soon as possible, I'm just trying to collect more PRs because some developers already invested into a workaround for lots of bugs we had so any new version could break their apps.

@gamingumar
Copy link

When the merge is expected?

@palingheorghe
Copy link
Collaborator

@gamingumar next week we'll clean the repo so we'll merge this PR as well because we're getting ready for v1.0.

@shiroze
Copy link

shiroze commented Mar 11, 2020

@initzx It should work to use it like this:

// in method where you want to focus on the input
this.input.focus();

...

// in render method
return (
  ...other stuff
  <Input
    onRef={(ref) => { this.input = ref; }}
    ...other input props
  />
  ...more stuff
);

I try using like this but give me null is not an object Package.json (v.0.6.3)

@palingheorghe
Copy link
Collaborator

Closed because we've merged the PR into the dev branch. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants