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

Inline image isn't scaled in Android version #11906

Closed
alexustinovsm opened this issue Jan 14, 2017 · 8 comments
Closed

Inline image isn't scaled in Android version #11906

alexustinovsm opened this issue Jan 14, 2017 · 8 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@alexustinovsm
Copy link

alexustinovsm commented Jan 14, 2017

When I use inline Image component with static image resources with different densities, I'll have problem in Android version with scaling of image. It looks like the app uses 1x instead of 3x image, but iOS version works fine.

Part of my code:

<Text>
  <Image source={ require('./imgs/my_icon.png') } /> with some text here
</Text>

My static image resources:

./imgs
|----> my_icon.png
|----> [email protected]
|----> [email protected]
|----> [email protected]
+----> [email protected]

ReactNative v0.40.0

@yloeza
Copy link

yloeza commented Mar 4, 2017

after some debugging on my own I found the reason why text inline image is not getting scaling properly, here my findings:

During this commit change: 68c6d71
The way width and height are used to generate TextInlineImageSpan was changed:
from:

public TextInlineImageSpan buildInlineImageSpan() {
     Resources resources = getThemedContext().getResources();
int height = (int) Math.ceil(getStyleHeight());
int width = (int) Math.ceil(getStyleWidth());
 return new FrescoBasedReactTextInlineImageSpan(
   resources,
   height,
 ...

to:

public TextInlineImageSpan buildInlineImageSpan() {
  Resources resources = getThemedContext().getResources();
  int height = (int) Math.ceil(mWidth);
  int width = (int) Math.ceil(mHeight);
  return new FrescoBasedReactTextInlineImageSpan(
    resources,
    height,
    ...

so before it was getting set from getStyle*() methods, that returns a value stored based on the result of the setStyle*() call, which transform the value of width to the pixel unit based of resolution.

public void setWidth(float width) {
   setStyleWidth(CSSConstants.isUndefined(width) ? width : PixelUtil.toPixelFromDIP(width));
 }

currently, this class does not apply any transformation to the width/height value so it ends up rendering without any notion of the current resolution.

a workaround for now is doing something like this:

class App extends Component {

  render() {
    const width = 80 * (Platform.OS === 'ios' ? 1 : PixelRatio.get());
    const height = 80 * (Platform.OS === 'ios' ? 1 : PixelRatio.get());
    return (
      <View style={{flex: 1}}>
        <Text style={{backgroundColor: 'red'}}>
          <Image
            style={{width, height}}
            source={{uri: 'http://s3.hilariousgifs.com/displeased-cat.jpg'}}
          />
        </Text>
      </View>
    );
  }
}

I hope this info is helpful to clarify this issue so we can expect a fix for this soon. Let me know if you guys need any more information.
I also noticed that iOS is rendering inline image a little off.
ReactNative v0.41.2
iOS:
image

before workaround:
image

after workaround:
image

@yloeza
Copy link

yloeza commented Apr 11, 2017

@christopherdro is there any news/progress around this issue?

@hramos
Copy link
Contributor

hramos commented Jul 20, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos added the Icebox label Jul 20, 2017
@hramos hramos closed this as completed Jul 20, 2017
@chuckwu0
Copy link

thx @yloeza .this work around for me

@doublex
Copy link

doublex commented Dec 12, 2017

@alexustinovsm
Still not fixed - could you re-open this issue?

@hramos
Copy link
Contributor

hramos commented Dec 21, 2017

I won't be reopening this issue as it does not contain sufficient information as required by the template. You may open a new one.

@doublex
Copy link

doublex commented Dec 22, 2017

@hramos

The problem is simple: <Images> inside <Text> on Android are not calculated according to "device pixels" but according to "real pixels" (which is wrong on high resolution devices).

A new issue would loose the information in the thread.

@hramos
Copy link
Contributor

hramos commented Dec 22, 2017

You can always link back to the thread and make sure the new issue summarizes any relevant information from this thread.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 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

7 participants