问题:如何在react native webview实现html代码注入,实现手势放大缩小?



  • 【描述】:在iOS OC代码中webview加载网页完成后,注入代码段,如下:

    • (void)webViewDidFinishLoad:(UIWebView *)webView
      {
      NSString *jsMeta = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=3';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"];

      [webView stringByEvaluatingJavaScriptFromString:jsMeta];
      }
      【问题】请问在react native是如何实现注入实现手势放大缩小?



  • 问题已解决,不断踏坑啊。
    贴代码段:

            onLoadEnd={(e) => console.log('onLoadEnd')
                this.WebView.injectedJavaScript="var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=2';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"
            }