question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requestFocus() call crashes on iOS

See original GitHub issue

Bug description: When I call requestFocus() on a webview I’m getting this error: dispatchViewManagerCommand must be called with a string or integer command This happens only on iOS, android looks OK.

To Reproduce: Pull the repro I made here: https://github.com/alexisbronchart/WebViewFocus

Expected behavior: The app should load the webview with the text input already focused as it does on android.

Environment:

  • OS: iOS
  • OS version: 13
  • react-native version: 0.61.4
  • react-native-webview version: 7.5.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
Slapboxcommented, Apr 29, 2021

Thanks for your reply @seanstrom.

I can confirm that calling .focus on an element through the injectedJavaScript prop was a “good-enough” workaround.

You’re right! After simply removing webview.current.requestFocus() it fixed the issue. Kind of baffling that it would break the app to call a supported method that’s required to achieve focusing the contents on Android, but ¯\_(ツ)_/¯ - at least it works!

1reaction
seanstromcommented, Apr 29, 2021

@Slapbox It’s been a while since I’ve dug into this, though I can try to help 😃. I’m not sure what the best way to compare notes will be, but I think I can post a demo with react-native-webview and expo. Are there any other dependencies that you’re using in your code? Can you provide a small example of how you’re using the ref version of the API? I’m not as familiar with the ref API in this case.

Based on my experience of using react-native-webview, I can confirm that calling .focus on an element through the injectedJavaScript prop was a “good-enough” workaround. Though, there’s a chance that loading the initial HTML or content of the webview isn’t “ready” before the .focus call on the node. In my case, I was loading the HTML and waiting for the page to fully load before calling .focus, I may even have deferred the call with a setTimeout too.

Some ideas for debugging:

  • Double check the injected code is running, maybe with a console.log statement
  • Verify that the element is being focused, you can try to attach styles or event handlers on the element to detect focus
  • Potentially play around with setTimeout around the .focus call, this can help with DOM elements that aren’t ready
Read more comments on GitHub >

github_iconTop Results From Across the Web

requestFocus() call crashes on iOS · Issue #1021 - GitHub
Bug description: When I call requestFocus() on a webview I'm getting this error: dispatchViewManagerCommand must be called with a string or ...
Read more >
Application crashes in NSOperationQueue - Stack Overflow
Don't call your block property completionBlock . NSOperation already has a completionBlock property (with a different signature). In my example ...
Read more >
Use Crash Detection on iPhone or Apple Watch to call for help ...
Crash Detection is designed to detect severe car crashes—such as front-impact, side-impact, and rear-end collisions, and rollovers—involving ...
Read more >
Handle input method visibility | Android Developers
For example, the following method takes a View in which the user is expected to type something, calls requestFocus() to give it focus, ......
Read more >
Understanding Flutter's keyboard focus system
The main reason to create your own FocusNode is to be able to call requestFocus() on the node to control the focus from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found