解决: 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
相关推荐
伟笑30 分钟前
React 的常用钩子函数在Vue中是如何设计体现出来的。
前端·react.js
形影相吊1 小时前
iOS防截屏实战
ios
吴Wu涛涛涛涛涛Tao1 小时前
Flutter 弹窗解析:从系统 Dialog 到完全自定义
flutter·ios
FogLetter1 小时前
React组件开发进阶:本地存储与自定义Hooks的艺术
前端·javascript·react.js
kymjs张涛3 小时前
零一开源|前沿技术周报 #7
android·前端·ios
AliciaIr4 小时前
深入React事件机制:解密“合成事件”与“事件委托”的底层奥秘
javascript·react.js
思考着亮5 小时前
15-错误处理
ios
思考着亮5 小时前
9.方法
ios
心.c5 小时前
后台管理系统-权限管理
javascript·react.js·github
杨进军6 小时前
实现 React 函数组件渲染
前端·react.js·前端框架