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

Issue when currentlyFocusedInput is not found #3

Open
jacquesdev opened this issue Dec 30, 2023 · 1 comment
Open

Issue when currentlyFocusedInput is not found #3

jacquesdev opened this issue Dec 30, 2023 · 1 comment

Comments

@jacquesdev
Copy link

I'm experiencing an issue on this line:

currentlyFocusedInput.measureInWindow((_x, y, _width, height) => {

I'm getting this error: TypeError: Cannot read property 'measureInWindow' of null. That means this line

const currentlyFocusedInput = TextInput.State.currentlyFocusedInput();

is returning null

Now in my use case, this error happens when I switch between clicking on TextInputs that are sometimes disabled (since I want the look of a text input, but use an onPress to interact with instead). I'm wondering if your code would not be able to read it if it's disabled, and if that is why it's returning that type error? Otherwise I guess just finding a solution where you confirm that currentlyFocusedInput exists, eg currentlyFocusedInput?.measureInWindow

@rlemasquerier
Copy link
Owner

Hello @jacquesdev and thank you for reporting this issue!

I have tried to add a disabled text input in the example app (I have committed this change so you can test yourself 🙂) but I did not reproduce the error. Perhaps you are using an older version of react native ?

Anyway, I have published a new version by adding your suggested fix with a safety operator, as it does not cost anything. Does it solve your issue?

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