解决: 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 注释了

相关推荐
gfdgd xi21 小时前
好消息:KMRE 安卓模拟器现可在Debian/GXDE使用
android·python·架构·bug·deepin·龙芯
La Pulga21 小时前
【STM32】FLASH闪存
android·c语言·javascript·stm32·单片机·嵌入式硬件·mcu
游戏开发爱好者81 天前
iOS 崩溃日志分析工具全指南,多工具协同构建稳定性分析体系
android·macos·ios·小程序·uni-app·cocoa·iphone
明仔的阳光午后1 天前
React 入门 02:从单页面应用到多页面应用
前端·react.js·前端框架
.生产的驴1 天前
React 页面路由ReactRouter 路由跳转 参数传递 路由配置 嵌套路由
前端·javascript·react.js·前端框架·json·ecmascript·html5
苏卫苏卫苏卫1 天前
【码源】智能无人仓库管理系统(详细码源下~基于React+TypeScript+Vite):
前端·react.js·typescript·vite·项目设计·智能无人仓库管理系统·码源
listhi5201 天前
利用React Hooks简化状态管理
前端·javascript·react.js
晨陌y1 天前
深入剖析:仓颉语言的性能优化核心技术
android·性能优化·仓颉
xhbh6661 天前
【实战总结】MySQL日期加减大全:日期计算、边界处理与性能优化详解
android
00后程序员张1 天前
如何提高 IPA 安全性 多工具组合打造可复用的 iOS 加固与反编译防护体系(IPA 安全 iOS 加固 无源码混淆 Ipa Guard 实战)
android·安全·ios·小程序·uni-app·iphone·webview