weixin_39773447
weixin_39773447
2021-01-08 18:18

requestFocus() call crashes on iOS

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

该提问来源于开源项目:react-native-webview/react-native-webview

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39806948 weixin_39806948 4月前

    Subscribing... Screen Shot 2020-01-06 at 7 17 27 AM

    点赞 评论 复制链接分享
  • weixin_39607937 weixin_39607937 4月前

    Having the issue, when trying to focus a webView in IOS. Any solution for this ?

    点赞 评论 复制链接分享
  • weixin_39948824 weixin_39948824 4月前

    If anyone is running into this issue, you should be able to set the keyboardDisplayRequiresUserAction prop to false (for IOS) and then request focus by using the injectedJavaScript prop.

    Pseudo Code Example

    javascript
    const INJECTED_JAVASCRIPT = `(function() {
        var inputId = 'search_input_react';
        var searchInputElement = window.document.getElementById(inputId);
    
        if (searchInputElement) {
          searchInputElement.focus();
        }
    })();`;
    
    <webview source="{{" uri: injectedjavascript="{INJECTED_JAVASCRIPT}" keyboarddisplayrequiresuseraction="{false}"></webview>;
    
    点赞 评论 复制链接分享
  • weixin_39778106 weixin_39778106 4月前

    Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

    点赞 评论 复制链接分享
  • weixin_39676242 weixin_39676242 4月前

    Issue is still here. thanks for the workaround. In my current use case I also had to call blur before focus to get it to work.

    点赞 评论 复制链接分享
  • weixin_39717029 weixin_39717029 4月前

    Issue persists for me with the exact same error message, dispatchViewManagerCommand must be called with a string or integer command

    • react-native-webview.7.0
    • expo.0.3
    点赞 评论 复制链接分享
  • weixin_39717029 weixin_39717029 4月前

    I absolutely cannot find a workaround here. Does anyone have any tips?

    In our case, we're trying to focus the a DOM node using this.webview.current.injectJavaScript([ourcommand]) instead of injectedJavaScript prop, but the injected code is essentially the same, and we get the same error as OP.

    , I assume you mean you had to blur a DOM element inside the webview, right? Because as far as I can tell the webview itself doesn't have a blur method. Were you getting an error without blurring, or just a lack of focus?

    点赞 评论 复制链接分享
  • weixin_39737001 weixin_39737001 4月前

    i have the same problem.

    点赞 评论 复制链接分享

相关推荐