首页 > 解决方案 > XCode 12.3 上的 ReactNative 0.59.10 未显示照片

问题描述

我正在处理一个旧的现有 ReactNative 项目。我在应用程序中显示照片时遇到问题。当我使用 Xcode 11.x 时,该应用程序很好。然后我开始使用 Xcode 12.3。当我在 Xcode 12.3 上构建项目时,它不再显示照片。这似乎是 Xcode 12.3 上 ReactNative 的一个已知问题。

我的 ReactNative 版本是 0.59.10。我正在关注这篇文章来解决这个问题,https://infinitbility.com/image-not-showing-in-ios-14-react-native。但它不起作用。

这是我到目前为止所做的。我安装了运行以下 npm 命令的补丁包。

npm install -g patch-package

然后我在项目的根文件夹中创建了一个补丁文件夹。然后我在 patchs 文件夹中创建了一个名为 patch/react-native+0.59.10.patch 的文件,其内容如下。

diff --git a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
2index 21f1a06..2444713 100644
3--- a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
4+++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
5@@ -272,6 +272,9 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink
6
7 - (void)displayLayer:(CALayer *)layer
8 {
9+  if (!_currentFrame) {
10+    _currentFrame = self.image;
11+  }
12   if (_currentFrame) {
13     layer.contentsScale = self.animatedImageScale;
14     layer.contents = (__bridge id)_currentFrame.CGImage;
15diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
16new file mode 100644
17index 0000000..361f5fb
18--- /dev/null
19+++ b/node_modules/react-native/scripts/.packager.env
20@@ -0,0 +1 @@
21+export RCT_METRO_PORT=8081

然后我运行以下命令来应用修复。

patch-package

我得到以下输出。

在此处输入图像描述

然后我关闭了 Xcode 并再次打开它。它仍然没有显示照片。我该如何解决?

标签: iosxcodereact-nativereact-native-ios

解决方案


推荐阅读