Image cannot show image in iOS 14
Problem
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"
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Image Rendering Issue in iOS 14 for React Native
The issue arises due to changes in how images are handled in iOS 14, particularly with the asset bundling and resource loading in React Native. The require statement may not resolve correctly due to caching or path issues in the new environment.
Awaiting Verification
Be the first to verify this fix
- 1
Check Image Path
Ensure that the image path is correct and that the image file exists in the specified directory. Sometimes, path issues can prevent the image from loading.
javascriptconst imageSource = require('./images/add_scan_images.png'); - 2
Clear Cache
Clear the React Native packager cache to ensure that any stale assets are removed. This can be done by running the following command in your project directory.
bashreact-native start --reset-cache - 3
Update React Native
Consider updating React Native to a more recent version that may have fixed compatibility issues with iOS 14. Check the changelog for any relevant fixes.
bashnpm install react-native@latest - 4
Use Image Component Properly
Ensure that the Image component is used correctly. If the image is not rendering, try using the `source` prop with an object that includes the `uri` property as a fallback.
javascript<Image source={{ uri: 'path/to/image/add_scan_images.png' }} /> - 5
Test on Physical Device
If the issue persists in the simulator, test the application on a physical device running iOS 14 to ensure that the problem is not simulator-specific.
bashnpx react-native run-ios
Validation
To confirm the fix worked, run the application and check if the image renders correctly on both the simulator and a physical device. Verify that there are no errors in the console related to image loading.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep