requestFocus() call crashes on iOS
See original GitHub issueBug 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:
- Created 4 years ago
- Reactions:1
- Comments:11
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your reply @seanstrom.
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!@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
andexpo
. 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 theinjectedJavaScript
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 asetTimeout
too.Some ideas for debugging:
console.log
statementsetTimeout
around the.focus
call, this can help with DOM elements that aren’t ready