当前位置: 首页 > news >正文

解决: React Native android webview 空白页

Android react-native-webview 之前是正常的, 升级了 react-native / react-native-webview 等 之后, 就变成了空白页.

通过下面的修改, 可以修复, 回到正常的状态.

来源: https://github.com/react-native-webview/react-native-webview/issues/3697

注意 ts 文件一定要改, 至关重要

在这里插入图片描述

index ff2cba5f710988acafe9dbc42ca814ea8622d8c3..47f37776e63eacfae8d41dd5c1adff51e317366d 100644
--- a/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java
+++ b/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java
@@ -313,6 +313,12 @@ public class RNCWebViewManager extends ViewGroupManager<RNCWebViewWrapper>mRNCWebViewManagerImpl.setSource(view, value);}+    @Override
+    @ReactProp(name = "source")
+    public void setSource(RNCWebViewWrapper view, @Nullable ReadableMap value) {
+        mRNCWebViewManagerImpl.setSource(view, value);
+    }
+@Override@ReactProp(name = "textZoom")public void setTextZoom(RNCWebViewWrapper view, int value) {
diff --git a/src/RNCWebViewNativeComponent.ts b/src/RNCWebViewNativeComponent.ts
index e2ddd361e1e2cb647bee370146b0ed020fb9fd02..39c8d3ec15cf878af0858a0abbb138982182cfe1 100644
--- a/src/RNCWebViewNativeComponent.ts
+++ b/src/RNCWebViewNativeComponent.ts
@@ -287,6 +287,15 @@ export interface NativeProps extends ViewProps {html?: string;baseUrl?: string;}>;
+  source: Readonly<{
+    uri?: string;
+    method?: string;
+    body?: string;
+
+    headers?: ReadonlyArray<Readonly<{ name: string; value: string }>>;
+    html?: string;
+    baseUrl?: string;
+  }>;userAgent?: string;injectedJavaScriptObject?: string;}

如果有错误:

FAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':react-native-webview:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler output below./Users/xxx/projects/xxxxx/node_modules/react-native-webview/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java:36: 错误: RNCWebViewManager不是抽象的, 并且未覆盖RNCWebViewManagerInterface中的抽象方法setSource(RNCWebViewWrapper,ReadableMap)public class RNCWebViewManager extends ViewGroupManager<RNCWebViewWrapper>^注: 某些输入文件使用或覆盖了已过时的 API。注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。1 个错误* Try:
> Check your code and dependencies to fix the compilation error(s)
> Run with --scan to get full insights.

修改以下代码:

    // @Override@ReactProp(name = "source")public void setSource(RNCWebViewWrapper view, @Nullable ReadableMap value) {mRNCWebViewManagerImpl.setSource(view, value);}

@Override 注释了

相关文章:

  • Docker基础理论与阿里云Linux服务器安装指南
  • 双因子认证如何让Windows系统登录更安全?SLA操作系统双因素认证解决方案深度解析
  • 裸金属服务器深度评测:云计算时代的性能与安全担当​​​​
  • 01、python实现matlab的插值算法,以及验证
  • 云原生安全
  • 操作系统期末复习--操作系统初识以及进程与线程
  • ios如何把H5网页变成主屏幕webapp应用
  • 算法导论第十四章 B树与B+树:海量数据的守护者
  • 日语学习-日语知识点小记-构建基础-JLPT-N4阶段(36):复习
  • Spring Boot(九十二):Spring Boot实现连接不上数据库就重启服务
  • 【MacOS】M3 Pro芯片MacBook极速搭建Kubernetes
  • 第21篇:数据库中间件的状态同步、事件驱动与一致性协议实践
  • 客户端开发八股
  • LeetCode 632.最小区间
  • 《HTTP权威指南》 第1-2章 HTTP和URL基础
  • ArkUI-X跨平台技术落地-华为运动健康(一)
  • python大学校园旧物捐赠系统
  • ROS2 笔记汇总(2) 通信接口
  • Android Retrofit 解析
  • 数学建模会议笔记
  • 软件企业网站模板/做一个官网要多少钱
  • 企业网站欣赏/上海网络优化服务
  • 南宁企业如何建网站/百度怎么做广告
  • web前端网站开发费用/社区营销
  • 湖南网站建设欧黎明/win7优化工具哪个好用
  • 做网站运营怎么样/深圳龙岗区优化防控措施