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

Unable to use height and width as props in Image components #41151

Closed
shubhamguptadream11 opened this issue Oct 23, 2023 · 5 comments
Closed
Labels
Component: Image Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available

Comments

@shubhamguptadream11
Copy link
Collaborator

shubhamguptadream11 commented Oct 23, 2023

Description

Unable to use height and width as props in Image components. It's working in rn0.69.1but not working after upgrade to 0.72.4. Because of this my Images are not visible on screen

React Native Version

0.72.4

Output of npx react-native info

System:
OS: macOS 13.4.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 839.98 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 16.14.0
path: /usr/local/bin/node
Yarn:
version: 1.22.19
path: /usr/local/bin/yarn
npm:
version: 8.3.1
path: /usr/local/bin/npm
Watchman:
version: 2023.10.02.00
path: /usr/local/bin/watchman
Managers:
CocoaPods:
version: 1.11.3
path: /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 22.2
- iOS 16.2
- macOS 13.1
- tvOS 16.1
- watchOS 9.1
Android SDK:
API Levels:
- "29"
- "30"
- "31"
- "32"
- "33"
- "34"
Build Tools:
- 28.0.3
- 29.0.1
- 29.0.2
- 29.0.3
- 30.0.1
- 30.0.2
- 30.0.3
- 31.0.0
- 31.0.0
- 33.0.0
- 33.0.1
System Images:
- android-24 | Google APIs Intel x86 Atom
- android-24 | Google Play Intel x86 Atom
- android-29 | Google Play Intel x86 Atom
- android-30 | Google APIs Intel x86 Atom
- android-30 | Google Play Intel x86 Atom
- android-31 | Intel x86_64 Atom
- android-31 | Google Play Intel x86 Atom_64
- android-33 | Google Play Intel x86_64 Atom
Android NDK: 22.1.7171670
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9619390
Xcode:
version: 14.2/14C18
path: /usr/bin/xcodebuild
Languages:
Java:
version: 1.8.0_281
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.4
wanted: 0.72.4
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce

Below is the sample Image component where I am passing array of sources to it with height and width passed as props.
Image is seen visible in rn 0.69.1 but not after rn upgrade 0.72.4.

Note: If I pass single source without any array then things are working fine.

import React from 'react';
import {Image} from 'react-native';

const sources = [
  {
    height: 84,
    uri: 'https://placekitten.com/100/100',
    width: 80,
  },
  {
    height: 168,
    uri: 'https://placekitten.com/100/100',
    width: 160,
  },
  {
    height: 252,
    uri: 'https://placekitten.com/100/100',
    width: 240,
  },
];

const ImageComponent = () => {

  // Image is not loading since it's not respecting given height and width
  return <Image height={100} width={100} style={styles.img} source={sources} />;
};

const styles = StyleSheet.create({
  img: {
    borderWidth: 1,
  },
});

Snack, screenshot, or link to a repository

Repro: https://snack.expo.dev/@sg43245/401ed2

Behaviour in 0.69.1 [Working]

Screenshot_20231023-154940

Behaviour in 0.72.4 [Not Working]

Screenshot_20231023-154919

@github-actions
Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.72.6. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added Newer Patch Available Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Component: Image labels Oct 23, 2023
@shubhamguptadream11
Copy link
Collaborator Author

shubhamguptadream11 commented Oct 23, 2023

I checked this on latest version 0.72.6 as well. This issue still exists.

I did some debugging around this.
In file packages/react-native/Libraries/Image/Image.android.js I found a code diff as compared to 0.69.1.

In 0.69.1
https://github.com/facebook/react-native/blob/v0.69.1/Libraries/Image/Image.android.js
Here if we see Image component we observe that we are spreading whole props object in nativeProps which is then passed to native side.

In 0.72.6
https://github.com/facebook/react-native/blob/v0.72.6/packages/react-native/Libraries/Image/Image.android.js
But here we are extracting height and width out before passing restProps to native Props.
This clearly points out that we are no longer using width and height coming as props in cases where we are passing array of sources.

So if I just pass whole props instead of restProps in native Props it works

This is the commit: #34481 where height and width are extracted out.

@shubhamguptadream11
Copy link
Collaborator Author

Repro link: https://snack.expo.dev/@sg43245/401ed2

@github-actions github-actions bot removed the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Oct 23, 2023
@cortinico cortinico added the Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. label Oct 24, 2023
@shubhamguptadream11
Copy link
Collaborator Author

Any update here? @cortinico

@jiunshinn
Copy link

@cortinico Can you assign this issue to me?

facebook-github-bot pushed a commit that referenced this issue Oct 18, 2024
Summary:
Fixes this: #41151

## Changelog:

[GENERAL] [FIXED] - Passed height and width as native props to support cases where source is an array.

**Issue**: Unable to use height and width as props in Image components when passing source as an array.

This functionality worked before this [commit](#34481). In Image.android.js and Image.ios.js, height and width props are extracted before passing them to the native side. This extraction makes these props ineffective when passed directly. Although setting height and width in style is a workaround, these props should still be respected since they exist for this purpose.

The issue occurs only when the source prop is an array. When source is an object, width and height are manually passed to the style object, so the issue doesn't arise.

Pull Request resolved: #47044

Test Plan: Tested this on `rn-tester` app

Reviewed By: necolas, javache

Differential Revision: D64458292

Pulled By: cipolleschi

fbshipit-source-id: 5cacad79b8d4468a4a1fd0977221e42ce4b2e5d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Image Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available
Projects
None yet
Development

No branches or pull requests

3 participants