解决: 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 文件一定要改, 至关重要

git 复制代码
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;
 }
 

如果有错误:

sh 复制代码
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.

修改以下代码:

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

@Override 注释了

相关推荐
hnlgzb24 分钟前
常见的Android Jetpack库会有哪些?这些库中又有哪些常用类的?
android·android jetpack
~无忧花开~1 小时前
React状态管理完全指南
开发语言·前端·javascript·react.js·前端框架
@大迁世界2 小时前
1.什么是 ReactJS?
前端·javascript·react.js·前端框架·ecmascript
钛态4 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
王码码20354 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
左手厨刀右手茼蒿4 小时前
Flutter for OpenHarmony: Flutter 三方库 shamsi_date 助力鸿蒙应用精准适配波斯历法(中东出海必备)
android·flutter·ui·华为·自动化·harmonyos
代码飞天4 小时前
wireshark的高级使用
android·java·wireshark
Highcharts.js5 小时前
Highcharts React v4 迁移指南(下):分步代码示例与常见问题解决
javascript·react.js·typescript·react·highcharts·代码示例·v4迁移
2501_915918415 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
skiy5 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql