question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Image] Retina Assets - Image component does not resolve images with filenames that include '@' symbol

See original GitHub issue

Is this a bug report?

Yes, this worked in previous versions.

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v: 0.46.1
  2. node -v: 8.1.4
  3. npm -v: 5.2.0
  4. yarn --version (if you use Yarn): none

Then, specify:

  1. Target Platform (e.g. iOS, Android): both
  2. Development Operating System (e.g. macOS Sierra, Windows 10): macOS Sierra
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): Xcode 8.3.3, Android Studio 2.3, iOS 10.3, Android 7.1.1

Steps to Reproduce

(Write your steps here:)

import React from 'react'
import { Image } from 'react-native'
import logo from '../images/logo@2x.png'

export default function Example () {
  return <Image source={logo} />
}

Expected Behavior

Image loaded correctly and displayed.

Actual Behavior

screenshot 2017-07-12 14 29 13

Reproducible Demo

The demo is made from create-react-native-app, eject, and react-native-git-upgrade.

https://github.com/timmywil/react-native-bug-example

I realize the workaround is simple, but I figure a regex got edited somewhere and this is a one-line fix.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
stigicommented, Jan 30, 2018

It’s 2018 and I am seeing the exact same issue as @hassanrazakhalid and the others above described. I’m on version 0.51.0.

I have icon.png, icon@2x.png and icon@3x.png and am using it a la

import icon from `./icon.png`

<Image source={icon} />

The dimensions of icon.png are 12x12px. The @2x dimensions are 24x24px, @3x are 36x36px. I would expect the Image to render in 12x12pt but it renders in 6x6pt. I’m testing on an iPhone 6 Simulator running iOS 11.2. PixelRatio.get() gives 2.

I believe I followed the instructions on https://facebook.github.io/react-native/docs/image.html exactly, but either there’s a small nuance I’m missing, or this is a bug. But since there’s not a huge outcry it’s hard for me to believe the later.

5reactions
codebymikeycommented, Feb 13, 2018

Did some more digging.

<Image source={require('./my-icon@2px.png')} /> should now be replaced with <Image source={require('./my-icon.png')} />. React Native/Metro Bundler will pick the correct one based on the device’s screen density.

Relevant documentation: https://facebook.github.io/react-native/docs/0.53/images.html

I think it’s definitely related to the move from react-native/packager to metro.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load local images in React.js - Stack Overflow
If I write the image path as src={require('./src/images/logo.png')} in my logo1 variable, it gives the error: Failed to compile. Error in ./src/ ...
Read more >
Asset Catalog Format Reference: Image Set Type
Describes the format for the Xcode document used to manage the mapping between named assets and content files.
Read more >
How to Make Images Retina-Ready for your Wordpress ...
Learn how to create Retina-ready images for your site here. ... The image resolution doesn't change the amount of data in the image, ......
Read more >
Understanding iOS Image Assets - MFractor
A picture still worth a thousand words (no pun intended)... The image above was taken from the article "Real retina vs. non-retina photos"...
Read more >
Images in Xamarin.Forms - Microsoft Learn
To use a single image across all apps, the same filename must be used on every platform, and it should be a valid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found