react-native: Image component does not load image from specific URI on iOS
Description
The Image
component does not render an image on iOS when loaded from a specific URI
React Native version:
System: OS: macOS 10.15.4 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 234.47 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.20.0 - ~/.nvm/versions/node/v10.20.0/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.4 - ~/.nvm/versions/node/v10.20.0/bin/npm Watchman: Not Found SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: Not Found IDEs: Android Studio: Not Found Xcode: 11.5/11E608c - /usr/bin/xcodebuild Languages: Java: 14.0.1 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.9.0 => 16.9.0 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: react-native: Not Found
Steps To Reproduce
See code snippet below
Expected Results
I would expect the code below to render an image on screen. It does do that on Android, but not on iOS. If i go to that link in a browser or curl
it from the terminal it renders or downloads as expected. But React Native on iOS does not render it.
Snack, code example, screenshot, or link to a repository:
<Image style={{height: 100, width: 100}} source={{ uri: 'https://api.openpay.mx/barcode/185017437691737?width=1&height=100' }} />
See example here: https://snack.expo.io/QH4nUBfc6
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 29
- Comments: 65 (8 by maintainers)
If any one is still facing the problem here are stepwise solution which worked for me :-
if (_currentFrame) { layer.contentsScale = self.animatedImageScale; layer.contents = (__bridge id)_currentFrame.CGImage; }
withif (_currentFrame) { layer.contentsScale = self.animatedImageScale; layer.contents = (__bridge id)_currentFrame.CGImage; }else { [super displayLayer:layer]; }
I can confirm this worked! Thank you!
For those who don’t know how this works:
npm i -g patch-package Make a new folder called patches Make a new file called react-native+0.63.0.patch Add the source code above. patch-package enter
Edit: fixed a typo.
@DennisdeWitNL use patch-package and my patch file (work with rn 0.63)
react-native+0.63.0.patch
Any dev want to
patch-package
step by step doc to solve image issue checkout below linkhttps://infinitbility.com/image-not-showing-in-ios-14-react-native
this worked like butter
All images not loading for me on iOS 14 beta
Hi everyone, face this issue today, Xcode 12, and iOS 14.3, tried the patch. without success,
So in the end of the url, that was using ‘http’, I replaced for ‘https’ and it worked:
.replace(‘http’,‘https’)
In my case my urls are http.
@DennisdeWitNL’s solution worked for me, although I made a few small adjustments as I don’t like global packages personally.
package.json
that will run this after you invokeyarn install
(or equivalent)These steps were found in the
patch-package
README.Worked like a charm!
I am still not able to see any images with the iOs 14.2 update. I have implemented:
Is anyone else seeing these solutions not working for them?
I am on: react-native-cli: 2.0.1 react-native: 0.61.4 Managed Expo: Expo CLI 3.28.2 environment info: System: OS: macOS 10.15.4 Shell: 3.2.57 - /bin/bash Binaries: Node: 15.0.1 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.0.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0 IDEs: Xcode: 11.1/11A1027 - /usr/bin/xcodebuild npmPackages: expo: ^37.0.12 => 37.0.12 react: 16.9.0 => 16.9.0 react-dom: 16.9.0 => 16.9.0 react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4 react-native-web: ^0.11.7 => 0.11.7 react-navigation: ^3.13.0 => 3.13.0 npmGlobalPackages: expo-cli: 3.28.2 Expo Workflow: managed
I came across this same issue too yesterday after an OS update. Lost a few hours trying to figure out the problem. Updating to the latest version of react-native fixed it for me, it looks like it contains the fix.
Worked for me with:
React Native: 0.61.5 Xcode: 12.0
I did the same as @ryanpag3 with one small tweak for step 1:
I’m having this issue with my app on an actual device with the release build (images from URI only). However, on the simulator it works perfectly fine. Would this fix also work for this scenario?
Thanks
I can confirm that @DennisdeWitNL’s fix https://github.com/facebook/react-native/issues/29215#issuecomment-657231577 also works for React Native 0.61.2, using Xcode 12 beta 3, iOS 14 simulator.
@abiespinal04 You make a new folder called ‘patches’ right in your React Native project folder.
@joewired This is strange. I applied the patch too, and I have multiple images with a width and height of 50 pixels, just as I programmed. And I also have a screen width filling Image Background, which is working fine too. I don’t have this problem.
I built the app with iOS 13 SDK and even on iOS 14 the images show perfectly fine. I built the app on Big Sur. The problem either is Xcode 12 or iOS 14 SDK.
Can confirm. I have the same problem on iOS 13.5 and iOS 14.