解决: React Native iOS webview 空白页

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

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

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

git 复制代码
diff --git a/node_modules/react-native-webview/apple/RNCWebView.mm b/node_modules/react-native-webview/apple/RNCWebView.mm
index f9d080e..10d90ee 100644
--- a/node_modules/react-native-webview/apple/RNCWebView.mm
+++ b/node_modules/react-native-webview/apple/RNCWebView.mm
@@ -244,7 +244,7 @@ - (instancetype)initWithFrame:(CGRect)frame
                 webViewEventEmitter->onHttpError(data);
             }
         };
-        self.contentView = _view;
+        [self addSubview:_view];
     }
     return self;
 }
@@ -488,6 +488,12 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
     [super updateProps:props oldProps:oldProps];
 }
 
+-(void)layoutSubviews
+{
+  [super layoutSubviews];
+  _view.frame = self.bounds;
+}
+
 - (void)handleCommand:(nonnull const NSString *)commandName args:(nonnull const NSArray *)args {
     RCTRNCWebViewHandleCommand(self, commandName, args);
 }
 
git 复制代码
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 复制代码
cd iOS
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf build Podfile.lock Pods
pod install
相关推荐
结局无敌10 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
茶底世界之下11 小时前
林间步道要不要加暗角?用 Awaking 把强度收在20%
前端·ios·图片资源
执子念的飞鱼11 小时前
纯前端预览 275 种文件格式是怎么做到的
前端·vue.js·react.js
season_zhu11 小时前
Skills For Real Engineers 系列之一:先配好项目,再让 ask-matt 帮我选技能
ios·openai·ai编程
结局无敌12 小时前
React Native for OpenHarmony 实战:三方库 react-native-paper 的鸿蒙化适配指南
javascript·人工智能·深度学习·react native·react.js·ecmascript·harmonyos
结局无敌13 小时前
React Native for OpenHarmony 实战:三方库 react-native-progress-steps 的鸿蒙化适配指南
javascript·人工智能·深度学习·react native·react.js·harmonyos
疯狂敲代码的老刘14 小时前
d2r-mobile:3.2千星开源暗黑破坏神2 iOS兼容层,3天冲上GitHub日榜
ios·github
Java后端的Ai之路1 天前
14、ReactJS - 路由(Router)
前端·react.js·状态模式
黑科技iOS上架1 天前
App Store5.6隐藏功能究竟怎么排查?
ios·审核
鶴哥只手遮天1 天前
React 19.3.1 源码深度剖析-第 12 章(下)RSC 与 Flight 协议
前端·react.js·开源