Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require('image!'+'name') doesn't work for big images #1708

Closed
0x0ece opened this issue Jun 22, 2015 · 2 comments
Closed

Require('image!'+'name') doesn't work for big images #1708

0x0ece opened this issue Jun 22, 2015 · 2 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@0x0ece
Copy link

0x0ece commented Jun 22, 2015

I reduced my issue to this minimal repro (react-native 0.5.0). I have a png of about 1MB, with smaller images I have no issues.

var image = require('image!name');

works properly, while

var image = require('image!'+'name');

returns "Requiring unknown module...".

My use case would be to have jpg images, and of course 'name' will be a variable different for each image. Will jpg be supported anytime soon? Thanks! E.

@browniefed
Copy link
Contributor

A static analysis done to determine what images to include or not, so doing dynamic images is not supported. At least that is what I assume is going on here.

@ide
Copy link
Contributor

ide commented Jun 22, 2015

@browniefed is right. @ecesena please try var image = require('image!name'); with your big image. If you want to dynamically display an image based on its name, write this:

function getImageSourceByName(name) {
switch (name) {
case 'pic1':
  return require('image!pic1');
case 'pic2':
  return require('image!pic2');
case 'pic3':
  return require('image!pic3');
}
}

Then you can write <Image source={getImageSourceByName(name)} />.

@ide ide closed this as completed Jun 22, 2015
@facebook facebook locked as resolved and limited conversation to collaborators Jun 22, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants