React Native 在 iOS 14 没显示项目的图片资源

React Native 2021-04-17 阅读 95 评论 0

问题描述

在 iOS 14 中运行 React Native 0.62.2 的项目,iPhone 设备没有显示项目的本地图片,如:

<Image source={require('./images/logo.png')} style={{width: 40, height: 40}} />

解决方法1

升级到 React Native 0.63.2+。在 React Naitve V0.62.2 的升级日志中可以看到,已经修复在 iOS 14中图片不显示的问题。如下图:

解决方法2

node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m 文件中,修改 displayLayer 方法。

#pragma mark - CALayerDelegate

- (void)displayLayer:(CALayer *)layer
{
  if (_currentFrame) {
    layer.contentsScale = self.animatedImageScale;
    layer.contents = (__bridge id)_currentFrame.CGImage;
  }
}

#pragma mark - CALayerDelegate

- (void)displayLayer:(CALayer *)layer
{
  if (_currentFrame) {
    layer.contentsScale = self.animatedImageScale;
    layer.contents = (__bridge id)_currentFrame.CGImage;
  } else {
    [super displayLayer:layer];
  }
}
最后更新 2021-04-17
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });