解决: 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
相关推荐
疯笔码良5 分钟前
iOS 国际化与本地化完整指南
ios·swift
库奇噜啦呼1 小时前
【iOS】GCD学习
学习·ios·cocoa
m0_726965981 小时前
ReAct 小发展
前端·react.js·前端框架
2401_860319522 小时前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Overlay 遮罩层(创建一个遮罩层)
react native·react.js·harmonyos
Kathleen1002 小时前
iOS--TableView的复用机制以及性能优化(处理网络数据)
ios·性能优化·网络请求·gcd·uitableview
七夜zippoe2 小时前
基于ReAct框架的智能体构建实战 - 从原理到企业级应用
前端·javascript·react.js·llm·agent·react
2401_860494703 小时前
【精通篇】打造React Native鸿蒙跨平台开发高级复合组件库开发系列:Slider 滑块(用于在给定的范围内选择一个值)
react native·react.js·harmonyos
梦6503 小时前
react,Table 表格树形如何展开所有子集,以及自定义展开按钮样式
前端·javascript·react.js
黑客思维者3 小时前
核弹级漏洞突袭React生态:RSC反序列化何以成为RCE通道?
前端·javascript·react.js·远程代码执行漏洞
接着奏乐接着舞4 小时前
react hooks
前端·javascript·react.js