React-native iOS 不显示图像(pods 问题)

Lui*_*oga 21 xcode image ios cocoapods react-native

我在我的 react-native 应用程序中安装了一个包(具体来说它是 react-navigation 中的 createMaterialTopTabNavigator)但是在安装成功后,出现了一些崩溃(错误:@react-navigation/material-top-tabs/src/index.tsx : 意外令牌 (16:12)),我试图修复它,所以我修复了它,但 iOS 上的图像停止工作。

在安装该软件包之前,我的 Image 组件在两个平台(iOS 和 Android)上都运行良好。

我想这与在 XCode 中处理图像的包/豆荚有关,但我尝试了一些东西但没有用(我不是 XCode 专家)。

在 Android 上,它们运行良好。

我为解决问题所做的但没有奏效:

- 将我的 react-native 版本从“0.61.5”升级到“0.62”

- 删除 pod,清理项目并使用“pod install”重新安装 pod

- 尝试了这个答案“/sf/ask/4084965741/”,但我想这不完全是我的问题。

你知道我还能做什么吗?我的想法不多了,我在互联网上找不到太多关于这个主题的信息。

谢谢!

更新 Image 组件制作它的动画,就像加载了图像一样,它只是不显示它。所以我确定这与 iOS 项目有关,也因为在 android 中工作正常。

gya*_*eep 114

如果您没有运行最新的 react-native 版本或不打算升级到最新版本的 react-native,则在 Xcode12 构建和修复中会看到图像问题,然后转到

node_modules > react-native > Libraries > Images > RCTUIImageViewAnimated.m 搜索 if (_currentFrame)

将以下 else 块添加到 if 块中,如下所示

 if (_currentFrame) {
    layer.contentsScale = self.animatedImageScale;
    layer.contents = (__bridge id)_currentFrame.CGImage;
  } else {
    [super displayLayer:layer];
  }
Run Code Online (Sandbox Code Playgroud)

参考:https : //github.com/facebook/react-native/issues/29279#issuecomment-658244428

  • 此修复适用于 React-native > 0.63.2 版本。我建议使用它作为临时修复,直到您升级到 0.63.2 或更高版本。 (2认同)

pra*_*huk 13

而且,如果您不想一遍又一遍地添加它,您可以将这些行替换为PodFile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
  end
end
Run Code Online (Sandbox Code Playgroud)

和,

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
    end
  end
  find_and_replace("../node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m",
    "_currentFrame.CGImage;","_currentFrame.CGImage ;} else { [super displayLayer:layer];")
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end
Run Code Online (Sandbox Code Playgroud)