解决: 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
相关推荐
zhenryx2 小时前
React Native 自定义 ScrollView 滚动条:开箱即用的 IndicatorScrollView(附源码示例)
javascript·react native·react.js·typescript
GISer_Jing2 小时前
2025年Flutter与React Native对比
android·flutter·react native
2501_915918413 小时前
移动端 HTTPS 抓包实战,多工具组合分析与高效排查指南
数据库·网络协议·ios·小程序·https·uni-app·iphone
Digitally3 小时前
解决“Move to iOS 卡在准备中”的 9 种有效方法
macos·ios·cocoa
Xeon_CC4 小时前
在react-app-rewired工程项目中,调试AntVG6库源码包。
前端·react.js·前端框架
码上成长5 小时前
React 18 并发特性:useTransition 和 useDeferredValue 动画级解释
javascript·react.js·ecmascript
G***T6916 小时前
React性能优化实战,避免不必要的重渲染
前端·javascript·react.js
5***79007 小时前
Swift进阶
开发语言·ios·swift
denggun123457 小时前
ios卡顿优化
ios·xcode
從南走到北7 小时前
JAVA国际版打车APP打车顺风车滴滴车跑腿APP源码Android+IOS+H5
android·java·ios