facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.42k stars 24.36k forks source link

Image cannot show image in iOS 14 #29279

Closed caofeng closed 4 years ago

caofeng commented 4 years ago

Image cannot show image in iOS 14, but can show location, like: <Image source={ require('./images/add_scan_images.png') } />

Environment: Xcode Version 12.0 beta (12A6159) Simulator: IPhone SE - 2nd generation - 14.0 "react": "16.11.0", "react-native": "0.62.2"

nigharsh commented 4 years ago

Tried all the solutions on 0.61.4, the remote images are loading fine but the local assets won't just show.

Any ideas?

BogdanRad commented 4 years ago

Thank you xcode.. image

fabiocberg commented 4 years ago

It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil

if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix.

https://github.com/facebook/react-native/blob/1c634a921887caf02f1b9fba6fd177c352f9ef78/Libraries/Image/RCTUIImageViewAnimated.m#L283-L289

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

It worked for me. Thanks! Additionally, you can use npx patch-package (more info here) to keep this change and don't need to keep fixing all-time node_modules is reinstalled.

These are the kind of bugs that makes me want to open any other business and stop being a programmer.

Justin9606 commented 4 years ago

https://github.com/huylvdev/react-native-fix-image it works for me

Thanks so ,much After spending a day finally i fixed by this help

virgial commented 4 years ago

I can confirm that this patch can also be applied to version 0.63.2. Rename the file to (react-native+0.62.2.patch).

Rohithzr commented 4 years ago

Please Re open this issue, This is still not solving the problem.

bhavishya2107 commented 4 years ago

https://github.com/huylvdev/react-native-fix-image it works for me

Thanks so ,much After spending a day finally i fixed by this help

Hey, I tried using react-native-fix-image it worked when I am doing npx react-native-fix-image but when I am removing the node_modules and reinstalling them. The app does not load the images. Did you face any such issue and do we have to run the npx command every time to render the images.

sobanarshad85 commented 4 years ago

here you go https://github.com/facebook/react-native/issues/29279#issuecomment-658244428

caiomendes23 commented 4 years ago

https://github.com/huylvdev/react-native-fix-image it works for me

Thanks so ,much After spending a day finally i fixed by this help

Thats work for me! Thks!!

mateodaza commented 4 years ago

It's not working for me on release mode, any idea?

todor-droxic commented 4 years ago

@tomcheung thank you a lot! I hit my head 2 days to find out what the problem is...

bpred754 commented 4 years ago

For those running older versions of React Native (e.g., 0.60.6) the patch is not possible since the RCTUIImageViewAnimated.m file doesn't exist. I solved this problem by using React Native Fast Image v8.1.5 and upgrading SDWebImage pod with pod update SDWebImage. More specifically, I upgraded SDWebImage from v5.8.1 to v5.9.2.

Source: https://github.com/DylanVann/react-native-fast-image/issues/702#issuecomment-653930858

petermason commented 4 years ago

Images not showing on release version. (ejected expo 39 project) RN 0.63.3 update: updating metro.config.js fixed my issue => https://forums.expo.io/t/assets-missing-only-in-ios-release-build-after-ejecting/42759

lock9 commented 4 years ago

Is this going to be officially fixed on any RN release? Afaik, the problem is still there.

d0xi5 commented 4 years ago

Is this going to be officially fixed on any RN release? Afaik, the problem is still there.

+1. Every once in a while Im on an old project and I have to patch it..

hanomain99 commented 4 years ago

