android - 如何在 react native 中缩小 WebView?

标签 android reactjs webview react-native

我在 react-native 中使用“WebView”来呈现网页。该网页没有适合移动设备的用户界面。

当我在 Chrome 浏览器中打开它时,它如下所示。 我想像下面那样渲染它

enter image description here

但是当我渲染下面的代码时,它看起来像下面显示的图像。 请看我尝试了不同的 Prop automaticallyAdjustContentInsets = {false} , scalesPageToFit={false}。但它并没有给我想要的输出。

render(){
    const URL  = "https://stellarterm.com";
    return(
          <WebView 
             source={{URL}}
          />

结果

enter image description here

如果您有任何解决方案,请随时提出建议。任何第三方库也可以。

最佳答案

您的网站已经在元数据中设置了页面宽度 <meta name="viewport" content="width=1080">

所以你需要用 injectedJavaScript 覆盖它

injectedJavaScript={`const meta = document.createElement('meta'); meta.setAttribute('content', 'width=device-width, initial-scale=0.5, maximum-scale=0.5, user-scalable=0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta); `} scalesPageToFit={false}

关于android - 如何在 react native 中缩小 WebView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50110920/

相关文章:

java - 在android中使 Canvas 动画

reactjs - 如何为 Material UI 的 TableHead 赋予圆角

javascript - 确定 react 组件是否为空

c# - 在 Windows 应用商店应用程序 WebView 中使用请求发布数据 - 使用 C#

java - 我的 cookie 似乎没有添加到 Android 中的 HttpsUrlConnection

android - 试图在运行时更改 TextView 的颜色,文本 "disappears"

android - Google Drive API 不能很好地与 ProGuard (NPE) 配合使用

javascript - Cloudinary 响应式图像仅在使用 Webpack 的 React 中的窗口大小变化时显示

android - 高亮文本功能,例如 google play book

javascript - 如何清除 react native webview cookies?