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

相关推荐
名字还没想好☜6 小时前
React 实现暗黑模式切换:localStorage 持久化、SSR 首屏闪烁与跟随系统主题
前端·javascript·react.js·ecmascript·react·next.js
文人sec12 小时前
MySQL主库出问题了,从库怎么办?备库为什么会延迟好几个小时?
android·数据库·mysql
hai_android12 小时前
不用 AIDL,手把手教你手写 Binder 代理类
android·kotlin
mmsx13 小时前
osmdroid 地图实战 03|地图的"分层世界":离线方案、图层模型与 Overlay 体系
android·前端
张文是假的啊14 小时前
IOC依赖注入问题:@Primary 和 @Qualifier的使用
android
换元不配限14 小时前
ConstraintLayout核心用法详解(三):引导线、屏障、组和占位
android·placeholder·barrier·约束布局·guideline
心平气和量大福大16 小时前
android studio(AS)工具-调试-统计总行数
android·ide·android studio
你的坚定17 小时前
SurfaceFlinger合成一帧的完整流程
android
爱笑鱼19 小时前
Android 系统启动机制(七):进入 SystemServer.main() 以后,system_server 还是一个空进程吗?
android·linux
好安静19 小时前
SurfaceFlinger 合成一帧的完整流程
android