diff --git a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m index 21f1a06..2444713 100644 --- a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m +++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m @@ -272,6 +272,9 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink

  • (void)displayLayer:(CALayer *)layer {
    • if (!_currentFrame) {
    • _currentFrame = self.image;
    • } if (_currentFrame) { layer.contentsScale = self.animatedImageScale; layer.contents = (__bridge id)_currentFrame.CGImage; diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env new file mode 100644 index 0000000..361f5fb --- /dev/null +++ b/node_modules/react-native/scripts/.packager.env @@ -0,0 +1 @@ +export RCT_METRO_PORT=8081

Thanks! This worked for me on my all old RN projects. Just replace the React Native version of your old project instead of 0.63 before creating the file of react-native+0.63.0.patch.

I created a video and I hope this would help someone.

matiasmir commented 4 years ago

@AsbarAli's fix worked for me, RN Version: 0.61.5.

gt-codes commented 4 years ago

It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix. https://github.com/facebook/react-native/blob/1c634a921887caf02f1b9fba6fd177c352f9ef78/Libraries/Image/RCTUIImageViewAnimated.m#L283-L289

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

It worked for me. Thanks! Additionally, you can use npx patch-package (more info here) to keep this change and don't need to keep fixing all-time node_modules is reinstalled.

These are the kind of bugs that makes me want to open any other business and stop being a programmer.

It's important that you run npx patch-package react-native for the patch to be applied.

safaiyeh commented 4 years ago

Hey all could someone confirm this was merged to core?

While patch-package is a solution it shouldn't be a permanent one.

I will keep this open until I can investigate.

enriccamacho commented 4 years ago

Are they not planning to fix this?

imhuy commented 4 years ago

https://www.npmjs.com/package/react-native-fix-image working for me

safaiyeh commented 4 years ago

It looks like it is fixed. Just won't be back ported to previous versions. I believe the fix is in 63.3

rjtubera commented 4 years ago

@AsbarAli's fix worked for me, RN Version: 0.61.5.

How did you do it? i'm using RN 61.2

rjtubera commented 4 years ago

Use react-native+0.63.0.patch

diff --git a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
index 21f1a06..2444713 100644
--- a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
+++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
@@ -272,6 +272,9 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink

 - (void)displayLayer:(CALayer *)layer
 {
+  if (!_currentFrame) {
+    _currentFrame = self.image;
+  }
   if (_currentFrame) {
     layer.contentsScale = self.animatedImageScale;
     layer.contents = (__bridge id)_currentFrame.CGImage;
diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
--- /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081

How can I apply this using patch-package please ? Beginner with using patch-package.

Hi! 1.- run "npm i -g patch-package" 2.- Make a new folder called patches 3.- Make a new file called react-native+0.63.0.patch inside that folder 4.- Add the source code above. 5.- run "patch-package" on the root of the project

I got this problem while using RN v0.61.2 but this still worked for me. Thanks

Hi can you help me? I also have RN 61.2 but it doesn't work at all. May bottom navigation images are not showing

kierandesmond commented 4 years ago

Hey @rjtubera, the patch is supposed to work with 0.63 though reportedly works also with 0.61.5 version of React Native. Perhaps if you try upgrading from React Native 0.61.2 to 0.61.5, and re-apply the steps you have quoted, it may work.

If that doesn't work, try upgrading to 0.63 and do the same. Though becareful as some of your components might break. You should test every component after the upgrade to make sure everything still works well (on iOS and Android).

tbanj commented 4 years ago

I encounter this issue, i fixed it by following steps at this link https://github.com/facebook/react-native/pull/29420#issuecomment-707435412

kierandesmond commented 4 years ago

Thanks Alabi, I sorted the issue too by patching React Native. Working well now so far 😊

From: Alabi Temitope Wahab notifications@github.com Reply to: facebook/react-native reply@reply.github.com Date: Tuesday 13 October 2020 at 03:56 To: facebook/react-native react-native@noreply.github.com Cc: Kieran Desmond kieran@sweep.ie, Comment comment@noreply.github.com Subject: Re: [facebook/react-native] Image cannot show image in iOS 14 (#29279)

I encounter this issue, i fixed it by following steps at this link

29420 (comment)https://github.com/facebook/react-native/pull/29420#issuecomment-707435412

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/facebook/react-native/issues/29279#issuecomment-707436028, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIENJUWD2RES5AC52CT4MG3SKOXURANCNFSM4ORGDXZA.

Anzormumladze commented 4 years ago

i upgraded to 0.63 version of react native, but i am facing same issue,anyone can help me ?

lissau commented 4 years ago

For those running older versions of React Native (e.g., 0.60.6) the patch is not possible since the RCTUIImageViewAnimated.m file doesn't exist. I solved this problem by using React Native Fast Image v8.1.5 and upgrading SDWebImage pod with pod update SDWebImage. More specifically, I upgraded SDWebImage from v5.8.1 to v5.9.2.

Source: DylanVann/react-native-fast-image#702 (comment)

Works perfectly.

Version 8.3.2 of react-native-fast-image even includes the upgraded version of SDWebImage, so no need to pod update!

Doha26 commented 4 years ago

https://www.npmjs.com/package/react-native-fix-image working for me

Worked for me too. 👍

alexanderkho commented 4 years ago

Upgrading from React-Native 0.63.1 to 0.63.2 worked for us.

ghasemikasra39 commented 4 years ago

I am facing the same issue on RN 0.62.2 on Xcode 12.0.1. and ios 14. Any solution?

RutsSantos commented 4 years ago

I am facing the same issue on RN 0.62.2 on Xcode 12.0.1. and ios 14. Any solution?

@ghasemikasra39 I was facing the same issue with your same versions. Installing react-native-fix-image worked for me.

JordanRosas commented 4 years ago

@RutsSantos right on this also worked for me!

1) npm install --save react-native-fix-image 2) npx react-native-fix-image 3) rebuild project

xtealer commented 4 years ago

Upgrading from React-Native 0.63.1 to 0.63.2 worked for us.

This worked for me.

basarburak commented 4 years ago

This worked for me. Thanks @JordanRosas

jkz27 commented 4 years ago

@JordanRosas Worked for me wonderfully too, thank you

Anzormumladze commented 4 years ago

upgrade react native version from 0.62.2 to 0.63.3 no need to patch or install npm modules anymore

hugoh59 commented 4 years ago

0.62.3 does not exists:

hugoh59 commented 4 years ago

0.63.3 0.63.2 0.63.1 0.63.0 0.63.0-rc.1 0.63.0-rc.0 ❯ 0.62.2 0.62.1 0.62.0

Anzormumladze commented 4 years ago

0.63.3 0.63.2 0.63.1 0.63.0 0.63.0-rc.1 0.63.0-rc.0 ❯ 0.62.2 0.62.1 0.62.0

corrected

cristianoccazinsp commented 4 years ago

Some of us can't upgrade until this critical RN bug is resolved: https://github.com/facebook/react-native/issues/29451

So we are either stuck with monkey patching 0.62.x or a bugged 0.63.x version.

ReemaVinodGangdev commented 4 years ago

It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil

if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix.

https://github.com/facebook/react-native/blob/1c634a921887caf02f1b9fba6fd177c352f9ef78/Libraries/Image/RCTUIImageViewAnimated.m#L283-L289

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

It works. Thank you!

haseebeqx commented 4 years ago

If you don't want to install any packages or directly edit node_modules you can try adding a preinstall stage hook in podfile as in https://stackoverflow.com/a/64495360/7477198 this worked for me. This is more git friendly.

adithyaBellary commented 4 years ago

For me, even on RN 63.3, images are not showing up on a physical device. As a workaround, I encoded the images in base 64 here: https://www.base64-image.de/ and then used that as the source for the Image component instead of require('imagePath')

TechMaagal commented 4 years ago

It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil

if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix.

https://github.com/facebook/react-native/blob/1c634a921887caf02f1b9fba6fd177c352f9ef78/Libraries/Image/RCTUIImageViewAnimated.m#L283-L289

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

Your are a genius man, you saved my life!

DanGDroid commented 4 years ago

Use react-native+0.63.0.patch

diff --git a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
index 21f1a06..2444713 100644
--- a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
+++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
@@ -272,6 +272,9 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink

 - (void)displayLayer:(CALayer *)layer
 {
+  if (!_currentFrame) {
+    _currentFrame = self.image;
+  }
   if (_currentFrame) {
     layer.contentsScale = self.animatedImageScale;
     layer.contents = (__bridge id)_currentFrame.CGImage;
diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
--- /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081

How can I apply this using patch-package please ? Beginner with using patch-package.

Hi!

1.- run "npm i -g patch-package" 2.- Make a new folder called patches 3.- Make a new file called react-native+0.63.0.patch inside that folder 4.- Add the source code above. 5.- run "patch-package" on the root of the project

Thanx worked for me fine on RN 0.61.5 i added a patch file called react-native+0.61.5.patch

also a fix for DylanVann/react-native-fast-image cd ios && pod update SDWebImage

joshhogg commented 4 years ago

Use react-native+0.63.0.patch

diff --git a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
index 21f1a06..2444713 100644
--- a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
+++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
@@ -272,6 +272,9 @@ - (void)displayDidRefresh:(CADisplayLink *)displayLink

 - (void)displayLayer:(CALayer *)layer
 {
+  if (!_currentFrame) {
+    _currentFrame = self.image;
+  }
   if (_currentFrame) {
     layer.contentsScale = self.animatedImageScale;
     layer.contents = (__bridge id)_currentFrame.CGImage;
diff --git a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
--- /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081

@legion-zver Thanks for the fix! Is the RCT_METRO_PORT required here, or something specific for your project?

PhoenixLeeSin commented 4 years ago

RN 0.59.0 on Xcode 12.0.1. and ios 14. Any solution?

douglasjunior commented 4 years ago

RN 0.59.0 on Xcode 12.0.1. and ios 14. Any solution?

3 solutions:

  1. Fix the problem manually within node_modules
  2. Use this fix library https://www.npmjs.com/package/react-native-fix-image
  3. Update to React Native 0.63.3